Class: DecentDecoration::Decoration

Inherits:
Object
  • Object
show all
Defined in:
lib/decent_decoration/decorate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Decoration

Returns a new instance of Decoration.



6
7
8
9
# File 'lib/decent_decoration/decorate.rb', line 6

def initialize(name, options = {})
  self.name = name
  self.original_options = options
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/decent_decoration/decorate.rb', line 3

def name
  @name
end

#original_options=(value) ⇒ Object

Sets the attribute original_options

Parameters:

  • value

    the value to set the attribute original_options to.



3
4
5
# File 'lib/decent_decoration/decorate.rb', line 3

def original_options=(value)
  @original_options = value
end

Instance Method Details

#decorate_methodObject



23
24
25
26
27
28
29
30
31
# File 'lib/decent_decoration/decorate.rb', line 23

def decorate_method
  if decorate_collection? && decorator_class.respond_to?(:decorate_collection)
    :decorate_collection
  elsif decorator_class.respond_to?(:decorate)
    :decorate
  else
    :new
  end
end

#decorated_nameObject



11
12
13
# File 'lib/decent_decoration/decorate.rb', line 11

def decorated_name
  "decorated_#{name}".to_sym
end

#decorator_classObject



19
20
21
# File 'lib/decent_decoration/decorate.rb', line 19

def decorator_class
  original_options.fetch(:decorator) { infer_decorator_class }
end

#optionsObject



15
16
17
# File 'lib/decent_decoration/decorate.rb', line 15

def options
  original_options.except(:decorator, :collection)
end