Module: Locomotive::Mongoid::Presenter
- Extended by:
- ActiveSupport::Concern
- Included in:
- CustomFields::Field
- Defined in:
- lib/locomotive/mongoid/presenter.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
-
#from_presenter(attributes = {}) ⇒ Object
Set the attributes of the document by using the corresponding presenter.
-
#to_presenter(options = {}) ⇒ Object
Get the presenter corresponding to the current document.
Instance Method Details
#as_json(options = {}) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/locomotive/mongoid/presenter.rb', line 34 def as_json( = {}) if presenter = self.to_presenter() presenter.as_json else self.as_json_from_mongoid() end end |
#from_presenter(attributes = {}) ⇒ Object
Set the attributes of the document by using the corresponding presenter.
30 31 32 |
# File 'lib/locomotive/mongoid/presenter.rb', line 30 def from_presenter(attributes = {}) self.to_presenter.attributes = attributes end |
#to_presenter(options = {}) ⇒ Object
Get the presenter corresponding to the current document
20 21 22 23 |
# File 'lib/locomotive/mongoid/presenter.rb', line 20 def to_presenter( = {}) return nil unless self.class.presenter_class self.class.presenter_class.new(self, ) end |