Module: BatchActions
- Defined in:
- lib/batch_actions.rb,
lib/batch_actions/version.rb,
lib/batch_actions/class_methods.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VERSION =
"0.0.2"
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/batch_actions.rb', line 32 def self.included(base) base.extend ClassMethods if defined?(InheritedResources::Base) && base < InheritedResources::Base base.batch_model base.resource_class end end |
Instance Method Details
#batch_actions ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/batch_actions.rb', line 5 def batch_actions return [] unless self.class.instance_variable_defined? :@batch_actions actions = self.class.instance_variable_get :@batch_actions allowed = [] actions.each do |keyword, condition| if instance_exec(&condition) allowed << keyword end end allowed end |
#dispatch_batch ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/batch_actions.rb', line 20 def dispatch_batch name = params[:batch_action] allowed = batch_actions.detect { |action| action.to_s == name.to_s } unless allowed raise ActionController::RoutingError.new('batch action is not allowed') end self.status, headers, self.response_body = self.class.action(:"batch_#{name}").call(env) self.headers.merge! headers end |