module StrongPresenter::Associable::ClassMethods
Public Instance Methods
presents_association(association, options = {}) { |presenter| ... }
click to toggle source
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]
# File lib/strong_presenter/associable.rb, line 21 def presents_association(association, options = {}) options.assert_valid_keys(:with, :scope) association = association.to_sym options[:with] = Associable.object_association_class(object_class, association) unless options.has_key? :with presenter_associations[association] ||= StrongPresenter::PresenterAssociation.new(association, options) do |presenter| presenter.link_permissions 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) { || ... }
click to toggle source
@overload presents_associations
(*associations, options = {})
Automatically wraps multiple associations. @param [Symbols*] associations names of the associations 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]
# File lib/strong_presenter/associable.rb, line 47 def presents_associations(*associations) options = associations.extract_options! options.assert_valid_keys(:with, :scope) associations.each { |association| presents_association(association, options) {|presenter| yield if block_given?} } end
Private Instance Methods
presenter_associations()
click to toggle source
# File lib/strong_presenter/associable.rb, line 54 def presenter_associations @presenter_associations ||= {} end