Module: Lotus::Action::Exposable::ClassMethods

Defined in:
lib/lotus/action/exposable.rb

Overview

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#expose(*names) ⇒ void

This method returns an undefined value.

Expose the given attributes on the outside of the object with a getter and a special method called #exposures.

Examples:

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 => [ ... ] }

Parameters:

  • names (Array<Symbol>)

    the name(s) of the attribute(s) to be exposed

Since:

  • 0.1.0



47
48
49
50
51
52
# File 'lib/lotus/action/exposable.rb', line 47

def expose(*names)
  class_eval do
    attr_reader    *names
    exposures.push *names
  end
end

#exposuresArray

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set of exposures attribute names

Returns:

  • (Array)

    the exposures attribute names

Since:

  • 0.1.0



60
61
62
# File 'lib/lotus/action/exposable.rb', line 60

def exposures
  @exposures ||= []
end