Module: Hanami::Action::Exposable::ClassMethods Private

Defined in:
lib/hanami/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 Also known as: _expose

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 'hanami/controller'

class Show
  include Hanami::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


65
66
67
68
69
70
71
72
73
# File 'lib/hanami/action/exposable.rb', line 65

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


85
86
87
# File 'lib/hanami/action/exposable.rb', line 85

def exposures
  @exposures ||= []
end