Module: UtopiaData::Resource::Controllers

Included in:
UtopiaData::Resource
Defined in:
lib/utopia_data/resource/controllers.rb

Instance Method Summary collapse

Instance Method Details

#controllerObject

Returns the controller for this config



33
34
35
# File 'lib/utopia_data/resource/controllers.rb', line 33

def controller
  @controller ||= controller_name.constantize
end

#controller_nameObject

Returns a properly formatted controller name for this config within its namespace



28
29
30
# File 'lib/utopia_data/resource/controllers.rb', line 28

def controller_name
  [resource_name.plural.camelize + "Controller"].compact.join('::')
end

#create_resource_controllerObject

Create the resource controller



38
39
40
41
42
43
44
45
46
47
# File 'lib/utopia_data/resource/controllers.rb', line 38

def create_resource_controller
  controller_class = <<-CONTROLLER
    class ::#{controller_name} < UtopiaData::ResourceController
      responders Roar::Rails::Responder
    end
  CONTROLLER

  eval controller_class
  controller.utopia_config = self
end