lib/lotus/action/exposable.rb
# Expose the given attributes on the outside of the object with
# a getter and a special method called #exposures.
#
# @param names [Array<Symbol>] the name(s) of the attribute(s) to be
#   exposed
#
# @return [void]
#
# @since 0.1.0
#
# @example
#   require 'lotus/controller'
#
#   class Show
#     include Lotus::Action
#
#     expose :article, :tags
#
#     def call(params)
#       @article = Article.find params[:id]
#       @tags    = Tag.for(article)
#     end
#   end
#
#   action = Show.new
#   action.call({id: 23})
#
#   action.article # => #<Article ...>
#   action.tags    # => [#<Tag ...>, #<Tag ...>]
#
#   action.exposures # => { :article => #<Article ...>, :tags => [ ... ] }
Expose the given attributes on the outside of the object with
a getter and a special method called #exposures.
Expose the given attributes on the outside of the object with a getter and a special method called #exposures .
def expose(*names)
          class_eval do
            attr_reader(   *names)
            exposures.push(*names)
          end
        end
def expose ( * names ) class_eval do attr_reader ( * names ) exposures . push ( * names ) end end
Expose the given attributes on the outside of the object with
a getter and a special method called #exposures.
Expose the given attributes on the outside of the object with a getter and a special method called #exposures .
None
void
names
the name(s) of the attribute(s) to be exposed
the name ( s ) of the attribute ( s ) to be exposed
since
None
example
require 'lotus/controller' class Show include Lotus::Action expose :article, :tags def call(params) @article = Article.find params[:id] @tags = Tag.for(article) end end action = Show.new action.call({id: 23}) action.article # => # action.tags # => [#, #] action.exposures # => { :article => #, :tags => [ ...
require ' lotus / controller ' class Show include Lotus :: Action expose : article : tags def call ( params ) @article = Article . find params [ : id ] @tags = Tag . for ( article ) end end action = Show . new action . call ( { id : 23 } ) action . article # = > # action . tags # = > [ # # ] action . exposures # = > { : article = > # : tags = > [ ...