Class: OrigenTesters::Doc::Generator::FlowLine

Inherits:
Object
  • Object
show all
Defined in:
lib/origen_testers/doc/generator/flow_line.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, attrs = {}) ⇒ FlowLine

Returns a new instance of FlowLine.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 7

def initialize(type, attrs = {})
  @type = type
  @test = attrs.delete(:test)
  @context = {}
  @attributes = {}
  flow_control_options = Origen.interface.extract_flow_control_options!(attrs)
  flow_control_options.each do |opt, val|
    send("#{opt}=", val)
  end
  attrs.each do |attribute, val|
    @attributes[attribute] = val
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &_block) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 80

def method_missing(method, *args, &_block)
  method = method.to_s
  if method.gsub!('=', '')
    @attributes[method] = args.first
  else
    @attributes[method]
  end
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



5
6
7
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 5

def attributes
  @attributes
end

#contextObject

Returns the value of attribute context.



5
6
7
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 5

def context
  @context
end

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 5

def description
  @description
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 5

def id
  @id
end

#testObject

Returns the value of attribute test.



5
6
7
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 5

def test
  @test
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 5

def type
  @type
end

Class Method Details

.unique_counterObject



190
191
192
193
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 190

def self.unique_counter
  @ix ||= -1
  @ix += 1
end

Instance Method Details

#attributes_to_yaml(_options = {}) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 38

def attributes_to_yaml(_options = {})
  a = {}
  @attributes.each do |name, val|
    a[name.to_s] = val if val
  end
  a
end

#context_to_yaml(_options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 46

def context_to_yaml(_options = {})
  # Turn attribute keys into strings for prettier yaml, this includes all
  # relationship meta data
  c = @context.reduce({}) { |memo, (k, v)| memo[k.to_s] = v; memo }
  # Now add job/enable word data
  if @enable
    c['if_enable'] = @enable
  end
  if @unless_enable
    c['unless_enable'] = @unless_enable
  end
  unless if_jobs.empty?
    c['if_jobs'] = if_jobs
  end
  unless unless_jobs.empty?
    c['unless_jobs'] = unless_jobs
  end
  c
end

#continue_on_failObject



178
179
180
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 178

def continue_on_fail
  @attributes[:continue] = true
end

#if_enable=(val) ⇒ Object Also known as: enable=, if_enabled=



110
111
112
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 110

def if_enable=(val)
  @enable = val
end

#if_job=(jobs) ⇒ Object Also known as: if_jobs=, add_if_jobs, add_if_job



121
122
123
124
125
126
127
128
129
130
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 121

def if_job=(jobs)
  [jobs].flatten.compact.each do |job|
    job = job.to_s.upcase
    if job =~ /!/
      self.unless_job = job
    else
      if_jobs << job unless if_jobs.include?(job)
    end
  end
end

#if_jobsObject



102
103
104
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 102

def if_jobs
  @if_jobs ||= []
end

#jobObject Also known as: jobs



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 89

def job
  if !if_jobs.empty? && !unless_jobs.empty?
    fail "Both if and unless jobs have been defined for test: #{parameter}"
  elsif !if_jobs.empty?
    if_jobs.join(',')
  elsif !unless_jobs.empty?
    unless_jobs.map { |j| "!#{j}" }.join(',')
  else
    ''
  end
end

#run_if_all_failed(parent) ⇒ Object



174
175
176
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 174

def run_if_all_failed(parent)
  @context[:if_all_failed] = parent.id
end

#run_if_all_passed(parent) ⇒ Object



166
167
168
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 166

def run_if_all_passed(parent)
  @context[:if_all_passed] = parent.id
end

#run_if_any_failed(parent) ⇒ Object



170
171
172
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 170

def run_if_any_failed(parent)
  @context[:if_any_failed] = parent.id
end

#run_if_any_passed(parent) ⇒ Object



162
163
164
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 162

def run_if_any_passed(parent)
  @context[:if_any_passed] = parent.id
end

#run_if_failed(id) ⇒ Object



146
147
148
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 146

def run_if_failed(id)
  @context[:if_failed] = id
end

#run_if_passed(id) ⇒ Object



150
151
152
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 150

def run_if_passed(id)
  @context[:if_passed] = id
end

#run_if_ran(id) ⇒ Object



154
155
156
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 154

def run_if_ran(id)
  @context[:if_ran] = id
end

#run_unless_ran(id) ⇒ Object



158
159
160
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 158

def run_unless_ran(id)
  @context[:unless_ran] = id
end

#test?Boolean

Returns:

  • (Boolean)


195
196
197
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 195

def test?
  @type == :test
end

#test_to_yaml(options = {}) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 66

def test_to_yaml(options = {})
  if @test
    if @test.is_a?(String) || @test.is_a?(Symbol)
      {
        'attributes' => {
          'name' => @test.to_s
        }
      }
    else
      @test.to_yaml(options)
    end
  end
end

#to_yaml(options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 21

def to_yaml(options = {})
  options = {
    include_descriptions: true
  }.merge(options)
  y = {
    'type'        => @type,
    'description' => description,
    'instance'    => test_to_yaml(options),
    'flow'        => {
      'attributes' => attributes_to_yaml(options),
      'context'    => context_to_yaml(options)
    }
  }
  y.delete('description') unless options[:include_descriptions]
  y
end

#unique_counterObject



186
187
188
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 186

def unique_counter
  @unique_counter ||= self.class.unique_counter
end

#unless_enable=(val) ⇒ Object Also known as: unless_enabled=



116
117
118
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 116

def unless_enable=(val)
  @unless_enable = val
end

#unless_job=(jobs) ⇒ Object Also known as: unless_jobs=, add_unless_jobs, add_unless_job



135
136
137
138
139
140
141
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 135

def unless_job=(jobs)
  [jobs].flatten.compact.each do |job|
    job = job.to_s.upcase
    job.gsub!('!', '')
    unless_jobs << job unless unless_jobs.include?(job)
  end
end

#unless_jobsObject



106
107
108
# File 'lib/origen_testers/doc/generator/flow_line.rb', line 106

def unless_jobs
  @unless_jobs ||= []
end