Module: Decco

Defined in:
lib/decco.rb,
lib/decco/helpers.rb,
lib/decco/railtie.rb,
lib/decco/version.rb

Defined Under Namespace

Modules: Helpers Classes: DecoratorNotFound, Railtie

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.builder(object, decorator, view) ⇒ Mixed

Get decorator

Returns:

  • (Mixed)

See Also:



26
27
28
29
30
# File 'lib/decco.rb', line 26

def self.builder(object, decorator, view)
  decorator || begin
    [object.class.to_s, 'Decorator'].join('').classify.constantize
  end.new(object, view)
end

.decorate(object, decorator = nil, view = nil) ⇒ Mixed

Decorate an object

Parameters:

  • Object (Object)

    to decorate

  • Decorator (Mixed)

    to use, default to <Class>Decorator

  • View (Mixed)

    context

Returns:

  • (Mixed)


15
16
17
18
19
20
# File 'lib/decco.rb', line 15

def self.decorate(object, decorator = nil, view = nil)
  @_d ||= {}
  @_d[object] ||= builder(object, decorator, view)
rescue NameError
  raise DecoratorNotFound
end