Module: ActsAsDynamic::Base

Defined in:
lib/acts_as_dynamic/base.rb

Overview

Base

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(attribute, value = "") ⇒ Object

Method missing



25
26
27
28
29
30
31
32
33
34
# File 'lib/acts_as_dynamic/base.rb', line 25

def method_missing(attribute, value = "")
  # Assignation?
  if attribute.to_s["="]
    # Adding attribute
    metaclass.send :attr_accessor, attribute.to_s[/[^=]+/]
    self.send attribute, value
  else
    nil
  end
end

Instance Method Details

#initialize(args = {}) ⇒ Object

Builder



10
11
12
13
14
15
# File 'lib/acts_as_dynamic/base.rb', line 10

def initialize args = {}
  (args || {}).each_pair do |attribute, value|
    self.send "#{attribute}=", value
  end
  self
end

#metaclassObject

Metaclass



18
19
20
21
22
# File 'lib/acts_as_dynamic/base.rb', line 18

def metaclass
  class << self
    self
  end
end

#new_record?Boolean

New record?

Returns:

  • (Boolean)


37
38
39
# File 'lib/acts_as_dynamic/base.rb', line 37

def new_record?
  true
end

#persisted?Boolean

Persisted?

Returns:

  • (Boolean)


42
43
44
# File 'lib/acts_as_dynamic/base.rb', line 42

def persisted?
  false
end