Module: SimpleMapper::SimpleModel

Defined in:
lib/simple_mapper/default_plugins/simple_model.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/simple_mapper/default_plugins/simple_model.rb', line 15

def method_missing(method, *args)
  if self.class.properties.include?(method.to_s)
    instance_variable_get('@'+method.to_s)
  elsif method.to_s =~ /=$/ && self.class.properties.include?(method.to_s.gsub(/=/, ''))
    instance_variable_set('@'+method.to_s.gsub(/=/, ''), *args)
  else
    super
  end
end

Class Method Details

.included(base) ⇒ Object



3
4
5
# File 'lib/simple_mapper/default_plugins/simple_model.rb', line 3

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

Instance Method Details

#identifierObject



11
12
13
# File 'lib/simple_mapper/default_plugins/simple_model.rb', line 11

def identifier
  instance_variable_get('@'+self.class.identifier)
end

#to_hash(options = {}) ⇒ Object



7
8
9
# File 'lib/simple_mapper/default_plugins/simple_model.rb', line 7

def to_hash(options={})
  self.class.properties.inject({}) {|h,k| h[k] = instance_variable_get("@#{k}"); h}
end