Module: Locomotive::Steam::Models::Entity

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::ToJson

#as_json, #to_hash, #to_json

Methods included from Concerns::Validation

#errors, #valid?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



15
16
17
18
19
20
21
22
23
24
# File 'lib/locomotive/steam/models/entity.rb', line 15

def method_missing(name, *args, &block)
  _name = name.to_s
  if attributes.include?(_name)
    self[_name]
  elsif _name.end_with?('=') && attributes.include?(_name.chop)
    self[_name.chop] = args.first
  else
    super
  end
end

Instance Attribute Details

#associationsObject

Returns the value of attribute associations.



9
10
11
# File 'lib/locomotive/steam/models/entity.rb', line 9

def associations
  @associations
end

#attributesObject

Returns the value of attribute attributes.



9
10
11
# File 'lib/locomotive/steam/models/entity.rb', line 9

def attributes
  @attributes
end

#base_urlObject

Returns the value of attribute base_url.



9
10
11
# File 'lib/locomotive/steam/models/entity.rb', line 9

def base_url
  @base_url
end

#localized_attributesObject

Returns the value of attribute localized_attributes.



9
10
11
# File 'lib/locomotive/steam/models/entity.rb', line 9

def localized_attributes
  @localized_attributes
end

Instance Method Details

#[](name) ⇒ Object



38
39
40
# File 'lib/locomotive/steam/models/entity.rb', line 38

def [](name)
  attributes[name]
end

#[]=(name, value) ⇒ Object



34
35
36
# File 'lib/locomotive/steam/models/entity.rb', line 34

def []=(name, value)
  attributes[name] = value
end

#_idObject



30
31
32
# File 'lib/locomotive/steam/models/entity.rb', line 30

def _id
  self['_id']
end

#change(new_attributes) ⇒ Object



42
43
44
45
# File 'lib/locomotive/steam/models/entity.rb', line 42

def change(new_attributes)
  attributes.merge!((new_attributes || {}).with_indifferent_access)
  self
end

#initialize(attributes) ⇒ Object



11
12
13
# File 'lib/locomotive/steam/models/entity.rb', line 11

def initialize(attributes)
  @attributes = attributes.with_indifferent_access
end

#respond_to?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/locomotive/steam/models/entity.rb', line 26

def respond_to?(name, include_private = false)
  attributes.include?(name.to_s) || super
end

#serializeObject



47
48
49
# File 'lib/locomotive/steam/models/entity.rb', line 47

def serialize
  attributes.dup
end