Class: Tomo::Configuration::RoleBasedTaskFilter
- Inherits:
-
Object
- Object
- Tomo::Configuration::RoleBasedTaskFilter
- Defined in:
- lib/tomo/configuration/role_based_task_filter.rb
Instance Method Summary collapse
- #add_role(name, task_specs) ⇒ Object
- #filter(tasks, host:) ⇒ Object
- #freeze ⇒ Object
-
#initialize ⇒ RoleBasedTaskFilter
constructor
A new instance of RoleBasedTaskFilter.
Constructor Details
#initialize ⇒ RoleBasedTaskFilter
Returns a new instance of RoleBasedTaskFilter.
6 7 8 |
# File 'lib/tomo/configuration/role_based_task_filter.rb', line 6 def initialize @globs = {} end |
Instance Method Details
#add_role(name, task_specs) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/tomo/configuration/role_based_task_filter.rb', line 15 def add_role(name, task_specs) name = name.to_s task_globs = Array(task_specs).flatten.map { |spec| Glob.new(spec) } task_globs.each do |task_glob| (globs[task_glob] ||= []) << name end end |
#filter(tasks, host:) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/tomo/configuration/role_based_task_filter.rb', line 23 def filter(tasks, host:) roles = host.roles roles = [""] if roles.empty? tasks.select do |task| roles.any? { |role| match?(task, role) } end end |
#freeze ⇒ Object
10 11 12 13 |
# File 'lib/tomo/configuration/role_based_task_filter.rb', line 10 def freeze globs.freeze super end |