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
42 43 44 45 46 |
# File 'lib/decoradar.rb', line 42 def attribute(name, = {}) attr = Attribute.new(.merge(name: name)) self.attribute_set << attr class_eval { def_delegators(:model, attr.name) } end |
#attributes(*names) ⇒ Object
38 39 40 |
# File 'lib/decoradar.rb', line 38 def attributes(*names) names.map { |name| attribute(name) } end |
#collection(name, options = {}) ⇒ Object
48 49 50 51 52 |
# File 'lib/decoradar.rb', line 48 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
54 55 56 57 58 |
# File 'lib/decoradar.rb', line 54 def decorate_collection(collection) raise TypeError if !collection.respond_to?(:map) collection.map { |item| new(item) } end |
#inherited(child) ⇒ Object
60 61 62 63 64 |
# File 'lib/decoradar.rb', line 60 def inherited(child) child.attribute_set = attribute_set.dup super end |