Class: Icing::Decorations::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/icing/decorations/base.rb

Direct Known Subclasses

Composite

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



24
25
26
27
28
29
30
# File 'lib/icing/decorations/base.rb', line 24

def method_missing(name, *args, &block)
  if name.to_s.start_with?('wrapping_')
    wrapping_other(*args)
  else
    super
  end
end

Instance Method Details

#decorated(object, method_name, *args, &block) ⇒ Object



4
5
6
# File 'lib/icing/decorations/base.rb', line 4

def decorated(object, method_name, *args, &block)
  object.public_send(method_name, *args, &block)
end

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

Returns:

  • (Boolean)


32
33
34
# File 'lib/icing/decorations/base.rb', line 32

def respond_to_missing?(method_name, include_private = false)
  method_name.to_s.start_with?('wrapping_') || super
end

#to_aObject



20
21
22
# File 'lib/icing/decorations/base.rb', line 20

def to_a
  [self]
end

#within(other) ⇒ Object



12
13
14
# File 'lib/icing/decorations/base.rb', line 12

def within(other)
  other.wrapping_other(self)
end

#wrapping(other) ⇒ Object



8
9
10
# File 'lib/icing/decorations/base.rb', line 8

def wrapping(other)
  other.within(self)
end

#wrapping_other(other) ⇒ Object



16
17
18
# File 'lib/icing/decorations/base.rb', line 16

def wrapping_other(other)
  decoration_factory.composite([other.to_a, self].flatten(1))
end