Class: InBedWith::Base
- Inherits:
-
Object
- Object
- InBedWith::Base
- Defined in:
- lib/in_bed_with/base.rb
Class Attribute Summary collapse
-
.attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/in_bed_with/base.rb', line 19 def initialize(attributes={}) attributes.symbolize_keys! self.class.attributes.each do |attribute, | value = attributes[attribute] || InBedWith.send(self.class.module_attr(attribute)) raise ArgumentError, missing(attribute) unless value || [:optional] self.send "#{attribute}=", value end end |
Class Attribute Details
.attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/in_bed_with/base.rb', line 4 def attributes @attributes end |
Class Method Details
.module_attr(attribute) ⇒ Object
14 15 16 |
# File 'lib/in_bed_with/base.rb', line 14 def module_attr(attribute) "#{name.demodulize.underscore}_#{attribute}" end |
.register(attribute, options = {}) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/in_bed_with/base.rb', line 6 def register(attribute, ={}) InBedWith.mattr_accessor module_attr(attribute) attr_accessor attribute @attributes ||= {} @attributes.merge!({ attribute.to_sym => }) end |