Class: InstantApi::Controller::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/instant_api/controller/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller_name, method_names) ⇒ Builder

Returns a new instance of Builder.



16
17
18
19
20
21
# File 'lib/instant_api/controller/builder.rb', line 16

def initialize(controller_name, method_names)
  @controller_name = controller_name

  @method_names = method_names.map(&:to_sym)
  @method_names << :resource if @method_names != [:index]
end

Instance Attribute Details

#controller_nameObject (readonly)

Returns the value of attribute controller_name.



15
16
17
# File 'lib/instant_api/controller/builder.rb', line 15

def controller_name
  @controller_name
end

#method_namesObject (readonly)

Returns the value of attribute method_names.



15
16
17
# File 'lib/instant_api/controller/builder.rb', line 15

def method_names
  @method_names
end

Instance Method Details

#build_classObject



23
24
25
26
27
28
29
30
# File 'lib/instant_api/controller/builder.rb', line 23

def build_class
  controller_class_name = "#{controller_name.camelize}Controller"
  controller = Class.new(ActionController::API)
  controller.send(:include, InstantApi::Controller::ExceptionHandler)
  build_methods(controller)

  Object.const_set(controller_class_name, controller)
end