Class: DTK::Shell::OverrideTasks
- Inherits:
-
Hash
- Object
- Hash
- DTK::Shell::OverrideTasks
- Defined in:
- lib/shell/domain/override_tasks.rb
Instance Attribute Summary collapse
-
#always_load_list ⇒ Object
Returns the value of attribute always_load_list.
-
#completed_tasks ⇒ Object
Returns the value of attribute completed_tasks.
Instance Method Summary collapse
- #add_to_completed(child_name) ⇒ Object
-
#are_there_self_override_tasks? ⇒ Boolean
returns true if there are overrides for tasks on first two levels.
- #check_help_item(help_item, is_command) ⇒ Object
-
#get_all_tasks(child_name) ⇒ Object
returns 2 arrays one for commands and next one for identifiers.
-
#initialize(hash = nil, always_load_listed = []) ⇒ OverrideTasks
constructor
using ‘always load listed’ to skip adding task to completed tasks e.g load utils for workspace and workspace_node.
- #is_completed?(child_name) ⇒ Boolean
Constructor Details
#initialize(hash = nil, always_load_listed = []) ⇒ OverrideTasks
using ‘always load listed’ to skip adding task to completed tasks e.g load utils for workspace and workspace_node
41 42 43 44 45 46 |
# File 'lib/shell/domain/override_tasks.rb', line 41 def initialize(hash=nil, always_load_listed=[]) super(hash) @completed_tasks = [] @always_load_list = always_load_listed self.merge!(hash) end |
Instance Attribute Details
#always_load_list ⇒ Object
Returns the value of attribute always_load_list.
27 28 29 |
# File 'lib/shell/domain/override_tasks.rb', line 27 def always_load_list @always_load_list end |
#completed_tasks ⇒ Object
Returns the value of attribute completed_tasks.
26 27 28 |
# File 'lib/shell/domain/override_tasks.rb', line 26 def completed_tasks @completed_tasks end |
Instance Method Details
#add_to_completed(child_name) ⇒ Object
82 83 84 |
# File 'lib/shell/domain/override_tasks.rb', line 82 def add_to_completed(child_name) @completed_tasks << child_name end |
#are_there_self_override_tasks? ⇒ Boolean
returns true if there are overrides for tasks on first two levels.
49 50 51 |
# File 'lib/shell/domain/override_tasks.rb', line 49 def are_there_self_override_tasks? return (self[:all][:self] || self[:command_only][:self] || self[:identifier_only][:self]) end |
#check_help_item(help_item, is_command) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/shell/domain/override_tasks.rb', line 53 def check_help_item(help_item, is_command) command_tasks, identifier_tasks = get_all_tasks(:self) found = [] if is_command found = command_tasks.select { |o_task| o_task[0].eql?(help_item[2]) } else found = identifier_tasks.select { |o_task| o_task[0].eql?(help_item[2]) } end # if we find self overriden task we remove it # [found.first[1],found.first[2],found.first[0]] => we convert from o_task structure to thor help structure return found.empty? ? help_item : [found.first[1],found.first[2],found.first[0]] end |
#get_all_tasks(child_name) ⇒ Object
returns 2 arrays one for commands and next one for identifiers
69 70 71 72 73 74 |
# File 'lib/shell/domain/override_tasks.rb', line 69 def get_all_tasks(child_name) command_o_tasks, identifier_o_tasks = [], [] command_o_tasks = (self[:all][child_name]||[]) + (self[:command_only][child_name]||[]) identifier_o_tasks = (self[:all][child_name]||[]) + (self[:identifier_only][child_name]||[]) return command_o_tasks, identifier_o_tasks end |
#is_completed?(child_name) ⇒ Boolean
76 77 78 79 80 |
# File 'lib/shell/domain/override_tasks.rb', line 76 def is_completed?(child_name) # do not add task to completed if explicitly said to always load that task return false if @always_load_list.include?(child_name) @completed_tasks.include?(child_name) end |