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