Class: Code

Inherits:
ApplicationRecord show all
Includes:
HasOwner
Defined in:
app/models/code.rb

Overview

Code for user

Attributes:

- agent_id [Agent], optional
- body [String]
- code_type_id [CodeType]
- created_at [DateTime]
- ip [Inet]
- payload [String], optional
- quantity [Integer]
- updated_at [DateTime]
- user_id [User], optional

Constant Summary collapse

BODY_LIMIT =
50
PAYLOAD_LIMIT =
255
QUANTITY_RANGE =
(0..32_767).freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasOwner

#owned_by?, #owner_name

Class Method Details

.creation_parametersObject



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

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

.entity_parametersObject



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

def self.entity_parameters
  %i[body payload quantity]
end

.page_for_administration(page = 1) ⇒ Object

Parameters:

  • page (Integer) (defaults to: 1)


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

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

Instance Method Details

#activated?Boolean

Returns:

  • (Boolean)


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

def activated?
  quantity < 1
end

#active?Boolean

Returns:

  • (Boolean)


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

def active?
  quantity.positive?
end