Class: Workflowable::Actions::Action
- Inherits:
-
Object
- Object
- Workflowable::Actions::Action
- Defined in:
- lib/workflowable/actions/action.rb
Constant Summary collapse
- NAME =
""
- OPTIONS =
{}
Class Method Summary collapse
- .autocomplete(field_type = nil, value = nil, options = {}, workflow = nil, object = nil, current_stage = nil, next_stage = nil, user = nil) ⇒ Object
- .name ⇒ Object
- .options(options = {}, workflow = nil, object = nil, current_stage = nil, next_stage = nil, user = nil) ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}, workflow = nil, object = nil, current_stage = nil, next_stage = nil, user = nil) ⇒ Action
constructor
A new instance of Action.
- #run ⇒ Object
- #validate_options ⇒ Object
Constructor Details
#initialize(options = {}, workflow = nil, object = nil, current_stage = nil, next_stage = nil, user = nil) ⇒ Action
Returns a new instance of Action.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/workflowable/actions/action.rb', line 22 def initialize(={}, workflow=nil, object=nil, current_stage=nil, next_stage=nil, user=nil) ||={} @options = .with_indifferent_access @workflow = workflow @object = object @current_stage = current_stage @next_stage = next_stage @user = user errors = if(errors.present?) return errors end end |
Class Method Details
.autocomplete(field_type = nil, value = nil, options = {}, workflow = nil, object = nil, current_stage = nil, next_stage = nil, user = nil) ⇒ Object
43 44 |
# File 'lib/workflowable/actions/action.rb', line 43 def self.autocomplete(field_type=nil, value=nil, ={}, workflow=nil, object=nil, current_stage=nil, next_stage=nil, user=nil) end |
.name ⇒ Object
46 47 48 |
# File 'lib/workflowable/actions/action.rb', line 46 def self.name return self::NAME end |
.options(options = {}, workflow = nil, object = nil, current_stage = nil, next_stage = nil, user = nil) ⇒ Object
50 51 52 53 |
# File 'lib/workflowable/actions/action.rb', line 50 def self.(={}, workflow=nil, object=nil, current_stage=nil, next_stage=nil, user=nil) return self::OPTIONS.with_indifferent_access.deep_merge() end |
Instance Method Details
#run ⇒ Object
39 40 41 |
# File 'lib/workflowable/actions/action.rb', line 39 def run end |
#validate_options ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/workflowable/actions/action.rb', line 55 def errors = [] = self.class.(@options, @workflow, @object, @current_stage, @next_stage, @user) begin @options.assert_valid_keys(.keys) rescue ArgumentError=>e errors << "#{e.} for action: #{self.class.name}\n" end missing_keys = .reject{|k,v| v[:required] != true }.keys - @options.reject{|k,v| v[:value].blank? }.keys missing_keys.each do |k| errors << "#{k} is required\n" end return errors.blank? ? nil : errors end |