Class: Workflow

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/claws/workflow.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_yaml) ⇒ Workflow

Returns a new instance of Workflow.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/claws/workflow.rb', line 11

def initialize(raw_yaml)
  @workflow = YAMLWithLines.load(raw_yaml)

  # enriched metadata about the workflow as a whole
  @meta = {}

  normalize_dashes(@workflow)
  extract_normalized_on(@workflow)
  extract_normalized_jobs(@workflow)
  extract_normalized_name(@workflow)
  extract_permissions(@workflow)

  @raw_yaml = raw_yaml
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



7
8
9
# File 'lib/claws/workflow.rb', line 7

def data
  @data
end

#jobsObject

Returns the value of attribute jobs.



7
8
9
# File 'lib/claws/workflow.rb', line 7

def jobs
  @jobs
end

#metaObject

Returns the value of attribute meta.



7
8
9
# File 'lib/claws/workflow.rb', line 7

def meta
  @meta
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/claws/workflow.rb', line 7

def name
  @name
end

#onObject

Returns the value of attribute on.



7
8
9
# File 'lib/claws/workflow.rb', line 7

def on
  @on
end

#permissionsObject

Returns the value of attribute permissions.



7
8
9
# File 'lib/claws/workflow.rb', line 7

def permissions
  @permissions
end

Class Method Details

.load(blob) ⇒ Object



26
27
28
# File 'lib/claws/workflow.rb', line 26

def self.load(blob)
  Workflow.new(blob)
end

Instance Method Details

#[](key) ⇒ Object



34
35
36
37
38
# File 'lib/claws/workflow.rb', line 34

def [](key)
  return @on if key.to_s == "on"
  return @jobs if key.to_s == "jobs"
  return @name if key.to_s == "name"
end

#get_snippet(line, context: 3) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/claws/workflow.rb', line 40

def get_snippet(line, context: 3)
  buffer = ""
  (([0, line - context].max)..(line + context)).each do |i|
    next if @raw_yaml.lines[i].nil?

    buffer += if i + 1 == line
                ">>> #{@raw_yaml.lines[i]}"
              else
                @raw_yaml.lines[i]
              end
  end

  buffer
end

#ignoresObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/claws/workflow.rb', line 55

def ignores
  ignores = {}

  @raw_yaml.lines.each_with_index do |line, i|
    i += 1 # line numbers are one indexed

    matches = line.match(/^\s*#.*ignore: (.*)/)
    next if matches.nil?

    matches = matches[1].split(",").map(&:strip)
    ignores[i] = matches
  end

  ignores
end

#lineObject



30
31
32
# File 'lib/claws/workflow.rb', line 30

def line
  @workflow.line
end