Class: WebMinion::Action
- Inherits:
-
Object
- Object
- WebMinion::Action
- Defined in:
- lib/web_minion/action.rb
Overview
Represents a group of steps that the bot can perform and valdiate have performed as expected
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#on_failure ⇒ Object
Returns the value of attribute on_failure.
-
#on_success ⇒ Object
Returns the value of attribute on_success.
-
#starting_action ⇒ Object
readonly
Returns the value of attribute starting_action.
-
#steps ⇒ Object
Returns the value of attribute steps.
Class Method Summary collapse
Instance Method Summary collapse
- #ending_action? ⇒ Boolean
- #generate_edges(all_actions) ⇒ Object
-
#initialize(fields = {}) ⇒ Action
constructor
A new instance of Action.
- #next_actions ⇒ Object
-
#perform(bot, saved_values) ⇒ Object
Again, boilerplate for initial setup.
- #starting_action? ⇒ Boolean
Constructor Details
#initialize(fields = {}) ⇒ Action
Returns a new instance of Action.
10 11 12 13 14 15 16 17 |
# File 'lib/web_minion/action.rb', line 10 def initialize(fields = {}) @name = fields[:name] @key = fields[:key] || @name @starting_action = fields[:starting] @on_success = fields[:on_success] @on_failure = fields[:on_failure] send("steps=", fields[:steps]) end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/web_minion/action.rb', line 7 def key @key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/web_minion/action.rb', line 7 def name @name end |
#on_failure ⇒ Object
Returns the value of attribute on_failure.
8 9 10 |
# File 'lib/web_minion/action.rb', line 8 def on_failure @on_failure end |
#on_success ⇒ Object
Returns the value of attribute on_success.
8 9 10 |
# File 'lib/web_minion/action.rb', line 8 def on_success @on_success end |
#starting_action ⇒ Object (readonly)
Returns the value of attribute starting_action.
7 8 9 |
# File 'lib/web_minion/action.rb', line 7 def starting_action @starting_action end |
#steps ⇒ Object
Returns the value of attribute steps.
7 8 9 |
# File 'lib/web_minion/action.rb', line 7 def steps @steps end |
Class Method Details
.build_from_hash(fields = {}, vars = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/web_minion/action.rb', line 19 def self.build_from_hash(fields = {}, vars = {}) steps = fields["steps"].map do |step| begin Step.new(step.merge("vars" => vars)) rescue NoValueForVariableError => e (step["skippable"] && (step["is_validator"].nil? || !step["is_validator"])) ? nil : raise(e, "Current step is missing variable. (step: #{step['name']})") end end steps = steps.reject(&:nil?) starting = (fields["starting"] || "false") == "false" ? false : true new(name: fields["name"], steps: steps, key: fields["key"], starting: starting, on_success: fields["on_success"], on_failure: fields["on_failure"]) end |
Instance Method Details
#ending_action? ⇒ Boolean
39 40 41 |
# File 'lib/web_minion/action.rb', line 39 def ending_action? @on_success.nil? end |
#generate_edges(all_actions) ⇒ Object
47 48 49 50 |
# File 'lib/web_minion/action.rb', line 47 def generate_edges(all_actions) @on_success = all_actions[on_success] @on_failure = all_actions[on_failure] end |
#next_actions ⇒ Object
43 44 45 |
# File 'lib/web_minion/action.rb', line 43 def next_actions [on_success, on_failure].compact end |
#perform(bot, saved_values) ⇒ Object
Again, boilerplate for initial setup
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/web_minion/action.rb', line 61 def perform(bot, saved_values) element = nil status = @steps.map do |step| if step.validator? step.perform(bot, element, saved_values) else if step.retain? step.perform(bot, element, saved_values) else element = step.perform(bot, element, saved_values) end nil end end !status.reject(&:nil?).include?(false) rescue StandardError => e puts e return false end |
#starting_action? ⇒ Boolean
35 36 37 |
# File 'lib/web_minion/action.rb', line 35 def starting_action? @starting_action end |