module Decoradar::ClassMethods
Public Instance Methods
attribute(name, options = {})
click to toggle source
# File lib/decoradar.rb, line 43 def attribute(name, options = {}) attr = Attribute.new(options.merge(name: name)) self.attribute_set << attr class_eval { def_delegators(:model, attr.name) } end
attributes(*names)
click to toggle source
# File lib/decoradar.rb, line 39 def attributes(*names) names.map { |name| attribute(name) } end
collection(name, options = {})
click to toggle source
# File lib/decoradar.rb, line 49 def collection(name, options = {}) col = Collection.new(options.merge(name: name)) self.attribute_set << col class_eval { def_delegators(:model, col.name) } end
decorate_collection(collection)
click to toggle source
# 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)
click to toggle source
Calls superclass method
# File lib/decoradar.rb, line 61 def inherited(child) child.attribute_set = attribute_set.dup super end