Module: GardenVariety::Controller::ClassMethods
- Defined in:
- lib/garden_variety/controller.rb
Instance Method Summary collapse
-
#garden_variety(*actions) ⇒ void
Macro to include garden variety implementations of specified actions in the controller.
-
#model_class ⇒ Class
Returns the controller model class.
-
#model_class=(klass) ⇒ klass
Sets the controller model class.
Instance Method Details
#garden_variety(*actions) ⇒ void
This method returns an undefined value.
Macro to include garden variety implementations of specified actions in the controller. If no actions are specified, all typical REST actions (index, show, new, create, edit, update, destroy) are included.
See also:
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/garden_variety/controller.rb', line 55 def garden_variety(*actions) actions.each do |action| unless ::GardenVariety::ACTION_MODULES.key?(action) raise ArgumentError, "Invalid action: #{action.inspect}" end end action_modules = actions.empty? ? ::GardenVariety::ACTION_MODULES.values : ::GardenVariety::ACTION_MODULES.values_at(*actions) action_modules.each{|m| include m } end |
#model_class ⇒ Class
Returns the controller model class. Defaults to a class corresponding to the singular-form of the controller name.
79 80 81 |
# File 'lib/garden_variety/controller.rb', line 79 def model_class @model_class ||= controller_path.classify.constantize end |
#model_class=(klass) ⇒ klass
Sets the controller model class.
92 93 94 95 |
# File 'lib/garden_variety/controller.rb', line 92 def model_class=(klass) @model_name = nil @model_class = klass end |