Class: ArtDeco::Decorator
- Inherits:
-
Object
- Object
- ArtDeco::Decorator
show all
- Defined in:
- lib/art_deco/decorator.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(component) ⇒ Decorator
Returns a new instance of Decorator.
5
6
7
8
|
# File 'lib/art_deco/decorator.rb', line 5
def initialize(component)
self.instance_variable_set "@#{component.class.name.downcase}".to_sym, component
@component = component
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/art_deco/decorator.rb', line 26
def method_missing(method_name, *args, &block)
if @component.respond_to?(method_name)
@component.send(method_name, *args)
else
super
end
end
|
Instance Attribute Details
#component ⇒ Object
Returns the value of attribute component.
3
4
5
|
# File 'lib/art_deco/decorator.rb', line 3
def component
@component
end
|
Class Method Details
.factory(component) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/art_deco/decorator.rb', line 38
def self.factory(component)
begin
"#{component.class.name}Decorator".constantize.new(component)
rescue
ArtDeco::Decorator.new(component)
end
end
|
.method_missing(method_name, *args, &block) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/art_deco/decorator.rb', line 46
def self.method_missing(method_name, *args, &block)
if self.constant_name.constantize.respond_to?(method_name)
self.constant_name.constantize.send(method_name, *args, &block)
else
super
end
end
|
.respond_to_missing?(method_name, include_private = false) ⇒ Boolean
54
55
56
|
# File 'lib/art_deco/decorator.rb', line 54
def self.respond_to_missing?(method_name, include_private = false)
self.constant_name.constantize.respond_to?(method_name)
end
|
.wrap(collection) ⇒ Object
20
21
22
|
# File 'lib/art_deco/decorator.rb', line 20
def self.wrap(collection)
collection.map{ |component| ArtDeco::Decorator.factory(component) }
end
|
Instance Method Details
#helpers ⇒ Object
Also known as:
h
10
11
12
|
# File 'lib/art_deco/decorator.rb', line 10
def helpers
ViewContext.current
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
34
35
36
|
# File 'lib/art_deco/decorator.rb', line 34
def respond_to_missing?(method_name, include_private = false)
@component.respond_to?(method_name)
end
|
#translate(*args) ⇒ Object
Also known as:
t
16
17
18
|
# File 'lib/art_deco/decorator.rb', line 16
def translate(*args)
I18n.translate(*args)
end
|