Module: Locomotive::Mongoid::Presenter::ClassMethods

Defined in:
lib/locomotive/mongoid/presenter.rb

Instance Method Summary collapse

Instance Method Details

#from_presenter(attributes) ⇒ Object

Initialize an instance of the document by passing attributes calculated by the associated presenter.

Parameters:

  • attributes (Hash)

    The document attributes

Returns:

  • (Object)

    A new document instance filled with the parameters



61
62
63
64
65
66
# File 'lib/locomotive/mongoid/presenter.rb', line 61

def from_presenter(attributes)
  new.tap do |document|
    presenter = document.to_presenter
    presenter.attributes = attributes
  end
end

#presenter_classClass

Return the memoized presenter class if it exists.

Returns:

  • (Class)

    The presenter class



48
49
50
51
52
# File 'lib/locomotive/mongoid/presenter.rb', line 48

def presenter_class
  return @presenter_class if @presenter_class
  _name             = "Locomotive::#{name.demodulize}Presenter"
  @presenter_class  = _name.constantize rescue nil
end