Module: AsJsonPresentable
- Defined in:
- lib/as_json_presentable.rb,
lib/as_json_presentable/presenter.rb
Defined Under Namespace
Modules: ClassMethods Classes: Presenter
Class Method Summary collapse
Instance Method Summary collapse
-
#as_json(options = nil) ⇒ Object
Attempts to delegate to the presenter class’s ‘#as_json` if it exists, and falls back to the parent class’s implementation if it does not.
-
#json_presenter_class ⇒ Object
Returns the presenter class, or nil if no presenter class exists.
Class Method Details
.included(klass) ⇒ Object
5 6 7 |
# File 'lib/as_json_presentable.rb', line 5 def self.included(klass) klass.extend ClassMethods end |
Instance Method Details
#as_json(options = nil) ⇒ Object
Attempts to delegate to the presenter class’s ‘#as_json` if it exists, and falls back to the parent class’s implementation if it does not.
12 13 14 15 16 17 18 |
# File 'lib/as_json_presentable.rb', line 12 def as_json(=nil) if && [:presenter_action] && json_presenter_class json_presenter_class.new(self).as_json() else super() end end |
#json_presenter_class ⇒ Object
Returns the presenter class, or nil if no presenter class exists
22 23 24 |
# File 'lib/as_json_presentable.rb', line 22 def json_presenter_class self.class.json_presenter_class end |