Module: Depict::Presentable::InstanceMethods
- Defined in:
- lib/depict/presentable.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/depict/presentable.rb', line 88
def method_missing(method, *args)
names = self.class.depict_presentations.keys
match = /^to_(#{names.join("|")})_presentation$/.match(method.to_s)
if match
to_presentation(match[1].to_sym)
else
super(method, *args)
end
end
|
Instance Method Details
#respond_to?(method, include_private = false) ⇒ Boolean
78
79
80
81
82
83
84
85
86
|
# File 'lib/depict/presentable.rb', line 78
def respond_to?(method, include_private=false)
names = self.class.depict_presentations.keys
if /^to_(#{names.join("|")})_presentation$/ =~ method.to_s
true
else
super(method, include_private)
end
end
|
#to_presentation(presentation) ⇒ Object
68
69
70
71
72
73
74
75
76
|
# File 'lib/depict/presentable.rb', line 68
def to_presentation(presentation)
presenter = self.class.depict_presentations[presentation]
if presenter
presenter.new(self).to_hash
else
{}
end
end
|