Class: Code

Inherits:
ApplicationRecord
  • Object
show all
Includes:
HasOwner, HasTrack
Defined in:
app/models/code.rb

Overview

Code for users

Attributes:

agent_id [Agent], optional
biovision_component_id [BiovisionComponent]
body [string]
created_at [DateTime]
data [jsonb]
ip_address_id [IpAddress], optional
quantity [integer]
updated_at [DateTime]
user_id [User]

Constant Summary collapse

BODY_LIMIT =
50
QUANTITY_RANGE =
(0..32_767)

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasOwner

#owned_by?, #owner_name

Class Method Details

.creation_parametersObject



47
48
49
# File 'app/models/code.rb', line 47

def self.creation_parameters
  entity_parameters + %i[user_id biovision_component_id]
end

.entity_parametersObject



43
44
45
# File 'app/models/code.rb', line 43

def self.entity_parameters
  %i[body quantity]
end

.page_for_administration(page = 1) ⇒ Object

Parameters:

  • page (Integer) (defaults to: 1)


39
40
41
# File 'app/models/code.rb', line 39

def self.page_for_administration(page = 1)
  list_for_administration.page(page)
end

Instance Method Details

#activated?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'app/models/code.rb', line 51

def activated?
  quantity < 1
end

#active?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/code.rb', line 55

def active?
  quantity.positive?
end

#code_typeObject



64
65
66
# File 'app/models/code.rb', line 64

def code_type
  data['type'].to_s
end

#code_type=(new_type) ⇒ Object

Parameters:

  • new_type (String)


69
70
71
# File 'app/models/code.rb', line 69

def code_type=(new_type)
  data['type'] = new_type.to_s
end

#phone?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'app/models/code.rb', line 73

def phone?
  type?(Biovision::Components::UsersComponent::CODE_PHONE_CONFIRMATION)
end

#type?(type_name) ⇒ Boolean

Parameters:

  • type_name (String)

Returns:

  • (Boolean)


60
61
62
# File 'app/models/code.rb', line 60

def type?(type_name)
  code_type == type_name.to_s
end