Class: Scaffolder::Tool::Validate

Inherits:
Scaffolder::Tool
  • Object
show all
Defined in:
lib/scaffolder/tool/validate.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.descriptionObject



7
8
9
# File 'lib/scaffolder/tool/validate.rb', line 7

def self.description
  "Validate scaffold for overlapping inserts"
end

.inserts_overlap?(a, b) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/scaffolder/tool/validate.rb', line 37

def self.inserts_overlap?(a,b)
  ! (a.position.to_a & b.position.to_a).empty?
end

.sequence_errors(sequence) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/scaffolder/tool/validate.rb', line 41

def self.sequence_errors(sequence)
  sequence.inserts.inject(Array.new) do |errors,a|
    sequence.inserts.each do |b|
      next if a.equal?(b)
      errors << [a,b].sort if inserts_overlap?(a,b)
    end
    errors
  end.uniq
end

Instance Method Details

#errorsObject



32
33
34
35
# File 'lib/scaffolder/tool/validate.rb', line 32

def errors
  sequences = scaffold.select{|i| i.entry_type == :sequence}
  sequences.reject{|i| self.class.sequence_errors(i).empty? }
end

#executeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/scaffolder/tool/validate.rb', line 11

def execute
  bad_sequences = errors
  return if bad_sequences.empty?

  output = bad_sequences.inject(Array.new) do |array, sequence|
    self.class.sequence_errors(sequence).each do |overlaps|
      array << {'sequence-insert-overlap' => {
        'source' => sequence.source,
        'inserts' => overlaps.map do |overlap|
          {'open'  => overlap.open,
          'close'  => overlap.close,
          'source' => overlap.source}
        end
      }}
    end
    array
  end

  YAML.dump(output)
end