Method: Hanami::ClassMethods#expose

Defined in:
lib/hanami/interactor.rb

#expose(*instance_variable_names) ⇒ Object

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.

Exposes local instance variables into the returning value of #call

Examples:

Exposes instance variable


class Signup
  include Hanami::Interactor
  expose :user

  def initialize(params)
    @params = params
    @user   = User.new(@params[:user])
  end

  def call
    # ...
  end
end

result = Signup.new(user: { name: "Luca" }).call

result.user   # => #<User:0x007fa85c58ccd8 @name="Luca">
result.params # => NoMethodError

Parameters:

  • instance_variable_names (Symbol, Array<Symbol>)

    one or more instance variable names

See Also:

Since:

  • 0.5.0



616
617
618
619
620
# File 'lib/hanami/interactor.rb', line 616

def expose(*instance_variable_names)
  instance_variable_names.each do |name|
    exposures[name.to_sym] = "@#{name}"
  end
end