Module: ContextExposer::ResourceController::ClassMethods
- Defined in:
- lib/context_exposer/resource_controller.rb,
lib/context_exposer/resource_controller.rb
Instance Method Summary collapse
-
#_exposing(name, options = {}, &block) ⇒ Object
for use in ResourceController.
- #_the_resource ⇒ Object
- #expose_resource_method?(type, types) ⇒ Boolean
- #expose_resources(*types) ⇒ Object
- #normalized_resource_list ⇒ Object
Instance Method Details
#_exposing(name, options = {}, &block) ⇒ Object
for use in ResourceController
49 50 51 |
# File 'lib/context_exposer/resource_controller.rb', line 49 def _exposing name, = {}, &block exposed name, , &block end |
#_the_resource ⇒ Object
53 54 55 56 57 58 |
# 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) ⇒ Boolean
29 30 31 |
# File 'lib/context_exposer/resource_controller.rb', line 29 def expose_resource_method? type, types ([type, :all] & types).empty? end |
#expose_resources(*types) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# 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 ⇒ Object
60 61 62 |
# File 'lib/context_exposer/resource_controller.rb', line 60 def normalized_resource_list normalized_resource_name.singularize + '_list' end |