Module: Hanami::ClassMethods Private

Defined in:
lib/hanami/interactor.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.

Since:

  • 0.5.0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(interactor) ⇒ 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.

Since:

  • 0.5.0



596
597
598
599
600
601
602
603
# File 'lib/hanami/interactor.rb', line 596

def self.extended(interactor)
  interactor.class_eval do
    include Utils::ClassAttribute

    class_attribute :exposures
    self.exposures = {}
  end
end

Instance Method Details

#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



645
646
647
648
649
# File 'lib/hanami/interactor.rb', line 645

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

#method_added(method_name) ⇒ 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.

Since:

  • 0.5.0



605
606
607
608
609
610
611
612
613
614
# File 'lib/hanami/interactor.rb', line 605

def method_added(method_name)
  super
  return unless method_name == :call

  if instance_method(:call).arity.zero?
    prepend Hanami::Interactor::LegacyInterface
  else
    prepend Hanami::Interactor::Interface
  end
end