Class: SimpleMapper::Attributes::Manager
- Inherits:
-
Object
- Object
- SimpleMapper::Attributes::Manager
- Defined in:
- lib/simple_mapper/attributes.rb
Instance Attribute Summary collapse
-
#applies_to ⇒ Object
Returns the value of attribute applies_to.
Instance Method Summary collapse
- #attributes ⇒ Object
- #create_anonymous_mapper(&block) ⇒ Object
- #create_attribute(name, options = {}) ⇒ Object
-
#initialize(apply_to = nil) ⇒ Manager
constructor
A new instance of Manager.
- #install_attribute(attr, object) ⇒ Object
Constructor Details
#initialize(apply_to = nil) ⇒ Manager
Returns a new instance of Manager.
157 158 159 |
# File 'lib/simple_mapper/attributes.rb', line 157 def initialize(apply_to = nil) self.applies_to = apply_to if apply_to end |
Instance Attribute Details
#applies_to ⇒ Object
Returns the value of attribute applies_to.
155 156 157 |
# File 'lib/simple_mapper/attributes.rb', line 155 def applies_to @applies_to end |
Instance Method Details
#attributes ⇒ Object
161 162 163 |
# File 'lib/simple_mapper/attributes.rb', line 161 def attributes @attributes ||= {} end |
#create_anonymous_mapper(&block) ⇒ Object
180 181 182 183 184 185 186 187 188 189 |
# File 'lib/simple_mapper/attributes.rb', line 180 def create_anonymous_mapper(&block) mapper = Class.new do include SimpleMapper::Attributes def self.decode(*arg) new(*arg) end end mapper.module_eval &block if block_given? mapper end |
#create_attribute(name, options = {}) ⇒ Object
165 166 167 168 |
# File 'lib/simple_mapper/attributes.rb', line 165 def create_attribute(name, = {}) attrib_class = [:attribute_class] || SimpleMapper::Attribute attrib_class.new(name, ) end |
#install_attribute(attr, object) ⇒ Object
170 171 172 173 174 175 176 177 178 |
# File 'lib/simple_mapper/attributes.rb', line 170 def install_attribute(attr, object) read_body = Proc.new { read_attribute(attr) } write_body = Proc.new {|value| write_attribute(attr, value)} applies_to.module_eval do define_method(attr, &read_body) define_method(:"#{attr}=", &write_body) end attributes[attr] = object end |