Class: LittleDecorator

Inherits:
Object
  • Object
show all
Defined in:
lib/little_decorator.rb,
lib/little_decorator/helper.rb

Defined Under Namespace

Modules: Helper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record, view = nil) ⇒ LittleDecorator

Returns a new instance of LittleDecorator.



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

def initialize(record, view=nil)
  @record, @view = record, view
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



16
17
18
19
20
21
# File 'lib/little_decorator.rb', line 16

def method_missing(method_name, *args, &block)
  [record, view].each do |item|
    return item.public_send(method_name, *args, &block) if item.respond_to?(method_name)
  end
  super
end

Instance Attribute Details

#recordObject (readonly) Also known as: model

Returns the value of attribute record.



8
9
10
# File 'lib/little_decorator.rb', line 8

def record
  @record
end

#viewObject (readonly)

Returns the value of attribute view.



8
9
10
# File 'lib/little_decorator.rb', line 8

def view
  @view
end

Instance Method Details

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/little_decorator.rb', line 23

def respond_to_missing?(method_name, include_private=false)
  [record, view].any? { |item| item.respond_to?(method_name, include_private) }
end