Module: Decoradar::ClassMethods
- Defined in:
- lib/decoradar.rb
Instance Method Summary collapse
- #attribute(name, options = {}) ⇒ Object
- #attributes(*names) ⇒ Object
- #decorate_collection(collection) ⇒ Object
- #inherited(child) ⇒ Object
Instance Method Details
#attribute(name, options = {}) ⇒ Object
41 42 43 44 45 |
# File 'lib/decoradar.rb', line 41 def attribute(name, = {}) attr = Attribute.new(.merge(name: name)) self.attribute_set << attr class_eval { def_delegators(:model, attr.name) } end |
#attributes(*names) ⇒ Object
37 38 39 |
# File 'lib/decoradar.rb', line 37 def attributes(*names) names.map { |name| attribute(name) } end |
#decorate_collection(collection) ⇒ Object
47 48 49 50 51 |
# File 'lib/decoradar.rb', line 47 def decorate_collection(collection) raise TypeError if !collection.respond_to?(:map) collection.map { |item| new(item) } end |
#inherited(child) ⇒ Object
53 54 55 56 57 |
# File 'lib/decoradar.rb', line 53 def inherited(child) child.attribute_set = attribute_set.dup super end |