Module: Origen::GlobalMethods
- Defined in:
- lib/origen/global_methods.rb
Constant Summary collapse
- Pattern =
Origen.pattern
- Flow =
Origen.flow
- Resources =
Origen.resources
- User =
Origen::Users::User
Instance Method Summary collapse
- #annotate(msg, options = {}) ⇒ Object
- #c1(msg, options = {}) ⇒ Object (also: #cc)
- #c2(msg, options = {}) ⇒ Object
- #debug(*lines) ⇒ Object
-
#encoding_search(symbol, options = {}) ⇒ Object
Returns the encoded symbol as a String if one match is found.
-
#encodings(format = nil) ⇒ Object
Returns Rgen supported encoding formats.
-
#get_excel_column(n) ⇒ Object
Returns an Excel column based on an Integer argument.
-
#get_full_class(obj) ⇒ Object
Returns the full class hierarchy of an object.
- #global_binding ⇒ Object
-
#options ⇒ Object
private
The options passed to an ERB template.
- #pp(*args, &block) ⇒ Object (also: #pattern_section, #ps)
-
#render(*args, &block) ⇒ Object
Render an ERB template.
-
#require_gem(name, options = {}) ⇒ Object
If a new gem (i.e. not part of the existing Ruby installation) is required by Origen or an application then it should be required via this method.
- #snip(*args, &block) ⇒ Object
- #ss(*args, &block) ⇒ Object (also: #step_comment)
Instance Method Details
#annotate(msg, options = {}) ⇒ Object
72 73 74 |
# File 'lib/origen/global_methods.rb', line 72 def annotate(msg, = {}) Origen.app.tester.annotate(msg, ) end |
#c1(msg, options = {}) ⇒ Object Also known as: cc
76 77 78 |
# File 'lib/origen/global_methods.rb', line 76 def c1(msg, = {}) Origen.app.tester.c1(msg, ) end |
#c2(msg, options = {}) ⇒ Object
81 82 83 |
# File 'lib/origen/global_methods.rb', line 81 def c2(msg, = {}) Origen.app.tester.c2(msg, ) end |
#debug(*lines) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/origen/global_methods.rb', line 120 def debug(*lines) Origen.deprecate 'debug method is deprecated, use Origen.log.debug instead' if Origen.debug? Origen.log.info '' c = caller[0] c =~ /(.*):(\d+):.*/ $_last_log_time ||= Time.now delta = Time.now - $_last_log_time $_last_log_time = Time.now begin Origen.log.info "*** Debug *** %.6f #{Regexp.last_match[1]}:#{Regexp.last_match[2]}" % delta rescue # For this to fail it means the deprecated method was called by IRB or similar # and in that case there is no point advising who called anyway end = lines.last.is_a?(Hash) ? lines.pop : {} lines.flatten.each do |line| line.split(/\n/).each do |line| Origen.log.info line, end end end end |
#encoding_search(symbol, options = {}) ⇒ Object
Returns the encoded symbol as a String if one match is found. Returns a hash for multiple results and nil for no match
190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/origen/global_methods.rb', line 190 def encoding_search(symbol, = {}) = { format: :utf8 }.update() fail "The encoding format '#{options[:format]}' is not supported, please choose from #{encodings}" unless encodings.include? [:format] results = Origen::ENCODINGS[[:format]].filter(symbol) if results.size == 1 results.values.first elsif results.size > 1 results else return nil end end |
#encodings(format = nil) ⇒ Object
Returns Rgen supported encoding formats
180 181 182 183 184 185 186 |
# File 'lib/origen/global_methods.rb', line 180 def encodings(format = nil) if format.nil? Origen::ENCODINGS.keys else Origen::ENCODINGS[format].keys end end |
#get_excel_column(n) ⇒ Object
Returns an Excel column based on an Integer argument
150 151 152 153 154 155 156 157 158 |
# File 'lib/origen/global_methods.rb', line 150 def get_excel_column(n) excel_columns = {} @column = 'A' (1..75).to_a.each do |i| excel_columns[i] = @column @column = @column.succ end excel_columns[n] end |
#get_full_class(obj) ⇒ Object
Returns the full class hierarchy of an object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/origen/global_methods.rb', line 161 def get_full_class(obj) klass_str = '' until obj.nil? if obj == Origen.top_level klass_str.prepend obj.class.to_s else # If the class method produces "SubBlock" then use the object name instead if obj.class.to_s.split('::').last == 'SubBlock' klass_str.prepend "::#{obj.name.upcase}" else klass_str.prepend "::#{obj.class.to_s.split('::').last}" end end obj = obj.parent end klass_str end |
#global_binding ⇒ Object
116 117 118 |
# File 'lib/origen/global_methods.rb', line 116 def global_binding binding end |
#options ⇒ Object
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.
The options passed to an ERB template. Having it global like this is ugly, but it does allow a hash of options to always be available in templates even if the template is being rendered using a custom binding.
111 112 113 114 |
# File 'lib/origen/global_methods.rb', line 111 def $_ || Origen.generator.compiler. end |
#pp(*args, &block) ⇒ Object Also known as: pattern_section, ps
90 91 92 |
# File 'lib/origen/global_methods.rb', line 90 def pp(*args, &block) Origen.app.tester.pattern_section(*args, &block) end |
#render(*args, &block) ⇒ Object
Render an ERB template
101 102 103 |
# File 'lib/origen/global_methods.rb', line 101 def render(*args, &block) Origen.generator.compiler.render(*args, &block) end |
#require_gem(name, options = {}) ⇒ Object
If a new gem (i.e. not part of the existing Ruby installation) is required by Origen or an application then it should be required via this method. On Windows this can be installed automatically and this method will take care of doing that.
However due to the restricted user permissions available on Linux this cannot be done automatically and you must ensure that you arrange to have the required gem installed on Linux - contact Stephen McGinty to get this done.
A given user will then have to update their local toolset to pick this up and this method will give them the necessary instructions.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/origen/global_methods.rb', line 20 def require_gem(name, = {}) Origen.deprecate "require_gem will be removed in Origen V3, Bundler should be used to manage gem dependencies\n" = { name: name }.merge() name = name.to_s [:name] = [:name].to_s if [:version] && [:version] =~ /^v(.*)/ [:version] = Regexp.last_match[1] end # This gem was not included in the initial Origen v2.x.x gemset, so need to handle instalations # without it begin if [:version] gem [:name], [:version] end require name rescue LoadError if Origen.running_on_windows? puts "Installing #{options[:name]}" command = "gem install #{options[:name]} --no-rdoc --no-ri" command += " --version #{options[:version]}" if [:version] if !system(command) puts 'It looks like a problem occurred, ensure you have installed Ruby exactly per the Origen guide' else puts 'A missing gem has just been installed to your system, please re-run the previous command' end else puts "Installing #{options[:name]}" command = "gem install --user-install #{options[:name]} --no-rdoc --no-ri" command += " --version #{options[:version]}" if [:version] if !system(command) puts 'It looks like there was a problem installing that gem, run the following commands to ensure you have an up to date' puts 'environment, then try again:' puts '' puts " cd #{Origen.top}" puts ' source source_setup update' puts " cd #{FileUtils.pwd}" else puts 'A missing gem has just been installed to your system, please re-run the previous command' end # puts "The current application has required a gem called #{options[:name]}, however that is not available in your current toolset." # puts 'This may be solved by following the instructions below, otherwise contact the application owner.' # puts '' # puts_require_latest_ruby end exit 1 end end |
#snip(*args, &block) ⇒ Object
96 97 98 |
# File 'lib/origen/global_methods.rb', line 96 def snip(*args, &block) Origen.app.tester.snip(*args, &block) end |
#ss(*args, &block) ⇒ Object Also known as: step_comment
85 86 87 |
# File 'lib/origen/global_methods.rb', line 85 def ss(*args, &block) Origen.app.tester.ss(*args, &block) end |