Class: OrigenTesters::Charz::Session
- Inherits:
-
Object
- Object
- OrigenTesters::Charz::Session
- Defined in:
- lib/origen_testers/charz/session.rb
Overview
A charz session contains a collection of the final combinations of charz object (routines/profiles) and user options to determine how and what charz tests should be created the session should be checked in your interface to determine the current status and can be queried to make charz generation decisions
Instance Attribute Summary collapse
-
#current_instance(options = {}) ⇒ Profile
Set when looping over instances via #loop_instances.
-
#defaults ⇒ Hash
List of values to instantiate the inherited attributes from Profile with if not altered by the session update.
-
#id ⇒ Symbol
Current session ID.
-
#instances ⇒ Array
List of active instances (which are essentially Profiles).
-
#stored_instance ⇒ Profile
This is to store the instance that the interface is storing.
-
#valid ⇒ Boolean
Whether or not the current session setup is valid, if not then charz wont be created.
Instance Method Summary collapse
- #active? ⇒ Boolean (also: #active)
- #charz_only ⇒ Object
- #charz_only? ⇒ Boolean
-
#initialize(options = {}) ⇒ Session
constructor
A new instance of Session.
- #loop_instances ⇒ Object
- #on_result? ⇒ Boolean
-
#pause ⇒ Object
Pauses the current session's activity while maintaining everthing else about the sessions state.
-
#resume ⇒ Object
Resume activity, if the session is valid.
-
#update(charz_tuples) ⇒ Object
Takes a CharzTuple and queries it to setup an instance's attributes the attributes values can be set from 3 different sources, in order of priority (first is most important): - options - charz object (Profile or Routine) - defaults.
Constructor Details
#initialize(options = {}) ⇒ Session
Returns a new instance of Session.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/origen_testers/charz/session.rb', line 21 def initialize( = {}) @id = :empty_session @instances = [] @current_instance = nil @stored_instance = nil @active = false @valid = false @defaults = { placement: :inline, routines: [], on_result: nil, enables: nil, flags: nil, enables_and: false, and_enables: false, flags_and: false, and_flags: false, name: 'charz', charz_only: false, force_keep_parent: false }.merge(([:defaults] || {})) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/origen_testers/charz/session.rb', line 150 def method_missing(method, *args, &block) deprecated_methods = [ :name, :placement, :on_result, :enables, :flags, :routines, :and_enables, :enables_and, :and_flags, :flags_and, :charz_only, :force_keep_parent ] if deprecated_methods.include?(method.to_sym) || deprecated_methods.include?(method.to_s[0..-2].to_sym) Origen.log.deprecate "charz_session.#{method} has been deprecated. Please query charz_instance.#{method} instead." if current_instance.nil? && !valid Origen.log.error "blocked call of 'charz_session.#{method}'!" Origen.log.warn 'The charz instance attributes are no longer accessible when the session is invalid!' else current_instance.send(method, *args, &block) end else super end end |
Instance Attribute Details
#current_instance(options = {}) ⇒ Profile
Returns Set when looping over instances via #loop_instances. The interface can query the charz_instance for more detailed info.
19 |
# File 'lib/origen_testers/charz/session.rb', line 19 attr_accessor :id, :instances, :current_instance, :valid, :defaults, :stored_instance |
#defaults ⇒ Hash
Returns list of values to instantiate the inherited attributes from Profile with if not altered by the session update.
19 |
# File 'lib/origen_testers/charz/session.rb', line 19 attr_accessor :id, :instances, :current_instance, :valid, :defaults, :stored_instance |
#id ⇒ Symbol
Returns current session ID. Will be a concatenation of the instances' ids.
19 20 21 |
# File 'lib/origen_testers/charz/session.rb', line 19 def id @id end |
#instances ⇒ Array
Returns list of active instances (which are essentially Profiles).
19 |
# File 'lib/origen_testers/charz/session.rb', line 19 attr_accessor :id, :instances, :current_instance, :valid, :defaults, :stored_instance |
#stored_instance ⇒ Profile
Returns This is to store the instance that the interface is storing. Its to support a legacy usecase of querying the session for instance level info during EOF.
19 |
# File 'lib/origen_testers/charz/session.rb', line 19 attr_accessor :id, :instances, :current_instance, :valid, :defaults, :stored_instance |
#valid ⇒ Boolean
Returns whether or not the current session setup is valid, if not then charz wont be created.
19 |
# File 'lib/origen_testers/charz/session.rb', line 19 attr_accessor :id, :instances, :current_instance, :valid, :defaults, :stored_instance |
Instance Method Details
#active? ⇒ Boolean Also known as: active
64 65 66 |
# File 'lib/origen_testers/charz/session.rb', line 64 def active? !!@active end |
#charz_only ⇒ Object
54 55 56 57 |
# File 'lib/origen_testers/charz/session.rb', line 54 def charz_only Origen.log.deprecate '#charz_only has been deprecated in favor of #charz_only? It is no longer an attribute, instead a runtime calculation.' charz_only? end |
#charz_only? ⇒ Boolean
48 49 50 51 52 |
# File 'lib/origen_testers/charz/session.rb', line 48 def charz_only? any_only = instances.any?(&:charz_only) any_force = instances.any?(&:force_keep_parent) !any_force && any_only && !on_result? end |
#loop_instances ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/origen_testers/charz/session.rb', line 87 def loop_instances instances.each do |charz_instance| @current_instance = charz_instance yield @current_instance = nil end end |
#on_result? ⇒ Boolean
44 45 46 |
# File 'lib/origen_testers/charz/session.rb', line 44 def on_result? instances.any? { |charz_instance| !charz_instance.on_result.nil? } end |
#pause ⇒ Object
Pauses the current session's activity while maintaining everthing else about the sessions state
60 61 62 |
# File 'lib/origen_testers/charz/session.rb', line 60 def pause @active = false end |
#resume ⇒ Object
Resume activity, if the session is valid
70 71 72 73 74 |
# File 'lib/origen_testers/charz/session.rb', line 70 def resume if @valid @active = true end end |
#update(charz_tuples) ⇒ Object
Takes a CharzTuple and queries it to setup an instance's attributes the attributes values can be set from 3 different sources, in order of priority (first is most important):
- options
- charz object (Profile or Routine)
- defaults
If the resulting session is invalid, @valid will turn false. Otherwise, the session becomes active
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/origen_testers/charz/session.rb', line 102 def update(charz_tuples) @instances = [] @valid = false if charz_tuples.nil? || charz_tuples.empty? @active = false @valid = false @current_instance = nil return @valid end @defined_routines = charz_tuples.map(&:defined_routines).flatten.uniq.compact charz_tuples.each do |charz_tuple| = assign_by_priority(charz_tuple) @instances << Profile.new(charz_tuple.obj.id, .merge(defined_routines: @defined_routines)) end @id = instances.map(&:id).join('_').to_sym @active = true @valid = true end |