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



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

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.



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

def associations
  @associations
end

#attributesObject

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

#base_urlObject

Returns the value of attribute base_url.



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

def base_url
  @base_url
end

#localized_attributesObject

Returns the value of attribute localized_attributes.



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

def localized_attributes
  @localized_attributes
end

Instance Method Details

#[](name) ⇒ Object



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

def [](name)
  attributes[name]
end

#[]=(name, value) ⇒ Object



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

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

#_idObject



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

def _id
  self['_id']
end

#change(new_attributes) ⇒ Object



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

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

#initialize(attributes) ⇒ Object



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

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

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

Returns:

  • (Boolean)


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

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

#serializeObject



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

def serialize
  attributes.dup
end