Class: Workflowable::Actions::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/workflowable/actions/action.rb

Constant Summary collapse

NAME =
""
OPTIONS =
{}

Class Method Summary collapse

Instance Method Summary collapse

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(options={}, workflow=nil, object=nil, current_stage=nil, next_stage=nil, user=nil)
    options ||={}
    @options = options.with_indifferent_access
    @workflow = workflow
    @object = object
    @current_stage = current_stage
    @next_stage = next_stage
    @user = user

    errors = validate_options

    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, options={}, workflow=nil, object=nil, current_stage=nil, next_stage=nil, user=nil)
end

.nameObject



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.options(options={}, workflow=nil, object=nil, current_stage=nil, next_stage=nil, user=nil)

    return self::OPTIONS.with_indifferent_access.deep_merge(options)
end

Instance Method Details

#runObject



39
40
41
# File 'lib/workflowable/actions/action.rb', line 39

def run

end

#validate_optionsObject



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 validate_options
    errors = []
    current_options = self.class.options(@options, @workflow, @object, @current_stage, @next_stage, @user)
    begin

        @options.assert_valid_keys(current_options.keys)
    rescue ArgumentError=>e
        errors << "#{e.message} for action: #{self.class.name}\n"
    end

    missing_keys = current_options.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