Class: Origen::Tester::Doc::Model
- Inherits:
-
Object
- Object
- Origen::Tester::Doc::Model
- Defined in:
- lib/origen/tester/doc/model.rb
Overview
Class representing a program model, provides an API to iterate on the flow based on context (e.g. which job).
Instance Attribute Summary (collapse)
-
- (Object) flows
Returns the value of attribute flows.
-
- (Object) target
Returns the value of attribute target.
Instance Method Summary (collapse)
-
- (Object) add_flow(name, content)
private
YAML likes strings for keys, we don't, so make sure all keys are symbols when receiving a new flow.
- - (Object) build_instance(test) private
-
- (Object) dependents_of(id, flows, options = {})
Searches the given flows to find dependents of the given test id.
-
- (Object) each_in_flow(flows = nil, options = {})
Iterates through each line in the given flow returning a hash for each line with the following structure:.
-
- (Object) find_by_id(id, flows, options = {})
Search for the given test id in the given flows.
- - (Object) format_test(test, _options = {}) private
-
- (Model) initialize
constructor
A new instance of Model.
- - (Object) symbolize_keys(hash) private
-
- (Boolean) valid_in_context?(test, context = nil)
Returns true if the given tests id valid under the given context (currently only tests for job matching).
Constructor Details
- (Model) initialize
Returns a new instance of Model
9 10 11 |
# File 'lib/origen/tester/doc/model.rb', line 9 def initialize @flows = {} end |
Instance Attribute Details
- (Object) flows
Returns the value of attribute flows
7 8 9 |
# File 'lib/origen/tester/doc/model.rb', line 7 def flows @flows end |
- (Object) target
Returns the value of attribute target
7 8 9 |
# File 'lib/origen/tester/doc/model.rb', line 7 def target @target end |
Instance Method Details
- (Object) add_flow(name, content)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
YAML likes strings for keys, we don't, so make sure all keys are symbols when receiving a new flow
134 135 136 137 138 139 140 141 142 |
# File 'lib/origen/tester/doc/model.rb', line 134 def add_flow(name, content) @flows[name.to_sym] = content.map do |h| h = symbolize_keys h if h[:instance] && h[:instance][:group] h[:instance][:group] = h[:instance][:group].map { |j| symbolize_keys j } end h end end |
- (Object) build_instance(test)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/origen/tester/doc/model.rb', line 119 def build_instance(test) if test[:instance] if test[:instance][:group] test[:instance][:group].map { |g| g[:attributes] || {} } else [test[:instance][:attributes] || {}] end else [{}] end end |
- (Object) dependents_of(id, flows, options = {})
Searches the given flows to find dependents of the given test id. The dependents are returned in arrays grouped by context:
{
:if_failed => [],
:if_passed => [],
:if_ran => [],
:unless_ran => [],
}
Each test will have the same format as described in #each_in_flow.
If no dependents are found an empty hash is returned.
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/origen/tester/doc/model.rb', line 70 def dependents_of(id, flows, = {}) d = {} each_in_flow(flows, ) do |test| test[:context].each do |key, val| if val == id d[key] ||= [] d[key] << test end end end d end |
- (Object) each_in_flow(flows = nil, options = {})
Iterates through each line in the given flow returning a hash for each line with the following structure:
{
:type => Symbol, # Type of flow line
:description => [], # Array of strings
:instance => [{}], # Array of attributes hashes (each one represents an individual test instance)
:flow => {}, # Hash of attributes
:context => {}, # Hash of attributes
}
In all cases if an item is missing then it will be replaced by an empty array or hash as appropriate so that the caller does not need to worry about this.
Supply the name of the flow(s) to consider, if the flows argument is left out then all lines in all flows will be returned.
A context option can be supplied to only return the tests for which the given context is true.
puts "The following tests run at FR:"
program_model.each_in_flow(:ft_flow, :context => { :job => "FR" }) do |line|
puts " #{line[:flow][:name]}"
end
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/origen/tester/doc/model.rb', line 38 def each_in_flow(flows = nil, = {}) if flows.is_a?(Hash) = flows flows = nil end unless flows flows = self.flows.keys end [flows].flatten.each do |flow| @flows[flow.to_sym].each do |test| test = format_test(test) if valid_in_context?(test, [:context]) yield test end end end nil end |
- (Object) find_by_id(id, flows, options = {})
Search for the given test id in the given flows. Returns nil if not found.
85 86 87 88 89 |
# File 'lib/origen/tester/doc/model.rb', line 85 def find_by_id(id, flows, = {}) each_in_flow(flows, ) do |test| return test if test[:flow][:id] == id end end |
- (Object) format_test(test, _options = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
108 109 110 111 112 113 114 115 116 |
# File 'lib/origen/tester/doc/model.rb', line 108 def format_test(test, = {}) { type: test[:type] ? test[:type].to_sym : :unknown, description: test[:description] || [], instance: build_instance(test), flow: test[:flow] ? test[:flow][:attributes] || {} : {}, context: test[:flow] ? test[:flow][:context] || {} : {} } end |
- (Object) symbolize_keys(hash)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/origen/tester/doc/model.rb', line 145 def symbolize_keys(hash) hash.reduce({}) do |result, (key, value)| new_key = case key when String then key.to_sym else key end new_value = case value when Hash then symbolize_keys(value) else value end result[new_key] = new_value result end end |
- (Boolean) valid_in_context?(test, context = nil)
Returns true if the given tests id valid under the given context (currently only tests for job matching)
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/origen/tester/doc/model.rb', line 93 def valid_in_context?(test, context = nil) if context && context[:job] && test[:context] if test[:context][:if_jobs] test[:context][:if_jobs].include?(context[:job]) elsif test[:context][:unless_jobs] !test[:context][:unless_jobs].include?(context[:job]) else true end else true end end |