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

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

Overview

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

Exposures API class methods

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#expose(*names) ⇒ void

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.

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



58
59
60
61
62
63
64
65
66
# File 'lib/lotus/action/exposable.rb', line 58

def expose(*names)
  class_eval do
    names.each do |name|
      attr_reader(name) unless attr_reader?(name)
    end

    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



74
75
76
# File 'lib/lotus/action/exposable.rb', line 74

def exposures
  @exposures ||= []
end