Module: Decoradar::ClassMethods

Defined in:
lib/decoradar.rb

Instance Method Summary collapse

Instance Method Details

#attribute(name, options = {}) ⇒ Object



41
42
43
44
45
# File 'lib/decoradar.rb', line 41

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) ⇒ Object



37
38
39
# File 'lib/decoradar.rb', line 37

def attributes(*names)
  names.map { |name| attribute(name) }
end

#decorate_collection(collection) ⇒ Object

Raises:

  • (TypeError)


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