Class: Workflowable::Action

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/workflowable/action.rb

Instance Method Summary collapse

Instance Method Details

#action_plugin_nameObject



108
109
110
# File 'app/models/workflowable/action.rb', line 108

def action_plugin_name
  ("Workflowable::Actions::"+action_plugin).constantize.name
end

#action_plugin_optionsObject



103
104
105
# File 'app/models/workflowable/action.rb', line 103

def action_plugin_options
  ("Workflowable::Actions::"+action_plugin).constantize.options
end

#autocomplete(field_type, value, options = {}, workflow = nil, object = nil, current_stage = nil, next_stage = nil, user = nil) ⇒ Object



46
47
48
# File 'app/models/workflowable/action.rb', line 46

def autocomplete(field_type, value, options={}, workflow=nil, object=nil, current_stage=nil, next_stage=nil, user=nil)
  ("Workflowable::Actions::"+action_plugin).constantize.autocomplete(field_type, value, options, workflow, object, current_stage, next_stage, user)
end

#available_options(options = {}, workflow = nil, object = nil, current_stage = nil, next_stage = nil, user = nil) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/models/workflowable/action.rb', line 67

def available_options(options={}, workflow=nil, object=nil, current_stage=nil, next_stage=nil, user=nil)
  options ||={}

  # value_options = options.with_indifferent_access.deep_dup.each{|k1,v1|
  #   v1.reject!{|k2,v2| k2!= "value" || v2.blank?};
  #   v1[:user_specified]=true;
  # }
  # default_options = options.with_indifferent_access.deep_dup.each{ |k1,v1|
  #   v1.reject!{|k2,v2| k2!= "default" || v2.blank? }
  # }



  value_options = options.with_indifferent_access.each{|k1,v1|
    v1.reject{|k2,v2| k2 != "value" || v2.blank?};
    v1[:user_specified]=true;
  }



  default_options = options.with_indifferent_access.each{ |k1,v1|
    v1.reject{|k2,v2| k2 != "default" || v2.blank? }
  }

  options = self.options.with_indifferent_access.deep_merge(default_options)

  options = value_options.with_indifferent_access.deep_merge(options)
  if(action_plugin)
    all_options = ("Workflowable::Actions::"+action_plugin).constantize.options(options, workflow, object, current_stage, next_stage, user)
  else
    all_options = {}
  end


end

#reject_blank_valuesObject



30
31
32
33
# File 'app/models/workflowable/action.rb', line 30

def reject_blank_values
  options.each{|k,v| v.reject!{ |k,v| v.blank? }}
  options.reject!{|k,v| v.blank?}
end

#run(options = {}, workflow, object, current_stage, next_stage, user) ⇒ Object



51
52
53
54
55
56
# File 'app/models/workflowable/action.rb', line 51

def run(options={}, workflow, object, current_stage, next_stage, user)
  options ||={}
  plugin = ("Workflowable::Actions::"+action_plugin).constantize#("Workflowable::Actions::" + self.action_plugin.to_s).constantize
  plugin.new(self.available_options(options), workflow, object, current_stage, next_stage, user).run

end

#validate_action_pluginObject



35
36
37
38
39
40
41
42
43
44
# File 'app/models/workflowable/action.rb', line 35

def validate_action_plugin
  begin
    if(Workflowable::Actions.constants.include?(action_plugin.to_sym))
      #if(Workflowable::Actions::Action.subclasses.include?(("Workflowable::Actions::"+action_plugin).constantize))
      return true
    end
  rescue
  end
  errors.add :action_plugin, "is invalid"
end

#validate_options(options = {}, workflow = nil, object = nil, current_stage = nil, next_stage = nil, user = nil) ⇒ Object



59
60
61
62
63
64
# File 'app/models/workflowable/action.rb', line 59

def validate_options(options={}, workflow=nil, object=nil, current_stage=nil, next_stage=nil, user=nil)
  plugin = ("Workflowable::Actions::"+action_plugin).constantize#("Workflowable::Actions::" + self.action_plugin.to_s).constantize
  results = plugin.new(self.available_options(options), workflow, object, current_stage, next_stage, user).validate_options

  return results
end