Class: DeployPin::TaskCriteria

Inherits:
Object
  • Object
show all
Defined in:
lib/deploy_pin/task_criteria.rb

Constant Summary collapse

SKIP_REGEXEP =
/\A!(.+[^!])\z/
FORCE_REGEXP =
/\A([^!].+)!\z/
COMMON_REGEXP =
/(^[^!]?.+[^!]?$)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifiers:) ⇒ TaskCriteria

Returns a new instance of TaskCriteria.



12
13
14
# File 'lib/deploy_pin/task_criteria.rb', line 12

def initialize(identifiers:)
  @identifiers = identifiers
end

Instance Attribute Details

#identifiersObject (readonly)

Returns the value of attribute identifiers.



10
11
12
# File 'lib/deploy_pin/task_criteria.rb', line 10

def identifiers
  @identifiers
end

Instance Method Details

#suitable?(task) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/deploy_pin/task_criteria.rb', line 16

def suitable?(task)
  task_cover = lambda { |task, regexp|
    items = identifiers.flat_map { |x| x.to_s.scan(regexp) }.flatten

    items & [task.group, task.identifier.to_s]
  }

  return false if task_cover.call(task, SKIP_REGEXEP).any?
  return true if task_cover.call(task, FORCE_REGEXP).any?

  task_cover.call(task, COMMON_REGEXP).any? && !task.done?
end