Class: GitShizzle::IndexSpecifications::Combined

Inherits:
Object
  • Object
show all
Defined in:
lib/git_shizzle/index_specifications/combined.rb

Instance Method Summary collapse

Constructor Details

#initialize(specs) ⇒ Combined

Returns a new instance of Combined.



5
6
7
# File 'lib/git_shizzle/index_specifications/combined.rb', line 5

def initialize(specs)
  @specs = specs
end

Instance Method Details

#apply(files) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/git_shizzle/index_specifications/combined.rb', line 29

def apply(files)
  result = files.each_with_index.map do |element, index|
    next unless include? index
    register_match index

    element
  end.compact

  unmatched_indexes = @specs.map do |spec|
    spec.unmatched
  end.flatten.compact.uniq.sort

  raise IndexSpecificationError.new(unmatched_indexes) if unmatched_indexes.any?

  result
end

#include?(index) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
# File 'lib/git_shizzle/index_specifications/combined.rb', line 9

def include?(index)
  index = humanize index

  @specs.any? do |spec|
    spec.include? index
  end
end

#register_match(index) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/git_shizzle/index_specifications/combined.rb', line 17

def register_match(index)
  index = humanize index

  @specs.each do |spec|
    spec.register_match index
  end
end

#unmatchedObject



25
26
27
# File 'lib/git_shizzle/index_specifications/combined.rb', line 25

def unmatched
  []
end