Class: NextErpBridge::Entity::Base

Inherits:
Object
  • Object
show all
Includes:
Core::Entry
Defined in:
lib/next_erp_bridge/entity/base.rb

Constant Summary collapse

@@klass_registry =
{ }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Core::Entry

included

Constructor Details

#initialize(attributes) ⇒ Base

Returns a new instance of Base.



9
10
11
# File 'lib/next_erp_bridge/entity/base.rb', line 9

def initialize(attributes)
  @attributes = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/next_erp_bridge/entity/base.rb', line 13

def method_missing(m, *args, &block)
  keys = attributes.keys.map(&:to_s)
  m = m.to_s
  is_setter = (m[-1] == '=')
  if is_setter
    m = m[0..(m.size-2)]
  end
  if keys.include?(m)
    attributes[m] = args[0] if is_setter
    attributes[m]
  else
    super(m.to_sym, *args)
  end
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



7
8
9
# File 'lib/next_erp_bridge/entity/base.rb', line 7

def attributes
  @attributes
end

Class Method Details

.klass_registryObject



28
29
30
# File 'lib/next_erp_bridge/entity/base.rb', line 28

def self.klass_registry
  @@klass_registry
end