Module: StrongPresenter::Associable::ClassMethods
- Defined in:
- lib/strong_presenter/associable.rb
Instance Method Summary collapse
-
#presents_association(association, options = {}) ⇒ Object
Automatically wraps multiple associations.
-
#presents_associations(*associations, options = {}) {|the| ... } ⇒ void
Automatically wraps multiple associations.
Instance Method Details
#presents_association(association, options = {}) ⇒ Object
Automatically wraps multiple associations. @param [Symbol] association name of the association to wrap. @option options [Class] :with the presenter to apply to the association. @option options [Symbol] :scope a scope to apply when fetching the association. @yield block executed when association presenter is initialized, in the context of the parent presenter instance (instance_exec-ed) @yieldparam [Presenter] the association presenter @return [void]
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/strong_presenter/associable.rb', line 21 def presents_association(association, = {}) .assert_valid_keys(:with, :scope) association = association.to_sym [:with] = .object_association_class(object_class, association) unless .has_key? :with presenter_associations[association] ||= StrongPresenter::PresenterAssociation.new(association, ) do |presenter| presenter. self, association yield presenter if block_given? end define_method(association) do presenter_associations[association] ||= self.class.send(:presenter_associations)[association].wrap(self) end end |
#presents_associations(*associations, options = {}) {|the| ... } ⇒ void
47 48 49 50 51 |
# File 'lib/strong_presenter/associable.rb', line 47 def presents_associations(*associations) = associations. .assert_valid_keys(:with, :scope) associations.each { |association| presents_association(association, ) {|presenter| yield if block_given?} } end |