Module: Apia::CallableWithEnvironment

Included in:
Authenticator, Endpoint
Defined in:
lib/apia/callable_with_environment.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **kwargs, &block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/apia/callable_with_environment.rb', line 30

def method_missing(name, *args, **kwargs, &block)
  if @environment.respond_to?(name)
    if kwargs.empty?
      return @environment.send(name, *args, &block)
    end

    return @environment.send(name, *args, **kwargs, &block)
  end

  super
end

Instance Method Details

#callObject



11
12
13
14
15
16
# File 'lib/apia/callable_with_environment.rb', line 11

def call
  action = self.class.definition.send(@action_name)
  return if action.nil?

  instance_exec(@environment.request, @environment.response, &action)
end

#call_with_error_handlingObject

rubocop:disable Lint/RescueException



19
20
21
22
23
# File 'lib/apia/callable_with_environment.rb', line 19

def call_with_error_handling
  call
rescue Exception => e
  raise_exception(e)
end

#initialize(environment, action_name: :action) ⇒ Object



6
7
8
9
# File 'lib/apia/callable_with_environment.rb', line 6

def initialize(environment, action_name: :action)
  @environment = environment
  @action_name = action_name
end

#respond_to_missing?(name, _include_private = false) ⇒ Boolean

rubocop:enable Lint/RescueException

Returns:

  • (Boolean)


26
27
28
# File 'lib/apia/callable_with_environment.rb', line 26

def respond_to_missing?(name, _include_private = false)
  @environment.respond_to?(name) || super
end