Class: Azeroth::ControllerInterface Private

Inherits:
Object
  • Object
show all
Defined in:
lib/azeroth/controller_interface.rb

Overview

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

Interface for using the controller

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ ControllerInterface

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.

Returns a new instance of ControllerInterface.

Parameters:

  • controller (ApplicationController)


9
10
11
# File 'lib/azeroth/controller_interface.rb', line 9

def initialize(controller)
  @controller = controller
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object (private)

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.

Dispatcher to delegate all methods call to controller

Parameters:

  • method_name (Symbol)

    name of the method called

  • args (Array<Object>)

    arguments of the method called

Returns:

  • (Object)


81
82
83
84
85
86
87
# File 'lib/azeroth/controller_interface.rb', line 81

def method_missing(method_name, *args)
  if controller.respond_to?(method_name, true)
    controller.send(method_name, *args)
  else
    super
  end
end

Instance Method Details

#add_headers(headers_hash) ⇒ Hash

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 response headers

Parameters:

  • headers_hash (Hash)

    headers to be set

Returns:

  • (Hash)


18
19
20
21
22
23
24
# File 'lib/azeroth/controller_interface.rb', line 18

def add_headers(headers_hash)
  controller.instance_eval do
    headers_hash.each do |key, value|
      headers[key.to_s] = value
    end
  end
end

#render_json(json, status) ⇒ String

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.

Renders response json

Returns:

  • (String)


29
30
31
32
33
# File 'lib/azeroth/controller_interface.rb', line 29

def render_json(json, status)
  controller.instance_eval do
    render(json: json, status: status)
  end
end

#run(block) ⇒ 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.

Forces a controller to run a block

When the block is a Proc that is evaluated, when it is a Symbol or String, a method is called

Returns:

  • (Object)

    whatever the block returns



51
52
53
54
55
56
57
58
# File 'lib/azeroth/controller_interface.rb', line 51

def run(block)
  case block
  when Proc
    controller.instance_eval(&block)
  else
    controller.send(block)
  end
end

#set(variable, value) ⇒ 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.

Set a variable in the controller

Parameters:

  • variable (String, Symbol)

    variable name

  • value (Object)

    value to be set

Returns:

  • (Object)


41
42
43
# File 'lib/azeroth/controller_interface.rb', line 41

def set(variable, value)
  controller.instance_variable_set("@#{variable}", value)
end