Class: ResourceFull::Base

Inherits:
ActionController::Base
  • Object
show all
Defined in:
lib/resource_full/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all_resourcesObject

Returns the list of all resources handled by ResourceFull.



14
15
16
17
18
19
20
# File 'lib/resource_full/base.rb', line 14

def all_resources
  ActionController::Routing.possible_controllers.map do |possible_controller|
    controller_for(possible_controller)
  end.select do |controller_class|
    controller_class.ancestors.include?(self)
  end
end

.controller_for(resource) ⇒ Object

Returns the controller for the given resource.



23
24
25
26
27
28
# File 'lib/resource_full/base.rb', line 23

def controller_for(resource)
  return resource if resource.is_a?(Class) && resource.ancestors.include?(ActionController::Base)
  "#{resource.to_s.underscore}_controller".classify.constantize
rescue NameError
  raise ResourceFull::ResourceNotFound, "not found: #{resource}"
end

Instance Method Details

#model_classObject



10
# File 'lib/resource_full/base.rb', line 10

def model_class; self.class.model_class; end

#model_nameObject



9
# File 'lib/resource_full/base.rb', line 9

def model_name; self.class.model_name; end