Module: Proxima::Attributes
- Included in:
- Model
- Defined in:
- lib/proxima/attributes.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
71 72 73 |
# File 'lib/proxima/attributes.rb', line 71 def self.included base base.extend ClassMethods end |
Instance Method Details
#attributes ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/proxima/attributes.rb', line 6 def attributes attributes_hash = {} self.class.attributes.each do |attribute, params| value = self.send attribute attributes_hash[attribute.to_s] = value end attributes_hash end |
#attributes=(params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/proxima/attributes.rb', line 15 def attributes=(params = {}) self.class.attributes.each do |attribute, attribute_params| value = params[attribute] if value == nil && default = attribute_params[:default] value = default.respond_to?(:call) ? default.call(self, params) : default end if value != nil && attribute_params[:klass] && !value.is_a?(attribute_params[:klass]) klass = attribute_params[:klass] value = klass.new value end self.send "#{attribute}=", value end end |