Module: EnotasApi::Attributable

Included in:
Entity
Defined in:
lib/enotas_api/support/attributable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
# File 'lib/enotas_api/support/attributable.rb', line 7

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#attribute_changed?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/enotas_api/support/attributable.rb', line 19

def attribute_changed?(attribute)
  attributes_changed.include?(attribute)
end

#attribute_type(attribute) ⇒ Object



27
28
29
# File 'lib/enotas_api/support/attributable.rb', line 27

def attribute_type(attribute)
  self.class.attribute_type(attribute)
end

#attributesObject



23
24
25
# File 'lib/enotas_api/support/attributable.rb', line 23

def attributes
  self.class.entity_attributes
end

#attributes_changedObject



15
16
17
# File 'lib/enotas_api/support/attributable.rb', line 15

def attributes_changed
  (@attributes_changed || []).freeze
end

#initializeObject



11
12
13
# File 'lib/enotas_api/support/attributable.rb', line 11

def initialize(...)
  set(...)
end

#set(attributes = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/enotas_api/support/attributable.rb', line 31

def set(attributes = nil)
  return if attributes.nil? || attributes.empty?

  attributes.each_pair do |attr, value|
    method = "#{attr}="
    method = attr unless respond_to?(method)
    send(method, value)
  end

  self
end