module ContextExposer::ResourceController::ClassMethods

Public Instance Methods

_exposing(name, options = {}) click to toggle source

for use in ResourceController

# File lib/context_exposer/resource_controller.rb, line 49
def _exposing name, options = {}, &block
  exposed name, options, &block
end
_the_resource() click to toggle source
# File lib/context_exposer/resource_controller.rb, line 53
def _the_resource
  clazz_name = self.to_s.sub(/Controller$/, '').singularize
  clazz_name.constantize
rescue NameError => e
  raise "Resource #{clazz_name} is not defined. #{e}"
end
expose_resource_method?(type, types) click to toggle source
# File lib/context_exposer/resource_controller.rb, line 29
def expose_resource_method? type, types
  ([type, :all] & types).empty?
end
expose_resources(*types) click to toggle source
# File lib/context_exposer/resource_controller.rb, line 12
def expose_resources *types
  types = types.flatten
  types = types.empty? ? [:all] : types

  unless expose_resource_method? :one, types
    _exposing(normalized_resource_name.singularize)  { find_single_resource    }
  end

  unless expose_resource_method? :many, types
    _exposing(normalized_resource_name.pluralize)    { find_all_resources      }
  end

  unless expose_resource_method? :list, types
    _exposing(normalized_resource_list)              { find_all_resources.to_a }
  end
end
normalized_resource_list() click to toggle source
# File lib/context_exposer/resource_controller.rb, line 60
def normalized_resource_list
  normalized_resource_name.singularize + '_list'
end