Class: MingleModel

Inherits:
ActiveResource::Base
  • Object
show all
Defined in:
lib/models/mingle_model.rb

Direct Known Subclasses

Card, Comment

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/models/mingle_model.rb', line 7

def method_missing method_name, *args
  super method_name, *args
rescue NoMethodError
  match = get_attribute_value(method_name)
  match = get_property_value(method_name) if match.nil? and self.respond_to?(:properties)

  raise if match.nil?
  match
end

Instance Method Details

#get_attribute_value(name) ⇒ Object



17
18
19
# File 'lib/models/mingle_model.rb', line 17

def get_attribute_value name
  self.attributes[key_encode(name)]
end

#get_property_value(name) ⇒ Object



21
22
23
24
# File 'lib/models/mingle_model.rb', line 21

def get_property_value name
  property = self.properties.select{ |prop| key_encode(prop.name) == key_encode(name) }.first
  property.value || 'not set' unless property.nil?
end