repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
list | docstring
stringlengths 8
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 94
266
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
curationexperts/riiif | app/services/riiif/resize.rb | Riiif.Resize.reduce? | def reduce?
case size
when IIIF::Image::Size::Full, IIIF::Image::Size::Max
false
when IIIF::Image::Size::Absolute
aspect_ratio = width.to_f / height
in_delta?(image_info.aspect, aspect_ratio, 0.001)
else
true
end
end | ruby | def reduce?
case size
when IIIF::Image::Size::Full, IIIF::Image::Size::Max
false
when IIIF::Image::Size::Absolute
aspect_ratio = width.to_f / height
in_delta?(image_info.aspect, aspect_ratio, 0.001)
else
true
end
end | [
"def",
"reduce?",
"case",
"size",
"when",
"IIIF",
"::",
"Image",
"::",
"Size",
"::",
"Full",
",",
"IIIF",
"::",
"Image",
"::",
"Size",
"::",
"Max",
"false",
"when",
"IIIF",
"::",
"Image",
"::",
"Size",
"::",
"Absolute",
"aspect_ratio",
"=",
"width",
".",
"to_f",
"/",
"height",
"in_delta?",
"(",
"image_info",
".",
"aspect",
",",
"aspect_ratio",
",",
"0.001",
")",
"else",
"true",
"end",
"end"
]
| Should we reduce this image with KDU? | [
"Should",
"we",
"reduce",
"this",
"image",
"with",
"KDU?"
]
| e55e2632d21b19080c23054cc6d94e74efba568f | https://github.com/curationexperts/riiif/blob/e55e2632d21b19080c23054cc6d94e74efba568f/app/services/riiif/resize.rb#L62-L72 | train |
curationexperts/riiif | app/transformers/riiif/kakadu_transformer.rb | Riiif.KakaduTransformer.post_process | def post_process(intermediate_file, reduction_factor)
# Calculate a new set of transforms with respect to reduction_factor
transformation = if reduction_factor
reduce(without_crop, reduction_factor)
else
without_crop
end
Riiif::File.new(intermediate_file).extract(transformation, image_info)
end | ruby | def post_process(intermediate_file, reduction_factor)
# Calculate a new set of transforms with respect to reduction_factor
transformation = if reduction_factor
reduce(without_crop, reduction_factor)
else
without_crop
end
Riiif::File.new(intermediate_file).extract(transformation, image_info)
end | [
"def",
"post_process",
"(",
"intermediate_file",
",",
"reduction_factor",
")",
"transformation",
"=",
"if",
"reduction_factor",
"reduce",
"(",
"without_crop",
",",
"reduction_factor",
")",
"else",
"without_crop",
"end",
"Riiif",
"::",
"File",
".",
"new",
"(",
"intermediate_file",
")",
".",
"extract",
"(",
"transformation",
",",
"image_info",
")",
"end"
]
| The data we get back from kdu_expand is a bmp and we need to change it
to the requested format by calling Imagemagick. | [
"The",
"data",
"we",
"get",
"back",
"from",
"kdu_expand",
"is",
"a",
"bmp",
"and",
"we",
"need",
"to",
"change",
"it",
"to",
"the",
"requested",
"format",
"by",
"calling",
"Imagemagick",
"."
]
| e55e2632d21b19080c23054cc6d94e74efba568f | https://github.com/curationexperts/riiif/blob/e55e2632d21b19080c23054cc6d94e74efba568f/app/transformers/riiif/kakadu_transformer.rb#L23-L31 | train |
curationexperts/riiif | app/transformers/riiif/kakadu_transformer.rb | Riiif.KakaduTransformer.without_crop | def without_crop
IIIF::Image::Transformation.new(region: IIIF::Image::Region::Full.new,
size: transformation.size.dup,
quality: transformation.quality,
rotation: transformation.rotation,
format: transformation.format)
end | ruby | def without_crop
IIIF::Image::Transformation.new(region: IIIF::Image::Region::Full.new,
size: transformation.size.dup,
quality: transformation.quality,
rotation: transformation.rotation,
format: transformation.format)
end | [
"def",
"without_crop",
"IIIF",
"::",
"Image",
"::",
"Transformation",
".",
"new",
"(",
"region",
":",
"IIIF",
"::",
"Image",
"::",
"Region",
"::",
"Full",
".",
"new",
",",
"size",
":",
"transformation",
".",
"size",
".",
"dup",
",",
"quality",
":",
"transformation",
".",
"quality",
",",
"rotation",
":",
"transformation",
".",
"rotation",
",",
"format",
":",
"transformation",
".",
"format",
")",
"end"
]
| Create a clone of the Transformation, without the crop
@return [IIIF::Image::Transformation] a new transformation | [
"Create",
"a",
"clone",
"of",
"the",
"Transformation",
"without",
"the",
"crop"
]
| e55e2632d21b19080c23054cc6d94e74efba568f | https://github.com/curationexperts/riiif/blob/e55e2632d21b19080c23054cc6d94e74efba568f/app/transformers/riiif/kakadu_transformer.rb#L37-L43 | train |
curationexperts/riiif | app/transformers/riiif/kakadu_transformer.rb | Riiif.KakaduTransformer.reduce | def reduce(transformation, factor)
resize = Resize.new(transformation.size, image_info)
IIIF::Image::Transformation.new(region: transformation.region.dup,
size: resize.reduce(factor),
quality: transformation.quality,
rotation: transformation.rotation,
format: transformation.format)
end | ruby | def reduce(transformation, factor)
resize = Resize.new(transformation.size, image_info)
IIIF::Image::Transformation.new(region: transformation.region.dup,
size: resize.reduce(factor),
quality: transformation.quality,
rotation: transformation.rotation,
format: transformation.format)
end | [
"def",
"reduce",
"(",
"transformation",
",",
"factor",
")",
"resize",
"=",
"Resize",
".",
"new",
"(",
"transformation",
".",
"size",
",",
"image_info",
")",
"IIIF",
"::",
"Image",
"::",
"Transformation",
".",
"new",
"(",
"region",
":",
"transformation",
".",
"region",
".",
"dup",
",",
"size",
":",
"resize",
".",
"reduce",
"(",
"factor",
")",
",",
"quality",
":",
"transformation",
".",
"quality",
",",
"rotation",
":",
"transformation",
".",
"rotation",
",",
"format",
":",
"transformation",
".",
"format",
")",
"end"
]
| Create a clone of this Transformation, scaled by the factor
@param [IIIF::Image::Transformation] transformation the transformation to clone
@param [Integer] factor the scale for the new transformation
@return [Transformation] a new transformation, scaled by factor | [
"Create",
"a",
"clone",
"of",
"this",
"Transformation",
"scaled",
"by",
"the",
"factor"
]
| e55e2632d21b19080c23054cc6d94e74efba568f | https://github.com/curationexperts/riiif/blob/e55e2632d21b19080c23054cc6d94e74efba568f/app/transformers/riiif/kakadu_transformer.rb#L49-L56 | train |
instana/ruby-sensor | lib/instana/agent.rb | Instana.Agent.setup | def setup
# The announce timer
# We attempt to announce this ruby sensor to the host agent.
# In case of failure, we try again in 30 seconds.
@announce_timer = @timers.every(30) do
if @state == :unannounced
if host_agent_available? && announce_sensor
transition_to(:announced)
::Instana.logger.info "Host agent available. We're in business. (#{@state} pid:#{Process.pid} #{@process[:name]})"
end
end
end
# The collect timer
# If we are in announced state, send metric data (only delta reporting)
# every ::Instana.config[:collector][:interval] seconds.
@collect_timer = @timers.every(::Instana.config[:collector][:interval]) do
# Make sure that this block doesn't get called more often than the interval. This can
# happen on high CPU load and a back up of timer runs. If we are called before `interval`
# then we just skip.
unless (Time.now - @last_collect_run) < ::Instana.config[:collector][:interval]
@last_collect_run = Time.now
if @state == :announced
if !::Instana.collector.collect_and_report
# If report has been failing for more than 1 minute,
# fall back to unannounced state
if (Time.now - @entity_last_seen) > 60
::Instana.logger.warn "Host agent offline for >1 min. Going to sit in a corner..."
transition_to(:unannounced)
end
end
::Instana.processor.send
end
end
end
end | ruby | def setup
# The announce timer
# We attempt to announce this ruby sensor to the host agent.
# In case of failure, we try again in 30 seconds.
@announce_timer = @timers.every(30) do
if @state == :unannounced
if host_agent_available? && announce_sensor
transition_to(:announced)
::Instana.logger.info "Host agent available. We're in business. (#{@state} pid:#{Process.pid} #{@process[:name]})"
end
end
end
# The collect timer
# If we are in announced state, send metric data (only delta reporting)
# every ::Instana.config[:collector][:interval] seconds.
@collect_timer = @timers.every(::Instana.config[:collector][:interval]) do
# Make sure that this block doesn't get called more often than the interval. This can
# happen on high CPU load and a back up of timer runs. If we are called before `interval`
# then we just skip.
unless (Time.now - @last_collect_run) < ::Instana.config[:collector][:interval]
@last_collect_run = Time.now
if @state == :announced
if !::Instana.collector.collect_and_report
# If report has been failing for more than 1 minute,
# fall back to unannounced state
if (Time.now - @entity_last_seen) > 60
::Instana.logger.warn "Host agent offline for >1 min. Going to sit in a corner..."
transition_to(:unannounced)
end
end
::Instana.processor.send
end
end
end
end | [
"def",
"setup",
"@announce_timer",
"=",
"@timers",
".",
"every",
"(",
"30",
")",
"do",
"if",
"@state",
"==",
":unannounced",
"if",
"host_agent_available?",
"&&",
"announce_sensor",
"transition_to",
"(",
":announced",
")",
"::",
"Instana",
".",
"logger",
".",
"info",
"\"Host agent available. We're in business. (#{@state} pid:#{Process.pid} #{@process[:name]})\"",
"end",
"end",
"end",
"@collect_timer",
"=",
"@timers",
".",
"every",
"(",
"::",
"Instana",
".",
"config",
"[",
":collector",
"]",
"[",
":interval",
"]",
")",
"do",
"unless",
"(",
"Time",
".",
"now",
"-",
"@last_collect_run",
")",
"<",
"::",
"Instana",
".",
"config",
"[",
":collector",
"]",
"[",
":interval",
"]",
"@last_collect_run",
"=",
"Time",
".",
"now",
"if",
"@state",
"==",
":announced",
"if",
"!",
"::",
"Instana",
".",
"collector",
".",
"collect_and_report",
"if",
"(",
"Time",
".",
"now",
"-",
"@entity_last_seen",
")",
">",
"60",
"::",
"Instana",
".",
"logger",
".",
"warn",
"\"Host agent offline for >1 min. Going to sit in a corner...\"",
"transition_to",
"(",
":unannounced",
")",
"end",
"end",
"::",
"Instana",
".",
"processor",
".",
"send",
"end",
"end",
"end",
"end"
]
| Sets up periodic timers and starts the agent in a background thread. | [
"Sets",
"up",
"periodic",
"timers",
"and",
"starts",
"the",
"agent",
"in",
"a",
"background",
"thread",
"."
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/agent.rb#L111-L146 | train |
instana/ruby-sensor | lib/instana/agent.rb | Instana.Agent.start | def start
if !host_agent_available?
if !ENV.key?("INSTANA_QUIET")
::Instana.logger.warn "Host agent not available. Will retry periodically. (Set env INSTANA_QUIET=1 to shut these messages off)"
end
end
loop do
if @state == :unannounced
@collect_timer.pause
@announce_timer.resume
else
@announce_timer.pause
@collect_timer.resume
end
@timers.wait
end
rescue Exception => e
::Instana.logger.warn "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
::Instana.logger.debug e.backtrace.join("\r\n")
ensure
if @state == :announced
# Pause the timers so they don't fire while we are
# reporting traces
@collect_timer.pause
@announce_timer.pause
::Instana.logger.debug "#{Thread.current}: Agent exiting. Reporting final #{::Instana.processor.queue_count} trace(s)."
::Instana.processor.send
end
end | ruby | def start
if !host_agent_available?
if !ENV.key?("INSTANA_QUIET")
::Instana.logger.warn "Host agent not available. Will retry periodically. (Set env INSTANA_QUIET=1 to shut these messages off)"
end
end
loop do
if @state == :unannounced
@collect_timer.pause
@announce_timer.resume
else
@announce_timer.pause
@collect_timer.resume
end
@timers.wait
end
rescue Exception => e
::Instana.logger.warn "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
::Instana.logger.debug e.backtrace.join("\r\n")
ensure
if @state == :announced
# Pause the timers so they don't fire while we are
# reporting traces
@collect_timer.pause
@announce_timer.pause
::Instana.logger.debug "#{Thread.current}: Agent exiting. Reporting final #{::Instana.processor.queue_count} trace(s)."
::Instana.processor.send
end
end | [
"def",
"start",
"if",
"!",
"host_agent_available?",
"if",
"!",
"ENV",
".",
"key?",
"(",
"\"INSTANA_QUIET\"",
")",
"::",
"Instana",
".",
"logger",
".",
"warn",
"\"Host agent not available. Will retry periodically. (Set env INSTANA_QUIET=1 to shut these messages off)\"",
"end",
"end",
"loop",
"do",
"if",
"@state",
"==",
":unannounced",
"@collect_timer",
".",
"pause",
"@announce_timer",
".",
"resume",
"else",
"@announce_timer",
".",
"pause",
"@collect_timer",
".",
"resume",
"end",
"@timers",
".",
"wait",
"end",
"rescue",
"Exception",
"=>",
"e",
"::",
"Instana",
".",
"logger",
".",
"warn",
"\"#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}\"",
"::",
"Instana",
".",
"logger",
".",
"debug",
"e",
".",
"backtrace",
".",
"join",
"(",
"\"\\r\\n\"",
")",
"ensure",
"if",
"@state",
"==",
":announced",
"@collect_timer",
".",
"pause",
"@announce_timer",
".",
"pause",
"::",
"Instana",
".",
"logger",
".",
"debug",
"\"#{Thread.current}: Agent exiting. Reporting final #{::Instana.processor.queue_count} trace(s).\"",
"::",
"Instana",
".",
"processor",
".",
"send",
"end",
"end"
]
| Starts the timer loop for the timers that were initialized
in the setup method. This is blocking and should only be
called from an already initialized background thread. | [
"Starts",
"the",
"timer",
"loop",
"for",
"the",
"timers",
"that",
"were",
"initialized",
"in",
"the",
"setup",
"method",
".",
"This",
"is",
"blocking",
"and",
"should",
"only",
"be",
"called",
"from",
"an",
"already",
"initialized",
"background",
"thread",
"."
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/agent.rb#L152-L182 | train |
instana/ruby-sensor | lib/instana/agent.rb | Instana.Agent.announce_sensor | def announce_sensor
unless @discovered
::Instana.logger.debug("#{__method__} called but discovery hasn't run yet!")
return false
end
# Always re-collect process info before announce in case the process name has been
# re-written (looking at you puma!)
@process = ::Instana::Util.collect_process_info
announce_payload = {}
announce_payload[:pid] = pid_namespace? ? get_real_pid : Process.pid
announce_payload[:name] = @process[:name]
announce_payload[:args] = @process[:arguments]
if @is_linux && !::Instana.test?
# We create an open socket to the host agent in case we are running in a container
# and the real pid needs to be detected.
socket = TCPSocket.new @discovered[:agent_host], @discovered[:agent_port]
announce_payload[:fd] = socket.fileno
announce_payload[:inode] = File.readlink("/proc/#{Process.pid}/fd/#{socket.fileno}")
end
uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{DISCOVERY_PATH}")
req = Net::HTTP::Put.new(uri)
req.body = Oj.dump(announce_payload, OJ_OPTIONS)
::Instana.logger.debug "Announce: http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{DISCOVERY_PATH} - payload: #{req.body}"
response = make_host_agent_request(req)
if response && (response.code.to_i == 200)
data = Oj.load(response.body, OJ_OPTIONS)
@process[:report_pid] = data['pid']
@agent_uuid = data['agentUuid']
if data.key?('extraHeaders')
@extra_headers = data['extraHeaders']
end
true
else
false
end
rescue => e
Instana.logger.info "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
Instana.logger.debug e.backtrace.join("\r\n")
return false
ensure
socket.close if socket
end | ruby | def announce_sensor
unless @discovered
::Instana.logger.debug("#{__method__} called but discovery hasn't run yet!")
return false
end
# Always re-collect process info before announce in case the process name has been
# re-written (looking at you puma!)
@process = ::Instana::Util.collect_process_info
announce_payload = {}
announce_payload[:pid] = pid_namespace? ? get_real_pid : Process.pid
announce_payload[:name] = @process[:name]
announce_payload[:args] = @process[:arguments]
if @is_linux && !::Instana.test?
# We create an open socket to the host agent in case we are running in a container
# and the real pid needs to be detected.
socket = TCPSocket.new @discovered[:agent_host], @discovered[:agent_port]
announce_payload[:fd] = socket.fileno
announce_payload[:inode] = File.readlink("/proc/#{Process.pid}/fd/#{socket.fileno}")
end
uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{DISCOVERY_PATH}")
req = Net::HTTP::Put.new(uri)
req.body = Oj.dump(announce_payload, OJ_OPTIONS)
::Instana.logger.debug "Announce: http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{DISCOVERY_PATH} - payload: #{req.body}"
response = make_host_agent_request(req)
if response && (response.code.to_i == 200)
data = Oj.load(response.body, OJ_OPTIONS)
@process[:report_pid] = data['pid']
@agent_uuid = data['agentUuid']
if data.key?('extraHeaders')
@extra_headers = data['extraHeaders']
end
true
else
false
end
rescue => e
Instana.logger.info "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
Instana.logger.debug e.backtrace.join("\r\n")
return false
ensure
socket.close if socket
end | [
"def",
"announce_sensor",
"unless",
"@discovered",
"::",
"Instana",
".",
"logger",
".",
"debug",
"(",
"\"#{__method__} called but discovery hasn't run yet!\"",
")",
"return",
"false",
"end",
"@process",
"=",
"::",
"Instana",
"::",
"Util",
".",
"collect_process_info",
"announce_payload",
"=",
"{",
"}",
"announce_payload",
"[",
":pid",
"]",
"=",
"pid_namespace?",
"?",
"get_real_pid",
":",
"Process",
".",
"pid",
"announce_payload",
"[",
":name",
"]",
"=",
"@process",
"[",
":name",
"]",
"announce_payload",
"[",
":args",
"]",
"=",
"@process",
"[",
":arguments",
"]",
"if",
"@is_linux",
"&&",
"!",
"::",
"Instana",
".",
"test?",
"socket",
"=",
"TCPSocket",
".",
"new",
"@discovered",
"[",
":agent_host",
"]",
",",
"@discovered",
"[",
":agent_port",
"]",
"announce_payload",
"[",
":fd",
"]",
"=",
"socket",
".",
"fileno",
"announce_payload",
"[",
":inode",
"]",
"=",
"File",
".",
"readlink",
"(",
"\"/proc/#{Process.pid}/fd/#{socket.fileno}\"",
")",
"end",
"uri",
"=",
"URI",
".",
"parse",
"(",
"\"http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{DISCOVERY_PATH}\"",
")",
"req",
"=",
"Net",
"::",
"HTTP",
"::",
"Put",
".",
"new",
"(",
"uri",
")",
"req",
".",
"body",
"=",
"Oj",
".",
"dump",
"(",
"announce_payload",
",",
"OJ_OPTIONS",
")",
"::",
"Instana",
".",
"logger",
".",
"debug",
"\"Announce: http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{DISCOVERY_PATH} - payload: #{req.body}\"",
"response",
"=",
"make_host_agent_request",
"(",
"req",
")",
"if",
"response",
"&&",
"(",
"response",
".",
"code",
".",
"to_i",
"==",
"200",
")",
"data",
"=",
"Oj",
".",
"load",
"(",
"response",
".",
"body",
",",
"OJ_OPTIONS",
")",
"@process",
"[",
":report_pid",
"]",
"=",
"data",
"[",
"'pid'",
"]",
"@agent_uuid",
"=",
"data",
"[",
"'agentUuid'",
"]",
"if",
"data",
".",
"key?",
"(",
"'extraHeaders'",
")",
"@extra_headers",
"=",
"data",
"[",
"'extraHeaders'",
"]",
"end",
"true",
"else",
"false",
"end",
"rescue",
"=>",
"e",
"Instana",
".",
"logger",
".",
"info",
"\"#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}\"",
"Instana",
".",
"logger",
".",
"debug",
"e",
".",
"backtrace",
".",
"join",
"(",
"\"\\r\\n\"",
")",
"return",
"false",
"ensure",
"socket",
".",
"close",
"if",
"socket",
"end"
]
| Collect process ID, name and arguments to notify
the host agent. | [
"Collect",
"process",
"ID",
"name",
"and",
"arguments",
"to",
"notify",
"the",
"host",
"agent",
"."
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/agent.rb#L187-L236 | train |
instana/ruby-sensor | lib/instana/agent.rb | Instana.Agent.report_metrics | def report_metrics(payload)
unless @discovered
::Instana.logger.debug("#{__method__} called but discovery hasn't run yet!")
return false
end
path = "com.instana.plugin.ruby.#{@process[:report_pid]}"
uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{path}")
req = Net::HTTP::Post.new(uri)
req.body = Oj.dump(payload, OJ_OPTIONS)
response = make_host_agent_request(req)
if response
if response.body && response.body.length > 2
# The host agent returned something indicating that is has a request for us that we
# need to process.
handle_agent_tasks(response.body)
end
if response.code.to_i == 200
@entity_last_seen = Time.now
return true
end
end
false
rescue => e
Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
Instana.logger.debug e.backtrace.join("\r\n")
end | ruby | def report_metrics(payload)
unless @discovered
::Instana.logger.debug("#{__method__} called but discovery hasn't run yet!")
return false
end
path = "com.instana.plugin.ruby.#{@process[:report_pid]}"
uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{path}")
req = Net::HTTP::Post.new(uri)
req.body = Oj.dump(payload, OJ_OPTIONS)
response = make_host_agent_request(req)
if response
if response.body && response.body.length > 2
# The host agent returned something indicating that is has a request for us that we
# need to process.
handle_agent_tasks(response.body)
end
if response.code.to_i == 200
@entity_last_seen = Time.now
return true
end
end
false
rescue => e
Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
Instana.logger.debug e.backtrace.join("\r\n")
end | [
"def",
"report_metrics",
"(",
"payload",
")",
"unless",
"@discovered",
"::",
"Instana",
".",
"logger",
".",
"debug",
"(",
"\"#{__method__} called but discovery hasn't run yet!\"",
")",
"return",
"false",
"end",
"path",
"=",
"\"com.instana.plugin.ruby.#{@process[:report_pid]}\"",
"uri",
"=",
"URI",
".",
"parse",
"(",
"\"http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{path}\"",
")",
"req",
"=",
"Net",
"::",
"HTTP",
"::",
"Post",
".",
"new",
"(",
"uri",
")",
"req",
".",
"body",
"=",
"Oj",
".",
"dump",
"(",
"payload",
",",
"OJ_OPTIONS",
")",
"response",
"=",
"make_host_agent_request",
"(",
"req",
")",
"if",
"response",
"if",
"response",
".",
"body",
"&&",
"response",
".",
"body",
".",
"length",
">",
"2",
"handle_agent_tasks",
"(",
"response",
".",
"body",
")",
"end",
"if",
"response",
".",
"code",
".",
"to_i",
"==",
"200",
"@entity_last_seen",
"=",
"Time",
".",
"now",
"return",
"true",
"end",
"end",
"false",
"rescue",
"=>",
"e",
"Instana",
".",
"logger",
".",
"debug",
"\"#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}\"",
"Instana",
".",
"logger",
".",
"debug",
"e",
".",
"backtrace",
".",
"join",
"(",
"\"\\r\\n\"",
")",
"end"
]
| Method to report metrics data to the host agent.
@param paylod [Hash] The collection of metrics to report.
@return [Boolean] true on success, false otherwise | [
"Method",
"to",
"report",
"metrics",
"data",
"to",
"the",
"host",
"agent",
"."
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/agent.rb#L244-L274 | train |
instana/ruby-sensor | lib/instana/agent.rb | Instana.Agent.report_spans | def report_spans(spans)
return unless @state == :announced
unless @discovered
::Instana.logger.debug("#{__method__} called but discovery hasn't run yet!")
return false
end
path = "com.instana.plugin.ruby/traces.#{@process[:report_pid]}"
uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{path}")
req = Net::HTTP::Post.new(uri)
opts = OJ_OPTIONS.merge({omit_nil: true})
req.body = Oj.dump(spans, opts)
response = make_host_agent_request(req)
if response
last_trace_response = response.code.to_i
if [200, 204].include?(last_trace_response)
return true
end
end
false
rescue => e
Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
Instana.logger.debug e.backtrace.join("\r\n")
end | ruby | def report_spans(spans)
return unless @state == :announced
unless @discovered
::Instana.logger.debug("#{__method__} called but discovery hasn't run yet!")
return false
end
path = "com.instana.plugin.ruby/traces.#{@process[:report_pid]}"
uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{path}")
req = Net::HTTP::Post.new(uri)
opts = OJ_OPTIONS.merge({omit_nil: true})
req.body = Oj.dump(spans, opts)
response = make_host_agent_request(req)
if response
last_trace_response = response.code.to_i
if [200, 204].include?(last_trace_response)
return true
end
end
false
rescue => e
Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
Instana.logger.debug e.backtrace.join("\r\n")
end | [
"def",
"report_spans",
"(",
"spans",
")",
"return",
"unless",
"@state",
"==",
":announced",
"unless",
"@discovered",
"::",
"Instana",
".",
"logger",
".",
"debug",
"(",
"\"#{__method__} called but discovery hasn't run yet!\"",
")",
"return",
"false",
"end",
"path",
"=",
"\"com.instana.plugin.ruby/traces.#{@process[:report_pid]}\"",
"uri",
"=",
"URI",
".",
"parse",
"(",
"\"http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{path}\"",
")",
"req",
"=",
"Net",
"::",
"HTTP",
"::",
"Post",
".",
"new",
"(",
"uri",
")",
"opts",
"=",
"OJ_OPTIONS",
".",
"merge",
"(",
"{",
"omit_nil",
":",
"true",
"}",
")",
"req",
".",
"body",
"=",
"Oj",
".",
"dump",
"(",
"spans",
",",
"opts",
")",
"response",
"=",
"make_host_agent_request",
"(",
"req",
")",
"if",
"response",
"last_trace_response",
"=",
"response",
".",
"code",
".",
"to_i",
"if",
"[",
"200",
",",
"204",
"]",
".",
"include?",
"(",
"last_trace_response",
")",
"return",
"true",
"end",
"end",
"false",
"rescue",
"=>",
"e",
"Instana",
".",
"logger",
".",
"debug",
"\"#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}\"",
"Instana",
".",
"logger",
".",
"debug",
"e",
".",
"backtrace",
".",
"join",
"(",
"\"\\r\\n\"",
")",
"end"
]
| Accept and report spans to the host agent.
@param traces [Array] An array of [Span]
@return [Boolean] | [
"Accept",
"and",
"report",
"spans",
"to",
"the",
"host",
"agent",
"."
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/agent.rb#L281-L309 | train |
instana/ruby-sensor | lib/instana/agent.rb | Instana.Agent.host_agent_available? | def host_agent_available?
@discovered ||= run_discovery
if @discovered
# Try default location or manually configured (if so)
uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/")
req = Net::HTTP::Get.new(uri)
response = make_host_agent_request(req)
if response && (response.code.to_i == 200)
return true
end
end
false
rescue => e
Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
Instana.logger.debug e.backtrace.join("\r\n") unless ::Instana.test?
return false
end | ruby | def host_agent_available?
@discovered ||= run_discovery
if @discovered
# Try default location or manually configured (if so)
uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/")
req = Net::HTTP::Get.new(uri)
response = make_host_agent_request(req)
if response && (response.code.to_i == 200)
return true
end
end
false
rescue => e
Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
Instana.logger.debug e.backtrace.join("\r\n") unless ::Instana.test?
return false
end | [
"def",
"host_agent_available?",
"@discovered",
"||=",
"run_discovery",
"if",
"@discovered",
"uri",
"=",
"URI",
".",
"parse",
"(",
"\"http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/\"",
")",
"req",
"=",
"Net",
"::",
"HTTP",
"::",
"Get",
".",
"new",
"(",
"uri",
")",
"response",
"=",
"make_host_agent_request",
"(",
"req",
")",
"if",
"response",
"&&",
"(",
"response",
".",
"code",
".",
"to_i",
"==",
"200",
")",
"return",
"true",
"end",
"end",
"false",
"rescue",
"=>",
"e",
"Instana",
".",
"logger",
".",
"debug",
"\"#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}\"",
"Instana",
".",
"logger",
".",
"debug",
"e",
".",
"backtrace",
".",
"join",
"(",
"\"\\r\\n\"",
")",
"unless",
"::",
"Instana",
".",
"test?",
"return",
"false",
"end"
]
| Check that the host agent is available and can be contacted. This will
first check localhost and if not, then attempt on the default gateway
for docker in bridged mode. | [
"Check",
"that",
"the",
"host",
"agent",
"is",
"available",
"and",
"can",
"be",
"contacted",
".",
"This",
"will",
"first",
"check",
"localhost",
"and",
"if",
"not",
"then",
"attempt",
"on",
"the",
"default",
"gateway",
"for",
"docker",
"in",
"bridged",
"mode",
"."
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/agent.rb#L315-L334 | train |
instana/ruby-sensor | lib/instana/tracer.rb | Instana.Tracer.start_or_continue_trace | def start_or_continue_trace(name, kvs = {}, incoming_context = {}, &block)
log_start_or_continue(name, kvs, incoming_context)
block.call
rescue Exception => e
log_error(e)
raise
ensure
log_end(name)
end | ruby | def start_or_continue_trace(name, kvs = {}, incoming_context = {}, &block)
log_start_or_continue(name, kvs, incoming_context)
block.call
rescue Exception => e
log_error(e)
raise
ensure
log_end(name)
end | [
"def",
"start_or_continue_trace",
"(",
"name",
",",
"kvs",
"=",
"{",
"}",
",",
"incoming_context",
"=",
"{",
"}",
",",
"&",
"block",
")",
"log_start_or_continue",
"(",
"name",
",",
"kvs",
",",
"incoming_context",
")",
"block",
".",
"call",
"rescue",
"Exception",
"=>",
"e",
"log_error",
"(",
"e",
")",
"raise",
"ensure",
"log_end",
"(",
"name",
")",
"end"
]
| Tracing blocks API methods
Will start a new trace or continue an on-going one (such as
from incoming remote requests with context headers).
@param name [String] the name of the span to start
@param kvs [Hash] list of key values to be reported in the span
@param incoming_context [Hash] specifies the incoming context. At a
minimum, it should specify :trace_id and :span_id from the following:
@:trace_id the trace ID (must be an unsigned hex-string)
:span_id the ID of the parent span (must be an unsigned hex-string)
:level specifies data collection level (optional) | [
"Tracing",
"blocks",
"API",
"methods"
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/tracer.rb#L38-L46 | train |
instana/ruby-sensor | lib/instana/tracer.rb | Instana.Tracer.trace | def trace(name, kvs = {}, &block)
log_entry(name, kvs)
result = block.call
result
rescue Exception => e
log_error(e)
raise
ensure
log_exit(name)
end | ruby | def trace(name, kvs = {}, &block)
log_entry(name, kvs)
result = block.call
result
rescue Exception => e
log_error(e)
raise
ensure
log_exit(name)
end | [
"def",
"trace",
"(",
"name",
",",
"kvs",
"=",
"{",
"}",
",",
"&",
"block",
")",
"log_entry",
"(",
"name",
",",
"kvs",
")",
"result",
"=",
"block",
".",
"call",
"result",
"rescue",
"Exception",
"=>",
"e",
"log_error",
"(",
"e",
")",
"raise",
"ensure",
"log_exit",
"(",
"name",
")",
"end"
]
| Trace a block of code within the context of the exiting trace
Example usage:
::Instana.tracer.trace(:dbwork, { :db_name => @db.name }) do
@db.select(1)
end
@param name [String] the name of the span to start
@param kvs [Hash] list of key values to be reported in this new span | [
"Trace",
"a",
"block",
"of",
"code",
"within",
"the",
"context",
"of",
"the",
"exiting",
"trace"
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/tracer.rb#L59-L68 | train |
instana/ruby-sensor | lib/instana/tracer.rb | Instana.Tracer.log_start_or_continue | def log_start_or_continue(name, kvs = {}, incoming_context = {})
return if !::Instana.agent.ready? || !::Instana.config[:tracing][:enabled]
::Instana.logger.debug "#{__method__} passed a block. Use `start_or_continue` instead!" if block_given?
self.current_trace = ::Instana::Trace.new(name, kvs, incoming_context)
end | ruby | def log_start_or_continue(name, kvs = {}, incoming_context = {})
return if !::Instana.agent.ready? || !::Instana.config[:tracing][:enabled]
::Instana.logger.debug "#{__method__} passed a block. Use `start_or_continue` instead!" if block_given?
self.current_trace = ::Instana::Trace.new(name, kvs, incoming_context)
end | [
"def",
"log_start_or_continue",
"(",
"name",
",",
"kvs",
"=",
"{",
"}",
",",
"incoming_context",
"=",
"{",
"}",
")",
"return",
"if",
"!",
"::",
"Instana",
".",
"agent",
".",
"ready?",
"||",
"!",
"::",
"Instana",
".",
"config",
"[",
":tracing",
"]",
"[",
":enabled",
"]",
"::",
"Instana",
".",
"logger",
".",
"debug",
"\"#{__method__} passed a block. Use `start_or_continue` instead!\"",
"if",
"block_given?",
"self",
".",
"current_trace",
"=",
"::",
"Instana",
"::",
"Trace",
".",
"new",
"(",
"name",
",",
"kvs",
",",
"incoming_context",
")",
"end"
]
| Lower level tracing API methods
Will start a new trace or continue an on-going one (such as
from incoming remote requests with context headers).
@param name [String] the name of the span to start
@param kvs [Hash] list of key values to be reported in the span
@param incoming_context [Hash] specifies the incoming context. At a
minimum, it should specify :trace_id and :span_id from the following:
:trace_id the trace ID (must be an unsigned hex-string)
:span_id the ID of the parent span (must be an unsigned hex-string)
:level specifies data collection level (optional) | [
"Lower",
"level",
"tracing",
"API",
"methods"
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/tracer.rb#L85-L89 | train |
instana/ruby-sensor | lib/instana/tracer.rb | Instana.Tracer.log_exit | def log_exit(name, kvs = {})
return unless tracing?
if ::Instana.debug? || ::Instana.test?
unless current_span_name?(name)
::Instana.logger.debug "Span mismatch: Attempt to exit #{name} span but #{current_span.name} is active."
end
end
self.current_trace.end_span(kvs)
end | ruby | def log_exit(name, kvs = {})
return unless tracing?
if ::Instana.debug? || ::Instana.test?
unless current_span_name?(name)
::Instana.logger.debug "Span mismatch: Attempt to exit #{name} span but #{current_span.name} is active."
end
end
self.current_trace.end_span(kvs)
end | [
"def",
"log_exit",
"(",
"name",
",",
"kvs",
"=",
"{",
"}",
")",
"return",
"unless",
"tracing?",
"if",
"::",
"Instana",
".",
"debug?",
"||",
"::",
"Instana",
".",
"test?",
"unless",
"current_span_name?",
"(",
"name",
")",
"::",
"Instana",
".",
"logger",
".",
"debug",
"\"Span mismatch: Attempt to exit #{name} span but #{current_span.name} is active.\"",
"end",
"end",
"self",
".",
"current_trace",
".",
"end_span",
"(",
"kvs",
")",
"end"
]
| Closes out the current span
@note `name` isn't really required but helps keep sanity that
we're closing out the span that we really want to close out.
@param name [String] the name of the span to exit (close out)
@param kvs [Hash] list of key values to be reported in the span | [
"Closes",
"out",
"the",
"current",
"span"
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/tracer.rb#L128-L138 | train |
instana/ruby-sensor | lib/instana/tracer.rb | Instana.Tracer.log_end | def log_end(name, kvs = {}, end_time = ::Instana::Util.now_in_ms)
return unless tracing?
if ::Instana.debug? || ::Instana.test?
unless current_span_name?(name)
::Instana.logger.debug "Span mismatch: Attempt to end #{name} span but #{current_span.name} is active."
end
end
self.current_trace.finish(kvs, end_time)
if ::Instana.agent.ready?
if !self.current_trace.has_async? ||
(self.current_trace.has_async? && self.current_trace.complete?)
Instana.processor.add(self.current_trace)
else
# This trace still has outstanding/uncompleted asynchronous spans.
# Put it in the staging queue until the async span closes out or
# 5 minutes has passed. Whichever comes first.
Instana.processor.stage(self.current_trace)
end
end
self.current_trace = nil
end | ruby | def log_end(name, kvs = {}, end_time = ::Instana::Util.now_in_ms)
return unless tracing?
if ::Instana.debug? || ::Instana.test?
unless current_span_name?(name)
::Instana.logger.debug "Span mismatch: Attempt to end #{name} span but #{current_span.name} is active."
end
end
self.current_trace.finish(kvs, end_time)
if ::Instana.agent.ready?
if !self.current_trace.has_async? ||
(self.current_trace.has_async? && self.current_trace.complete?)
Instana.processor.add(self.current_trace)
else
# This trace still has outstanding/uncompleted asynchronous spans.
# Put it in the staging queue until the async span closes out or
# 5 minutes has passed. Whichever comes first.
Instana.processor.stage(self.current_trace)
end
end
self.current_trace = nil
end | [
"def",
"log_end",
"(",
"name",
",",
"kvs",
"=",
"{",
"}",
",",
"end_time",
"=",
"::",
"Instana",
"::",
"Util",
".",
"now_in_ms",
")",
"return",
"unless",
"tracing?",
"if",
"::",
"Instana",
".",
"debug?",
"||",
"::",
"Instana",
".",
"test?",
"unless",
"current_span_name?",
"(",
"name",
")",
"::",
"Instana",
".",
"logger",
".",
"debug",
"\"Span mismatch: Attempt to end #{name} span but #{current_span.name} is active.\"",
"end",
"end",
"self",
".",
"current_trace",
".",
"finish",
"(",
"kvs",
",",
"end_time",
")",
"if",
"::",
"Instana",
".",
"agent",
".",
"ready?",
"if",
"!",
"self",
".",
"current_trace",
".",
"has_async?",
"||",
"(",
"self",
".",
"current_trace",
".",
"has_async?",
"&&",
"self",
".",
"current_trace",
".",
"complete?",
")",
"Instana",
".",
"processor",
".",
"add",
"(",
"self",
".",
"current_trace",
")",
"else",
"Instana",
".",
"processor",
".",
"stage",
"(",
"self",
".",
"current_trace",
")",
"end",
"end",
"self",
".",
"current_trace",
"=",
"nil",
"end"
]
| Closes out the current span in the current trace
and queues the trace for reporting
@note `name` isn't really required but helps keep sanity that
we're ending the span that we really want to close out.
@param name [String] the name of the span to end
@param kvs [Hash] list of key values to be reported in the span | [
"Closes",
"out",
"the",
"current",
"span",
"in",
"the",
"current",
"trace",
"and",
"queues",
"the",
"trace",
"for",
"reporting"
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/tracer.rb#L149-L172 | train |
instana/ruby-sensor | lib/instana/tracer.rb | Instana.Tracer.log_async_info | def log_async_info(kvs, span)
# Asynchronous spans can persist longer than the parent
# trace. With the trace ID, we check the current trace
# but otherwise, we search staged traces.
if tracing? && self.current_trace.id == span.context.trace_id
self.current_trace.add_async_info(kvs, span)
else
trace = ::Instana.processor.staged_trace(span.context.trace_id)
if trace
trace.add_async_info(kvs, span)
else
::Instana.logger.debug "#{__method__}: Couldn't find staged trace. #{span.inspect}"
end
end
end | ruby | def log_async_info(kvs, span)
# Asynchronous spans can persist longer than the parent
# trace. With the trace ID, we check the current trace
# but otherwise, we search staged traces.
if tracing? && self.current_trace.id == span.context.trace_id
self.current_trace.add_async_info(kvs, span)
else
trace = ::Instana.processor.staged_trace(span.context.trace_id)
if trace
trace.add_async_info(kvs, span)
else
::Instana.logger.debug "#{__method__}: Couldn't find staged trace. #{span.inspect}"
end
end
end | [
"def",
"log_async_info",
"(",
"kvs",
",",
"span",
")",
"if",
"tracing?",
"&&",
"self",
".",
"current_trace",
".",
"id",
"==",
"span",
".",
"context",
".",
"trace_id",
"self",
".",
"current_trace",
".",
"add_async_info",
"(",
"kvs",
",",
"span",
")",
"else",
"trace",
"=",
"::",
"Instana",
".",
"processor",
".",
"staged_trace",
"(",
"span",
".",
"context",
".",
"trace_id",
")",
"if",
"trace",
"trace",
".",
"add_async_info",
"(",
"kvs",
",",
"span",
")",
"else",
"::",
"Instana",
".",
"logger",
".",
"debug",
"\"#{__method__}: Couldn't find staged trace. #{span.inspect}\"",
"end",
"end",
"end"
]
| Add info to an asynchronous span
@param kvs [Hash] list of key values to be reported in the span
@param span [Span] the span for this Async op (previously returned
from `log_async_entry`) | [
"Add",
"info",
"to",
"an",
"asynchronous",
"span"
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/tracer.rb#L198-L213 | train |
instana/ruby-sensor | lib/instana/tracer.rb | Instana.Tracer.log_async_error | def log_async_error(e, span)
# Asynchronous spans can persist longer than the parent
# trace. With the trace ID, we check the current trace
# but otherwise, we search staged traces.
if tracing? && self.current_trace.id == span.context.trace_id
self.current_trace.add_async_error(e, span)
else
trace = ::Instana.processor.staged_trace(span.context.trace_id)
if trace
trace.add_async_error(e, span)
else
::Instana.logger.debug "#{__method__}: Couldn't find staged trace. #{span.inspect}"
end
end
end | ruby | def log_async_error(e, span)
# Asynchronous spans can persist longer than the parent
# trace. With the trace ID, we check the current trace
# but otherwise, we search staged traces.
if tracing? && self.current_trace.id == span.context.trace_id
self.current_trace.add_async_error(e, span)
else
trace = ::Instana.processor.staged_trace(span.context.trace_id)
if trace
trace.add_async_error(e, span)
else
::Instana.logger.debug "#{__method__}: Couldn't find staged trace. #{span.inspect}"
end
end
end | [
"def",
"log_async_error",
"(",
"e",
",",
"span",
")",
"if",
"tracing?",
"&&",
"self",
".",
"current_trace",
".",
"id",
"==",
"span",
".",
"context",
".",
"trace_id",
"self",
".",
"current_trace",
".",
"add_async_error",
"(",
"e",
",",
"span",
")",
"else",
"trace",
"=",
"::",
"Instana",
".",
"processor",
".",
"staged_trace",
"(",
"span",
".",
"context",
".",
"trace_id",
")",
"if",
"trace",
"trace",
".",
"add_async_error",
"(",
"e",
",",
"span",
")",
"else",
"::",
"Instana",
".",
"logger",
".",
"debug",
"\"#{__method__}: Couldn't find staged trace. #{span.inspect}\"",
"end",
"end",
"end"
]
| Add an error to an asynchronous span
@param e [Exception] Add exception to the current span
@param span [Span] the span for this Async op (previously returned
from `log_async_entry`) | [
"Add",
"an",
"error",
"to",
"an",
"asynchronous",
"span"
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/tracer.rb#L221-L236 | train |
instana/ruby-sensor | lib/instana/tracer.rb | Instana.Tracer.log_async_exit | def log_async_exit(_name, kvs, span)
# An asynchronous span can end after the current trace has
# already completed so we make sure that we end the span
# on the right trace.
if tracing? && self.current_trace.id == span.context.trace_id
self.current_trace.end_async_span(kvs, span)
else
# Different trace from current so find the staged trace
# and close out the span on it.
trace = ::Instana.processor.staged_trace(span.context.trace_id)
if trace
trace.end_async_span(kvs, span)
else
::Instana.logger.debug "#{__method__}: Couldn't find staged trace. #{span.inspect}"
end
end
end | ruby | def log_async_exit(_name, kvs, span)
# An asynchronous span can end after the current trace has
# already completed so we make sure that we end the span
# on the right trace.
if tracing? && self.current_trace.id == span.context.trace_id
self.current_trace.end_async_span(kvs, span)
else
# Different trace from current so find the staged trace
# and close out the span on it.
trace = ::Instana.processor.staged_trace(span.context.trace_id)
if trace
trace.end_async_span(kvs, span)
else
::Instana.logger.debug "#{__method__}: Couldn't find staged trace. #{span.inspect}"
end
end
end | [
"def",
"log_async_exit",
"(",
"_name",
",",
"kvs",
",",
"span",
")",
"if",
"tracing?",
"&&",
"self",
".",
"current_trace",
".",
"id",
"==",
"span",
".",
"context",
".",
"trace_id",
"self",
".",
"current_trace",
".",
"end_async_span",
"(",
"kvs",
",",
"span",
")",
"else",
"trace",
"=",
"::",
"Instana",
".",
"processor",
".",
"staged_trace",
"(",
"span",
".",
"context",
".",
"trace_id",
")",
"if",
"trace",
"trace",
".",
"end_async_span",
"(",
"kvs",
",",
"span",
")",
"else",
"::",
"Instana",
".",
"logger",
".",
"debug",
"\"#{__method__}: Couldn't find staged trace. #{span.inspect}\"",
"end",
"end",
"end"
]
| Closes out an asynchronous span
@param name [String] the name of the async span to exit (close out)
@param kvs [Hash] list of key values to be reported in the span
@param span [Span] the span for this Async op (previously returned
from `log_async_entry`) | [
"Closes",
"out",
"an",
"asynchronous",
"span"
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/tracer.rb#L245-L262 | train |
instana/ruby-sensor | lib/instana/tracer.rb | Instana.Tracer.inject | def inject(span_context, format, carrier)
case format
when OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY
::Instana.logger.debug 'Unsupported inject format'
when OpenTracing::FORMAT_RACK
carrier['X-Instana-T'] = ::Instana::Util.id_to_header(span_context.trace_id)
carrier['X-Instana-S'] = ::Instana::Util.id_to_header(span_context.span_id)
else
::Instana.logger.debug 'Unknown inject format'
end
end | ruby | def inject(span_context, format, carrier)
case format
when OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY
::Instana.logger.debug 'Unsupported inject format'
when OpenTracing::FORMAT_RACK
carrier['X-Instana-T'] = ::Instana::Util.id_to_header(span_context.trace_id)
carrier['X-Instana-S'] = ::Instana::Util.id_to_header(span_context.span_id)
else
::Instana.logger.debug 'Unknown inject format'
end
end | [
"def",
"inject",
"(",
"span_context",
",",
"format",
",",
"carrier",
")",
"case",
"format",
"when",
"OpenTracing",
"::",
"FORMAT_TEXT_MAP",
",",
"OpenTracing",
"::",
"FORMAT_BINARY",
"::",
"Instana",
".",
"logger",
".",
"debug",
"'Unsupported inject format'",
"when",
"OpenTracing",
"::",
"FORMAT_RACK",
"carrier",
"[",
"'X-Instana-T'",
"]",
"=",
"::",
"Instana",
"::",
"Util",
".",
"id_to_header",
"(",
"span_context",
".",
"trace_id",
")",
"carrier",
"[",
"'X-Instana-S'",
"]",
"=",
"::",
"Instana",
"::",
"Util",
".",
"id_to_header",
"(",
"span_context",
".",
"span_id",
")",
"else",
"::",
"Instana",
".",
"logger",
".",
"debug",
"'Unknown inject format'",
"end",
"end"
]
| Inject a span into the given carrier
@param span_context [SpanContext]
@param format [OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY, OpenTracing::FORMAT_RACK]
@param carrier [Carrier] | [
"Inject",
"a",
"span",
"into",
"the",
"given",
"carrier"
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/tracer.rb#L296-L306 | train |
instana/ruby-sensor | lib/instana/tracer.rb | Instana.Tracer.extract | def extract(format, carrier)
case format
when OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY
::Instana.logger.debug 'Unsupported extract format'
when OpenTracing::FORMAT_RACK
::Instana::SpanContext.new(::Instana::Util.header_to_id(carrier['HTTP_X_INSTANA_T']),
::Instana::Util.header_to_id(carrier['HTTP_X_INSTANA_S']))
else
::Instana.logger.debug 'Unknown inject format'
nil
end
end | ruby | def extract(format, carrier)
case format
when OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY
::Instana.logger.debug 'Unsupported extract format'
when OpenTracing::FORMAT_RACK
::Instana::SpanContext.new(::Instana::Util.header_to_id(carrier['HTTP_X_INSTANA_T']),
::Instana::Util.header_to_id(carrier['HTTP_X_INSTANA_S']))
else
::Instana.logger.debug 'Unknown inject format'
nil
end
end | [
"def",
"extract",
"(",
"format",
",",
"carrier",
")",
"case",
"format",
"when",
"OpenTracing",
"::",
"FORMAT_TEXT_MAP",
",",
"OpenTracing",
"::",
"FORMAT_BINARY",
"::",
"Instana",
".",
"logger",
".",
"debug",
"'Unsupported extract format'",
"when",
"OpenTracing",
"::",
"FORMAT_RACK",
"::",
"Instana",
"::",
"SpanContext",
".",
"new",
"(",
"::",
"Instana",
"::",
"Util",
".",
"header_to_id",
"(",
"carrier",
"[",
"'HTTP_X_INSTANA_T'",
"]",
")",
",",
"::",
"Instana",
"::",
"Util",
".",
"header_to_id",
"(",
"carrier",
"[",
"'HTTP_X_INSTANA_S'",
"]",
")",
")",
"else",
"::",
"Instana",
".",
"logger",
".",
"debug",
"'Unknown inject format'",
"nil",
"end",
"end"
]
| Extract a span from a carrier
@param format [OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY, OpenTracing::FORMAT_RACK]
@param carrier [Carrier]
@return [SpanContext] | [
"Extract",
"a",
"span",
"from",
"a",
"carrier"
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/tracer.rb#L315-L326 | train |
instana/ruby-sensor | lib/instana/tracing/processor.rb | Instana.Processor.add | def add(trace)
# Do a quick checkup on our background thread.
if ::Instana.agent.collect_thread.nil? || !::Instana.agent.collect_thread.alive?
::Instana.agent.spawn_background_thread
end
# ::Instana.logger.debug("Queuing completed trace id: #{trace.id}")
@queue.push(trace)
end | ruby | def add(trace)
# Do a quick checkup on our background thread.
if ::Instana.agent.collect_thread.nil? || !::Instana.agent.collect_thread.alive?
::Instana.agent.spawn_background_thread
end
# ::Instana.logger.debug("Queuing completed trace id: #{trace.id}")
@queue.push(trace)
end | [
"def",
"add",
"(",
"trace",
")",
"if",
"::",
"Instana",
".",
"agent",
".",
"collect_thread",
".",
"nil?",
"||",
"!",
"::",
"Instana",
".",
"agent",
".",
"collect_thread",
".",
"alive?",
"::",
"Instana",
".",
"agent",
".",
"spawn_background_thread",
"end",
"@queue",
".",
"push",
"(",
"trace",
")",
"end"
]
| Adds a trace to the queue to be processed and
sent to the host agent
@param [Trace] the trace to be added to the queue | [
"Adds",
"a",
"trace",
"to",
"the",
"queue",
"to",
"be",
"processed",
"and",
"sent",
"to",
"the",
"host",
"agent"
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/tracing/processor.rb#L31-L39 | train |
instana/ruby-sensor | lib/instana/tracing/processor.rb | Instana.Processor.staged_trace | def staged_trace(trace_id)
candidate = nil
@staging_lock.synchronize {
@staging_queue.each do |trace|
if trace.id == trace_id
candidate = trace
break
end
end
}
unless candidate
::Instana.logger.debug("Couldn't find staged trace with trace_id: #{trace_id}")
end
candidate
end | ruby | def staged_trace(trace_id)
candidate = nil
@staging_lock.synchronize {
@staging_queue.each do |trace|
if trace.id == trace_id
candidate = trace
break
end
end
}
unless candidate
::Instana.logger.debug("Couldn't find staged trace with trace_id: #{trace_id}")
end
candidate
end | [
"def",
"staged_trace",
"(",
"trace_id",
")",
"candidate",
"=",
"nil",
"@staging_lock",
".",
"synchronize",
"{",
"@staging_queue",
".",
"each",
"do",
"|",
"trace",
"|",
"if",
"trace",
".",
"id",
"==",
"trace_id",
"candidate",
"=",
"trace",
"break",
"end",
"end",
"}",
"unless",
"candidate",
"::",
"Instana",
".",
"logger",
".",
"debug",
"(",
"\"Couldn't find staged trace with trace_id: #{trace_id}\"",
")",
"end",
"candidate",
"end"
]
| Retrieves a single staged trace from the staging queue. Staged traces
are traces that have completed but may have outstanding
asynchronous spans.
@param trace_id [Integer] the Trace ID to be searched for | [
"Retrieves",
"a",
"single",
"staged",
"trace",
"from",
"the",
"staging",
"queue",
".",
"Staged",
"traces",
"are",
"traces",
"that",
"have",
"completed",
"but",
"may",
"have",
"outstanding",
"asynchronous",
"spans",
"."
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/tracing/processor.rb#L166-L180 | train |
instana/ruby-sensor | lib/instana/tracing/trace.rb | Instana.Trace.new_span | def new_span(name, kvs = nil, start_time = ::Instana::Util.now_in_ms, child_of = nil)
return unless @current_span
if child_of && child_of.is_a?(::Instana::Span)
new_span = Span.new(name, @id, parent_id: child_of.id, start_time: start_time)
new_span.parent = child_of
new_span.baggage = child_of.baggage.dup
else
new_span = Span.new(name, @id, parent_id: @current_span.id, start_time: start_time)
new_span.parent = @current_span
new_span.baggage = @current_span.baggage.dup
end
new_span.set_tags(kvs) if kvs
@spans.add(new_span)
@current_span = new_span
end | ruby | def new_span(name, kvs = nil, start_time = ::Instana::Util.now_in_ms, child_of = nil)
return unless @current_span
if child_of && child_of.is_a?(::Instana::Span)
new_span = Span.new(name, @id, parent_id: child_of.id, start_time: start_time)
new_span.parent = child_of
new_span.baggage = child_of.baggage.dup
else
new_span = Span.new(name, @id, parent_id: @current_span.id, start_time: start_time)
new_span.parent = @current_span
new_span.baggage = @current_span.baggage.dup
end
new_span.set_tags(kvs) if kvs
@spans.add(new_span)
@current_span = new_span
end | [
"def",
"new_span",
"(",
"name",
",",
"kvs",
"=",
"nil",
",",
"start_time",
"=",
"::",
"Instana",
"::",
"Util",
".",
"now_in_ms",
",",
"child_of",
"=",
"nil",
")",
"return",
"unless",
"@current_span",
"if",
"child_of",
"&&",
"child_of",
".",
"is_a?",
"(",
"::",
"Instana",
"::",
"Span",
")",
"new_span",
"=",
"Span",
".",
"new",
"(",
"name",
",",
"@id",
",",
"parent_id",
":",
"child_of",
".",
"id",
",",
"start_time",
":",
"start_time",
")",
"new_span",
".",
"parent",
"=",
"child_of",
"new_span",
".",
"baggage",
"=",
"child_of",
".",
"baggage",
".",
"dup",
"else",
"new_span",
"=",
"Span",
".",
"new",
"(",
"name",
",",
"@id",
",",
"parent_id",
":",
"@current_span",
".",
"id",
",",
"start_time",
":",
"start_time",
")",
"new_span",
".",
"parent",
"=",
"@current_span",
"new_span",
".",
"baggage",
"=",
"@current_span",
".",
"baggage",
".",
"dup",
"end",
"new_span",
".",
"set_tags",
"(",
"kvs",
")",
"if",
"kvs",
"@spans",
".",
"add",
"(",
"new_span",
")",
"@current_span",
"=",
"new_span",
"end"
]
| Initializes a new instance of Trace
@param name [String] the name of the span to start
@param kvs [Hash] list of key values to be reported in the span
@param incoming_context [Hash] specifies the incoming context. At a
minimum, it should specify :trace_id and :span_id from the following:
:trace_id the trace ID (must be an unsigned hex-string)
:span_id the ID of the parent span (must be an unsigned hex-string)
:level specifies data collection level (optional)
Start a new span as a child of @current_span
@param name [String] the name of the span to start
@param kvs [Hash] list of key values to be reported in the span | [
"Initializes",
"a",
"new",
"instance",
"of",
"Trace"
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/tracing/trace.rb#L59-L75 | train |
instana/ruby-sensor | lib/instana/tracing/trace.rb | Instana.Trace.add_error | def add_error(e, span = nil)
# Return if we've already logged this exception and it
# is just propogating up the spans.
return if e && e.instance_variable_get(:@instana_logged) || @current_span.nil?
span ||= @current_span
span.add_error(e)
end | ruby | def add_error(e, span = nil)
# Return if we've already logged this exception and it
# is just propogating up the spans.
return if e && e.instance_variable_get(:@instana_logged) || @current_span.nil?
span ||= @current_span
span.add_error(e)
end | [
"def",
"add_error",
"(",
"e",
",",
"span",
"=",
"nil",
")",
"return",
"if",
"e",
"&&",
"e",
".",
"instance_variable_get",
"(",
":@instana_logged",
")",
"||",
"@current_span",
".",
"nil?",
"span",
"||=",
"@current_span",
"span",
".",
"add_error",
"(",
"e",
")",
"end"
]
| Log an error into the current span
@param e [Exception] Add exception to the current span | [
"Log",
"an",
"error",
"into",
"the",
"current",
"span"
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/tracing/trace.rb#L95-L101 | train |
instana/ruby-sensor | lib/instana/tracing/trace.rb | Instana.Trace.end_span | def end_span(kvs = {}, end_time = ::Instana::Util.now_in_ms)
return unless @current_span
@current_span.close(end_time)
add_info(kvs) if kvs && !kvs.empty?
@current_span = @current_span.parent unless @current_span.is_root?
end | ruby | def end_span(kvs = {}, end_time = ::Instana::Util.now_in_ms)
return unless @current_span
@current_span.close(end_time)
add_info(kvs) if kvs && !kvs.empty?
@current_span = @current_span.parent unless @current_span.is_root?
end | [
"def",
"end_span",
"(",
"kvs",
"=",
"{",
"}",
",",
"end_time",
"=",
"::",
"Instana",
"::",
"Util",
".",
"now_in_ms",
")",
"return",
"unless",
"@current_span",
"@current_span",
".",
"close",
"(",
"end_time",
")",
"add_info",
"(",
"kvs",
")",
"if",
"kvs",
"&&",
"!",
"kvs",
".",
"empty?",
"@current_span",
"=",
"@current_span",
".",
"parent",
"unless",
"@current_span",
".",
"is_root?",
"end"
]
| Close out the current span and set the parent as
the current span
@param kvs [Hash] list of key values to be reported in the span | [
"Close",
"out",
"the",
"current",
"span",
"and",
"set",
"the",
"parent",
"as",
"the",
"current",
"span"
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/tracing/trace.rb#L108-L114 | train |
instana/ruby-sensor | lib/instana/tracing/trace.rb | Instana.Trace.end_async_span | def end_async_span(kvs = {}, span)
span.set_tags(kvs) unless kvs.empty?
span.close
end | ruby | def end_async_span(kvs = {}, span)
span.set_tags(kvs) unless kvs.empty?
span.close
end | [
"def",
"end_async_span",
"(",
"kvs",
"=",
"{",
"}",
",",
"span",
")",
"span",
".",
"set_tags",
"(",
"kvs",
")",
"unless",
"kvs",
".",
"empty?",
"span",
".",
"close",
"end"
]
| End an asynchronous span
@param name [Symbol] the name of the span
@param kvs [Hash] list of key values to be reported in the span
@param span [Span] the span of this Async op (previously returned
from `log_async_entry`) | [
"End",
"an",
"asynchronous",
"span"
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/tracing/trace.rb#L168-L171 | train |
instana/ruby-sensor | lib/instana/tracing/trace.rb | Instana.Trace.add_backtrace_to_span | def add_backtrace_to_span(bt, limit = nil, span)
frame_count = 0
span[:stack] = []
bt.each do |i|
# If the stack has the full instana gem version in it's path
# then don't include that frame. Also don't exclude the Rack module.
if !i.match(/instana\/instrumentation\/rack.rb/).nil? ||
(i.match(::Instana::VERSION_FULL).nil? && i.match('lib/instana/').nil?)
break if limit && frame_count >= limit
x = i.split(':')
span[:stack] << {
:f => x[0],
:n => x[1],
:m => x[2]
}
frame_count = frame_count + 1 if limit
end
end
end | ruby | def add_backtrace_to_span(bt, limit = nil, span)
frame_count = 0
span[:stack] = []
bt.each do |i|
# If the stack has the full instana gem version in it's path
# then don't include that frame. Also don't exclude the Rack module.
if !i.match(/instana\/instrumentation\/rack.rb/).nil? ||
(i.match(::Instana::VERSION_FULL).nil? && i.match('lib/instana/').nil?)
break if limit && frame_count >= limit
x = i.split(':')
span[:stack] << {
:f => x[0],
:n => x[1],
:m => x[2]
}
frame_count = frame_count + 1 if limit
end
end
end | [
"def",
"add_backtrace_to_span",
"(",
"bt",
",",
"limit",
"=",
"nil",
",",
"span",
")",
"frame_count",
"=",
"0",
"span",
"[",
":stack",
"]",
"=",
"[",
"]",
"bt",
".",
"each",
"do",
"|",
"i",
"|",
"if",
"!",
"i",
".",
"match",
"(",
"/",
"\\/",
"\\/",
"/",
")",
".",
"nil?",
"||",
"(",
"i",
".",
"match",
"(",
"::",
"Instana",
"::",
"VERSION_FULL",
")",
".",
"nil?",
"&&",
"i",
".",
"match",
"(",
"'lib/instana/'",
")",
".",
"nil?",
")",
"break",
"if",
"limit",
"&&",
"frame_count",
">=",
"limit",
"x",
"=",
"i",
".",
"split",
"(",
"':'",
")",
"span",
"[",
":stack",
"]",
"<<",
"{",
":f",
"=>",
"x",
"[",
"0",
"]",
",",
":n",
"=>",
"x",
"[",
"1",
"]",
",",
":m",
"=>",
"x",
"[",
"2",
"]",
"}",
"frame_count",
"=",
"frame_count",
"+",
"1",
"if",
"limit",
"end",
"end",
"end"
]
| Adds the passed in backtrace to the specified span. Backtrace can be one
generated from Kernel.caller or one attached to an exception
@param bt [Array] the backtrace
@param limit [Integer] Limit the backtrace to the top <limit> frames
@param span [Span] the span to add the backtrace to or if unspecified
the current span | [
"Adds",
"the",
"passed",
"in",
"backtrace",
"to",
"the",
"specified",
"span",
".",
"Backtrace",
"can",
"be",
"one",
"generated",
"from",
"Kernel",
".",
"caller",
"or",
"one",
"attached",
"to",
"an",
"exception"
]
| 9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99 | https://github.com/instana/ruby-sensor/blob/9d1b3e46b22c4f77919f67ff6ee5831dad5d5b99/lib/instana/tracing/trace.rb#L297-L319 | train |
Origen-SDK/origen | lib/origen/parameters.rb | Origen.Parameters.param? | def param?(name)
_param = name.to_s =~ /^params./ ? name.to_s : 'params.' + name.to_s
begin
val = eval("self.#{_param}")
rescue
nil
else
val
end
end | ruby | def param?(name)
_param = name.to_s =~ /^params./ ? name.to_s : 'params.' + name.to_s
begin
val = eval("self.#{_param}")
rescue
nil
else
val
end
end | [
"def",
"param?",
"(",
"name",
")",
"_param",
"=",
"name",
".",
"to_s",
"=~",
"/",
"/",
"?",
"name",
".",
"to_s",
":",
"'params.'",
"+",
"name",
".",
"to_s",
"begin",
"val",
"=",
"eval",
"(",
"\"self.#{_param}\"",
")",
"rescue",
"nil",
"else",
"val",
"end",
"end"
]
| Return value of param if it exists, nil otherwise. | [
"Return",
"value",
"of",
"param",
"if",
"it",
"exists",
"nil",
"otherwise",
"."
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/parameters.rb#L73-L82 | train |
Origen-SDK/origen | lib/origen/controller.rb | Origen.Controller.model | def model
@model ||= begin
if self.class.path_to_model
m = eval(self.class.path_to_model)
if m
if m.respond_to?(:_controller=)
m.send(:_controller=, self)
end
else
fail "No model object found at path: #{self.class.path_to_model}"
end
m
end
end
end | ruby | def model
@model ||= begin
if self.class.path_to_model
m = eval(self.class.path_to_model)
if m
if m.respond_to?(:_controller=)
m.send(:_controller=, self)
end
else
fail "No model object found at path: #{self.class.path_to_model}"
end
m
end
end
end | [
"def",
"model",
"@model",
"||=",
"begin",
"if",
"self",
".",
"class",
".",
"path_to_model",
"m",
"=",
"eval",
"(",
"self",
".",
"class",
".",
"path_to_model",
")",
"if",
"m",
"if",
"m",
".",
"respond_to?",
"(",
":_controller=",
")",
"m",
".",
"send",
"(",
":_controller=",
",",
"self",
")",
"end",
"else",
"fail",
"\"No model object found at path: #{self.class.path_to_model}\"",
"end",
"m",
"end",
"end",
"end"
]
| Returns the controller's model | [
"Returns",
"the",
"controller",
"s",
"model"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/controller.rb#L65-L79 | train |
Origen-SDK/origen | lib/origen/controller.rb | Origen.Controller.method_missing | def method_missing(method, *args, &block)
if model.respond_to?(method)
# This method is handled separately since it is important to produce a proxy method
# that takes no arguments, otherwise the register address lookup system mistakes it
# for a legacy way of calculating the base address whereby the register itself was
# given as an argument.
if method.to_sym == :base_address
define_singleton_method(method) do
model.send(method)
end
base_address
else
define_singleton_method(method) do |*args, &block|
model.send(method, *args, &block)
end
send(method, *args, &block)
end
else
super
end
end | ruby | def method_missing(method, *args, &block)
if model.respond_to?(method)
# This method is handled separately since it is important to produce a proxy method
# that takes no arguments, otherwise the register address lookup system mistakes it
# for a legacy way of calculating the base address whereby the register itself was
# given as an argument.
if method.to_sym == :base_address
define_singleton_method(method) do
model.send(method)
end
base_address
else
define_singleton_method(method) do |*args, &block|
model.send(method, *args, &block)
end
send(method, *args, &block)
end
else
super
end
end | [
"def",
"method_missing",
"(",
"method",
",",
"*",
"args",
",",
"&",
"block",
")",
"if",
"model",
".",
"respond_to?",
"(",
"method",
")",
"if",
"method",
".",
"to_sym",
"==",
":base_address",
"define_singleton_method",
"(",
"method",
")",
"do",
"model",
".",
"send",
"(",
"method",
")",
"end",
"base_address",
"else",
"define_singleton_method",
"(",
"method",
")",
"do",
"|",
"*",
"args",
",",
"&",
"block",
"|",
"model",
".",
"send",
"(",
"method",
",",
"*",
"args",
",",
"&",
"block",
")",
"end",
"send",
"(",
"method",
",",
"*",
"args",
",",
"&",
"block",
")",
"end",
"else",
"super",
"end",
"end"
]
| Used to proxy all method and attribute requests not implemented on the controller
to the model.
On first call of a missing method a method is generated to avoid the missing lookup
next time, this should be faster for repeated lookups of the same method, e.g. reg | [
"Used",
"to",
"proxy",
"all",
"method",
"and",
"attribute",
"requests",
"not",
"implemented",
"on",
"the",
"controller",
"to",
"the",
"model",
"."
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/controller.rb#L122-L142 | train |
Origen-SDK/origen | lib/origen/chips.rb | Origen.Chips.has_chip? | def has_chip?(s, options = {})
_chips
options = {
group: nil,
family: nil,
performance: nil,
chip: nil,
creating_spec: false
}.update(options)
options[:chip] = s
!!show_chips(options)
end | ruby | def has_chip?(s, options = {})
_chips
options = {
group: nil,
family: nil,
performance: nil,
chip: nil,
creating_spec: false
}.update(options)
options[:chip] = s
!!show_chips(options)
end | [
"def",
"has_chip?",
"(",
"s",
",",
"options",
"=",
"{",
"}",
")",
"_chips",
"options",
"=",
"{",
"group",
":",
"nil",
",",
"family",
":",
"nil",
",",
"performance",
":",
"nil",
",",
"chip",
":",
"nil",
",",
"creating_spec",
":",
"false",
"}",
".",
"update",
"(",
"options",
")",
"options",
"[",
":chip",
"]",
"=",
"s",
"!",
"!",
"show_chips",
"(",
"options",
")",
"end"
]
| Check if the current IP has a spec | [
"Check",
"if",
"the",
"current",
"IP",
"has",
"a",
"spec"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/chips.rb#L86-L97 | train |
Origen-SDK/origen | lib/origen/chips.rb | Origen.Chips.filter_hash | def filter_hash(hash, filter)
fail 'Hash argument is not a Hash!' unless hash.is_a? Hash
filtered_hash = {}
select_logic = case filter
when String then 'k[Regexp.new(filter)]'
when (Fixnum || Integer || Float || Numeric) then "k[Regexp.new('#{filter}')]"
when Regexp then 'k[filter]'
when Symbol then
'k == filter'
when NilClass then true # Return all specs if a filter is set to nil (i.e. user doesn't care about this filter)
else true
end
# rubocop:disable UnusedBlockArgument
filtered_hash = hash.select do |k, v|
[TrueClass, FalseClass].include?(select_logic.class) ? select_logic : eval(select_logic)
end
filtered_hash
end | ruby | def filter_hash(hash, filter)
fail 'Hash argument is not a Hash!' unless hash.is_a? Hash
filtered_hash = {}
select_logic = case filter
when String then 'k[Regexp.new(filter)]'
when (Fixnum || Integer || Float || Numeric) then "k[Regexp.new('#{filter}')]"
when Regexp then 'k[filter]'
when Symbol then
'k == filter'
when NilClass then true # Return all specs if a filter is set to nil (i.e. user doesn't care about this filter)
else true
end
# rubocop:disable UnusedBlockArgument
filtered_hash = hash.select do |k, v|
[TrueClass, FalseClass].include?(select_logic.class) ? select_logic : eval(select_logic)
end
filtered_hash
end | [
"def",
"filter_hash",
"(",
"hash",
",",
"filter",
")",
"fail",
"'Hash argument is not a Hash!'",
"unless",
"hash",
".",
"is_a?",
"Hash",
"filtered_hash",
"=",
"{",
"}",
"select_logic",
"=",
"case",
"filter",
"when",
"String",
"then",
"'k[Regexp.new(filter)]'",
"when",
"(",
"Fixnum",
"||",
"Integer",
"||",
"Float",
"||",
"Numeric",
")",
"then",
"\"k[Regexp.new('#{filter}')]\"",
"when",
"Regexp",
"then",
"'k[filter]'",
"when",
"Symbol",
"then",
"'k == filter'",
"when",
"NilClass",
"then",
"true",
"else",
"true",
"end",
"filtered_hash",
"=",
"hash",
".",
"select",
"do",
"|",
"k",
",",
"v",
"|",
"[",
"TrueClass",
",",
"FalseClass",
"]",
".",
"include?",
"(",
"select_logic",
".",
"class",
")",
"?",
"select_logic",
":",
"eval",
"(",
"select_logic",
")",
"end",
"filtered_hash",
"end"
]
| Return a hash based on the filter provided | [
"Return",
"a",
"hash",
"based",
"on",
"the",
"filter",
"provided"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/chips.rb#L220-L237 | train |
Origen-SDK/origen | lib/c99/nvm.rb | C99.NVMSub.add_reg_with_block_format | def add_reg_with_block_format
# ** Data Register 3 **
# This is dreg
add_reg :dreg, 0x1000, size: 16 do |reg|
# This is dreg bit 15
reg.bit 15, :bit15, reset: 1
# **Bit 14** - This does something cool
#
# 0 | Coolness is disabled
# 1 | Coolness is enabled
reg.bits 14, :bit14
# This is dreg bit upper
reg.bits 13..8, :upper
# This is dreg bit lower
# This is dreg bit lower line 2
reg.bit 7..0, :lower, writable: false, reset: 0x55
end
# This is dreg2
reg :dreg2, 0x1000, size: 16 do
# This is dreg2 bit 15
bit 15, :bit15, reset: 1
# This is dreg2 bit upper
bits 14..8, :upper
# This is dreg2 bit lower
# This is dreg2 bit lower line 2
bit 7..0, :lower, writable: false, reset: 0x55
end
# Finally a test that descriptions can be supplied via the API
reg :dreg3, 0x1000, size: 16, description: "** Data Register 3 **\nThis is dreg3" do
bit 15, :bit15, reset: 1, description: 'This is dreg3 bit 15'
bit 14, :bit14, description: "**Bit 14** - This does something cool\n\n0 | Coolness is disabled\n1 | Coolness is enabled"
bits 13..8, :upper, description: 'This is dreg3 bit upper'
bit 7..0, :lower, writable: false, reset: 0x55, description: "This is dreg3 bit lower\nThis is dreg3 bit lower line 2"
end
reg :dreg4, 0x1000, size: 8, description: "** Data Register 4 **\nThis is dreg4" do
bit 7..0, :busy, reset: 0x55, description: "**Busy Bits** - These do something super cool\n\n0 | Job0\n1 | Job1\n10 | Job2\n11 | Job3\n100 | Job4\n101 | Job5\n110 | Job6\n111 | Job7\n1000 | Job8\n1001 | Job9\n1010 | Job10\n1011 | Job11\n1100 | Job12\n1101 | Job13\n1110 | Job14\n1111 | Job15\n10000 | Job16\n10001 | Job17\n10010 | Job18"
end
end | ruby | def add_reg_with_block_format
# ** Data Register 3 **
# This is dreg
add_reg :dreg, 0x1000, size: 16 do |reg|
# This is dreg bit 15
reg.bit 15, :bit15, reset: 1
# **Bit 14** - This does something cool
#
# 0 | Coolness is disabled
# 1 | Coolness is enabled
reg.bits 14, :bit14
# This is dreg bit upper
reg.bits 13..8, :upper
# This is dreg bit lower
# This is dreg bit lower line 2
reg.bit 7..0, :lower, writable: false, reset: 0x55
end
# This is dreg2
reg :dreg2, 0x1000, size: 16 do
# This is dreg2 bit 15
bit 15, :bit15, reset: 1
# This is dreg2 bit upper
bits 14..8, :upper
# This is dreg2 bit lower
# This is dreg2 bit lower line 2
bit 7..0, :lower, writable: false, reset: 0x55
end
# Finally a test that descriptions can be supplied via the API
reg :dreg3, 0x1000, size: 16, description: "** Data Register 3 **\nThis is dreg3" do
bit 15, :bit15, reset: 1, description: 'This is dreg3 bit 15'
bit 14, :bit14, description: "**Bit 14** - This does something cool\n\n0 | Coolness is disabled\n1 | Coolness is enabled"
bits 13..8, :upper, description: 'This is dreg3 bit upper'
bit 7..0, :lower, writable: false, reset: 0x55, description: "This is dreg3 bit lower\nThis is dreg3 bit lower line 2"
end
reg :dreg4, 0x1000, size: 8, description: "** Data Register 4 **\nThis is dreg4" do
bit 7..0, :busy, reset: 0x55, description: "**Busy Bits** - These do something super cool\n\n0 | Job0\n1 | Job1\n10 | Job2\n11 | Job3\n100 | Job4\n101 | Job5\n110 | Job6\n111 | Job7\n1000 | Job8\n1001 | Job9\n1010 | Job10\n1011 | Job11\n1100 | Job12\n1101 | Job13\n1110 | Job14\n1111 | Job15\n10000 | Job16\n10001 | Job17\n10010 | Job18"
end
end | [
"def",
"add_reg_with_block_format",
"add_reg",
":dreg",
",",
"0x1000",
",",
"size",
":",
"16",
"do",
"|",
"reg",
"|",
"reg",
".",
"bit",
"15",
",",
":bit15",
",",
"reset",
":",
"1",
"reg",
".",
"bits",
"14",
",",
":bit14",
"reg",
".",
"bits",
"13",
"..",
"8",
",",
":upper",
"reg",
".",
"bit",
"7",
"..",
"0",
",",
":lower",
",",
"writable",
":",
"false",
",",
"reset",
":",
"0x55",
"end",
"reg",
":dreg2",
",",
"0x1000",
",",
"size",
":",
"16",
"do",
"bit",
"15",
",",
":bit15",
",",
"reset",
":",
"1",
"bits",
"14",
"..",
"8",
",",
":upper",
"bit",
"7",
"..",
"0",
",",
":lower",
",",
"writable",
":",
"false",
",",
"reset",
":",
"0x55",
"end",
"reg",
":dreg3",
",",
"0x1000",
",",
"size",
":",
"16",
",",
"description",
":",
"\"** Data Register 3 **\\nThis is dreg3\"",
"do",
"bit",
"15",
",",
":bit15",
",",
"reset",
":",
"1",
",",
"description",
":",
"'This is dreg3 bit 15'",
"bit",
"14",
",",
":bit14",
",",
"description",
":",
"\"**Bit 14** - This does something cool\\n\\n0 | Coolness is disabled\\n1 | Coolness is enabled\"",
"bits",
"13",
"..",
"8",
",",
":upper",
",",
"description",
":",
"'This is dreg3 bit upper'",
"bit",
"7",
"..",
"0",
",",
":lower",
",",
"writable",
":",
"false",
",",
"reset",
":",
"0x55",
",",
"description",
":",
"\"This is dreg3 bit lower\\nThis is dreg3 bit lower line 2\"",
"end",
"reg",
":dreg4",
",",
"0x1000",
",",
"size",
":",
"8",
",",
"description",
":",
"\"** Data Register 4 **\\nThis is dreg4\"",
"do",
"bit",
"7",
"..",
"0",
",",
":busy",
",",
"reset",
":",
"0x55",
",",
"description",
":",
"\"**Busy Bits** - These do something super cool\\n\\n0 | Job0\\n1 | Job1\\n10 | Job2\\n11 | Job3\\n100 | Job4\\n101 | Job5\\n110 | Job6\\n111 | Job7\\n1000 | Job8\\n1001 | Job9\\n1010 | Job10\\n1011 | Job11\\n1100 | Job12\\n1101 | Job13\\n1110 | Job14\\n1111 | Job15\\n10000 | Job16\\n10001 | Job17\\n10010 | Job18\"",
"end",
"end"
]
| Tests that the block format for defining registers works | [
"Tests",
"that",
"the",
"block",
"format",
"for",
"defining",
"registers",
"works"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/c99/nvm.rb#L68-L108 | train |
Origen-SDK/origen | lib/origen/registers.rb | Origen.Registers.add_reg | def add_reg(id, address, size = nil, bit_info = {}, &_block)
if address.is_a?(Hash)
fail 'add_reg requires the address to be supplied as the 2nd argument, e.g. add_reg :my_reg, 0x1000'
end
size, bit_info = nil, size if size.is_a?(Hash)
size ||= bit_info.delete(:size) || 32
description = bit_info.delete(:description)
local_vars = {}
Reg::REG_LEVEL_ATTRIBUTES.each do |attribute, meta|
aliases = [attribute[1..-1].to_sym]
aliases += meta[:aliases] if meta[:aliases]
aliases.each { |_a| local_vars[attribute] = bit_info.delete(_a) if bit_info.key?(_a) }
end
local_vars[:_reset] ||= :memory if local_vars[:_memory]
@min_reg_address ||= address
@max_reg_address ||= address
# Must set an initial value, otherwise max_address_reg_size will be nil if a sub_block contains only
# a single register.
@max_address_reg_size = size unless @max_address_reg_size
@min_reg_address = address if address < @min_reg_address
if address > @max_reg_address
@max_address_reg_size = size
@max_reg_address = address
end
@reg_define_file ||= define_file(caller[0])
if block_given?
@new_reg_attrs = { meta: bit_info }
yield self
bit_info = @new_reg_attrs
else
# If no block given then init with all writable bits unless bit_info has
# been supplied
unless bit_info.any? { |k, v| v.is_a?(Hash) && v[:pos] }
bit_info = { d: { pos: 0, bits: size }.merge(bit_info) }
end
end
if _registers[id] && Origen.config.strict_errors
puts ''
puts "Add register error, you have already added a register named #{id} to #{self.class}"
puts ''
fail 'Duplicate register error!'
else
attributes = {
define_file: @reg_define_file,
address: address,
size: size,
bit_info: bit_info,
description: description
}
Reg::REG_LEVEL_ATTRIBUTES.each do |attribute, _meta|
attributes[attribute] = local_vars[attribute]
end
_registers[id] = Placeholder.new(self, id, attributes)
end
@reg_define_file = nil
end | ruby | def add_reg(id, address, size = nil, bit_info = {}, &_block)
if address.is_a?(Hash)
fail 'add_reg requires the address to be supplied as the 2nd argument, e.g. add_reg :my_reg, 0x1000'
end
size, bit_info = nil, size if size.is_a?(Hash)
size ||= bit_info.delete(:size) || 32
description = bit_info.delete(:description)
local_vars = {}
Reg::REG_LEVEL_ATTRIBUTES.each do |attribute, meta|
aliases = [attribute[1..-1].to_sym]
aliases += meta[:aliases] if meta[:aliases]
aliases.each { |_a| local_vars[attribute] = bit_info.delete(_a) if bit_info.key?(_a) }
end
local_vars[:_reset] ||= :memory if local_vars[:_memory]
@min_reg_address ||= address
@max_reg_address ||= address
# Must set an initial value, otherwise max_address_reg_size will be nil if a sub_block contains only
# a single register.
@max_address_reg_size = size unless @max_address_reg_size
@min_reg_address = address if address < @min_reg_address
if address > @max_reg_address
@max_address_reg_size = size
@max_reg_address = address
end
@reg_define_file ||= define_file(caller[0])
if block_given?
@new_reg_attrs = { meta: bit_info }
yield self
bit_info = @new_reg_attrs
else
# If no block given then init with all writable bits unless bit_info has
# been supplied
unless bit_info.any? { |k, v| v.is_a?(Hash) && v[:pos] }
bit_info = { d: { pos: 0, bits: size }.merge(bit_info) }
end
end
if _registers[id] && Origen.config.strict_errors
puts ''
puts "Add register error, you have already added a register named #{id} to #{self.class}"
puts ''
fail 'Duplicate register error!'
else
attributes = {
define_file: @reg_define_file,
address: address,
size: size,
bit_info: bit_info,
description: description
}
Reg::REG_LEVEL_ATTRIBUTES.each do |attribute, _meta|
attributes[attribute] = local_vars[attribute]
end
_registers[id] = Placeholder.new(self, id, attributes)
end
@reg_define_file = nil
end | [
"def",
"add_reg",
"(",
"id",
",",
"address",
",",
"size",
"=",
"nil",
",",
"bit_info",
"=",
"{",
"}",
",",
"&",
"_block",
")",
"if",
"address",
".",
"is_a?",
"(",
"Hash",
")",
"fail",
"'add_reg requires the address to be supplied as the 2nd argument, e.g. add_reg :my_reg, 0x1000'",
"end",
"size",
",",
"bit_info",
"=",
"nil",
",",
"size",
"if",
"size",
".",
"is_a?",
"(",
"Hash",
")",
"size",
"||=",
"bit_info",
".",
"delete",
"(",
":size",
")",
"||",
"32",
"description",
"=",
"bit_info",
".",
"delete",
"(",
":description",
")",
"local_vars",
"=",
"{",
"}",
"Reg",
"::",
"REG_LEVEL_ATTRIBUTES",
".",
"each",
"do",
"|",
"attribute",
",",
"meta",
"|",
"aliases",
"=",
"[",
"attribute",
"[",
"1",
"..",
"-",
"1",
"]",
".",
"to_sym",
"]",
"aliases",
"+=",
"meta",
"[",
":aliases",
"]",
"if",
"meta",
"[",
":aliases",
"]",
"aliases",
".",
"each",
"{",
"|",
"_a",
"|",
"local_vars",
"[",
"attribute",
"]",
"=",
"bit_info",
".",
"delete",
"(",
"_a",
")",
"if",
"bit_info",
".",
"key?",
"(",
"_a",
")",
"}",
"end",
"local_vars",
"[",
":_reset",
"]",
"||=",
":memory",
"if",
"local_vars",
"[",
":_memory",
"]",
"@min_reg_address",
"||=",
"address",
"@max_reg_address",
"||=",
"address",
"@max_address_reg_size",
"=",
"size",
"unless",
"@max_address_reg_size",
"@min_reg_address",
"=",
"address",
"if",
"address",
"<",
"@min_reg_address",
"if",
"address",
">",
"@max_reg_address",
"@max_address_reg_size",
"=",
"size",
"@max_reg_address",
"=",
"address",
"end",
"@reg_define_file",
"||=",
"define_file",
"(",
"caller",
"[",
"0",
"]",
")",
"if",
"block_given?",
"@new_reg_attrs",
"=",
"{",
"meta",
":",
"bit_info",
"}",
"yield",
"self",
"bit_info",
"=",
"@new_reg_attrs",
"else",
"unless",
"bit_info",
".",
"any?",
"{",
"|",
"k",
",",
"v",
"|",
"v",
".",
"is_a?",
"(",
"Hash",
")",
"&&",
"v",
"[",
":pos",
"]",
"}",
"bit_info",
"=",
"{",
"d",
":",
"{",
"pos",
":",
"0",
",",
"bits",
":",
"size",
"}",
".",
"merge",
"(",
"bit_info",
")",
"}",
"end",
"end",
"if",
"_registers",
"[",
"id",
"]",
"&&",
"Origen",
".",
"config",
".",
"strict_errors",
"puts",
"''",
"puts",
"\"Add register error, you have already added a register named #{id} to #{self.class}\"",
"puts",
"''",
"fail",
"'Duplicate register error!'",
"else",
"attributes",
"=",
"{",
"define_file",
":",
"@reg_define_file",
",",
"address",
":",
"address",
",",
"size",
":",
"size",
",",
"bit_info",
":",
"bit_info",
",",
"description",
":",
"description",
"}",
"Reg",
"::",
"REG_LEVEL_ATTRIBUTES",
".",
"each",
"do",
"|",
"attribute",
",",
"_meta",
"|",
"attributes",
"[",
"attribute",
"]",
"=",
"local_vars",
"[",
"attribute",
"]",
"end",
"_registers",
"[",
"id",
"]",
"=",
"Placeholder",
".",
"new",
"(",
"self",
",",
"id",
",",
"attributes",
")",
"end",
"@reg_define_file",
"=",
"nil",
"end"
]
| Add a register.
When adding a register you must supply a name, an address, size in bits, and bit definitions,
any bits that are not declared will be filled with dummy bit objects that are
not writable and will read back as 0.
@example
Name Address Size Bit Definitions
add_reg :control, 0x00, 16 :mode => { :pos => 8, :bits => 8 },
# Leaving out bits does 1 by default
:launch => { :pos => 6 },
# The default reset state is 0, specify an alternative..
:status => { :pos => 4, :bits => 2, :res => 0b11 },
:fail => { :pos => 2 },
:done => { :pos => 0 }
Can be called on any object to add a register to it | [
"Add",
"a",
"register",
".",
"When",
"adding",
"a",
"register",
"you",
"must",
"supply",
"a",
"name",
"an",
"address",
"size",
"in",
"bits",
"and",
"bit",
"definitions",
"any",
"bits",
"that",
"are",
"not",
"declared",
"will",
"be",
"filled",
"with",
"dummy",
"bit",
"objects",
"that",
"are",
"not",
"writable",
"and",
"will",
"read",
"back",
"as",
"0",
"."
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/registers.rb#L310-L369 | train |
Origen-SDK/origen | lib/origen/registers.rb | Origen.Registers.bit | def bit(index, name, attrs = {})
if index.is_a?(Range)
msb = index.first
lsb = index.last
msb, lsb = lsb, msb if lsb > msb
pos = lsb
bits = (msb - lsb).abs + 1
elsif index.is_a?(Numeric)
pos = index
bits = 1
else
fail 'No valid index supplied when defining a register bit!'
end
# Traynor, this could be more elegant
# its just a dirty way to make the value of the
# key in @new_reg_atts hash array (ie name) tie to
# a value that is an array of hashes describing
# data for each scrambled bit
attrs = attrs.merge(pos: pos, bits: bits)
temparray = []
if @new_reg_attrs[name].nil?
@new_reg_attrs[name] = attrs
else
if @new_reg_attrs[name].is_a? Hash
temparray = temparray.push(@new_reg_attrs[name])
else
temparray = @new_reg_attrs[name]
end
temparray = temparray.push(attrs)
# added the sort so that the order the registers bits is described is not important
@new_reg_attrs[name] = temparray.sort { |a, b| b[:pos] <=> a[:pos] }
end
end | ruby | def bit(index, name, attrs = {})
if index.is_a?(Range)
msb = index.first
lsb = index.last
msb, lsb = lsb, msb if lsb > msb
pos = lsb
bits = (msb - lsb).abs + 1
elsif index.is_a?(Numeric)
pos = index
bits = 1
else
fail 'No valid index supplied when defining a register bit!'
end
# Traynor, this could be more elegant
# its just a dirty way to make the value of the
# key in @new_reg_atts hash array (ie name) tie to
# a value that is an array of hashes describing
# data for each scrambled bit
attrs = attrs.merge(pos: pos, bits: bits)
temparray = []
if @new_reg_attrs[name].nil?
@new_reg_attrs[name] = attrs
else
if @new_reg_attrs[name].is_a? Hash
temparray = temparray.push(@new_reg_attrs[name])
else
temparray = @new_reg_attrs[name]
end
temparray = temparray.push(attrs)
# added the sort so that the order the registers bits is described is not important
@new_reg_attrs[name] = temparray.sort { |a, b| b[:pos] <=> a[:pos] }
end
end | [
"def",
"bit",
"(",
"index",
",",
"name",
",",
"attrs",
"=",
"{",
"}",
")",
"if",
"index",
".",
"is_a?",
"(",
"Range",
")",
"msb",
"=",
"index",
".",
"first",
"lsb",
"=",
"index",
".",
"last",
"msb",
",",
"lsb",
"=",
"lsb",
",",
"msb",
"if",
"lsb",
">",
"msb",
"pos",
"=",
"lsb",
"bits",
"=",
"(",
"msb",
"-",
"lsb",
")",
".",
"abs",
"+",
"1",
"elsif",
"index",
".",
"is_a?",
"(",
"Numeric",
")",
"pos",
"=",
"index",
"bits",
"=",
"1",
"else",
"fail",
"'No valid index supplied when defining a register bit!'",
"end",
"attrs",
"=",
"attrs",
".",
"merge",
"(",
"pos",
":",
"pos",
",",
"bits",
":",
"bits",
")",
"temparray",
"=",
"[",
"]",
"if",
"@new_reg_attrs",
"[",
"name",
"]",
".",
"nil?",
"@new_reg_attrs",
"[",
"name",
"]",
"=",
"attrs",
"else",
"if",
"@new_reg_attrs",
"[",
"name",
"]",
".",
"is_a?",
"Hash",
"temparray",
"=",
"temparray",
".",
"push",
"(",
"@new_reg_attrs",
"[",
"name",
"]",
")",
"else",
"temparray",
"=",
"@new_reg_attrs",
"[",
"name",
"]",
"end",
"temparray",
"=",
"temparray",
".",
"push",
"(",
"attrs",
")",
"@new_reg_attrs",
"[",
"name",
"]",
"=",
"temparray",
".",
"sort",
"{",
"|",
"a",
",",
"b",
"|",
"b",
"[",
":pos",
"]",
"<=>",
"a",
"[",
":pos",
"]",
"}",
"end",
"end"
]
| Called within an add_reg block to define bits | [
"Called",
"within",
"an",
"add_reg",
"block",
"to",
"define",
"bits"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/registers.rb#L387-L421 | train |
Origen-SDK/origen | lib/origen/registers.rb | Origen.Registers.default_reg_metadata | def default_reg_metadata
Origen::Registers.reg_metadata[self.class] ||= {}
if block_given?
collector = Origen::Utility::Collector.new
yield collector
Origen::Registers.reg_metadata[self.class].merge!(collector.to_h)
end
Origen::Registers.reg_metadata[self.class]
end | ruby | def default_reg_metadata
Origen::Registers.reg_metadata[self.class] ||= {}
if block_given?
collector = Origen::Utility::Collector.new
yield collector
Origen::Registers.reg_metadata[self.class].merge!(collector.to_h)
end
Origen::Registers.reg_metadata[self.class]
end | [
"def",
"default_reg_metadata",
"Origen",
"::",
"Registers",
".",
"reg_metadata",
"[",
"self",
".",
"class",
"]",
"||=",
"{",
"}",
"if",
"block_given?",
"collector",
"=",
"Origen",
"::",
"Utility",
"::",
"Collector",
".",
"new",
"yield",
"collector",
"Origen",
"::",
"Registers",
".",
"reg_metadata",
"[",
"self",
".",
"class",
"]",
".",
"merge!",
"(",
"collector",
".",
"to_h",
")",
"end",
"Origen",
"::",
"Registers",
".",
"reg_metadata",
"[",
"self",
".",
"class",
"]",
"end"
]
| Can be called to add app specific meta data that is isolated to all registers
defined within a given class | [
"Can",
"be",
"called",
"to",
"add",
"app",
"specific",
"meta",
"data",
"that",
"is",
"isolated",
"to",
"all",
"registers",
"defined",
"within",
"a",
"given",
"class"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/registers.rb#L427-L435 | train |
Origen-SDK/origen | lib/origen/registers.rb | Origen.Registers.has_reg? | def has_reg?(name, params = {})
params = {
test_for_true_false: true
}.update(params)
if params.key?(:enabled_features) || params.key?(:enabled_feature)
return !!get_registers(params).include?(name)
else
params[:enabled_features] = :default
return !!get_registers(params).include?(name)
end
end | ruby | def has_reg?(name, params = {})
params = {
test_for_true_false: true
}.update(params)
if params.key?(:enabled_features) || params.key?(:enabled_feature)
return !!get_registers(params).include?(name)
else
params[:enabled_features] = :default
return !!get_registers(params).include?(name)
end
end | [
"def",
"has_reg?",
"(",
"name",
",",
"params",
"=",
"{",
"}",
")",
"params",
"=",
"{",
"test_for_true_false",
":",
"true",
"}",
".",
"update",
"(",
"params",
")",
"if",
"params",
".",
"key?",
"(",
":enabled_features",
")",
"||",
"params",
".",
"key?",
"(",
":enabled_feature",
")",
"return",
"!",
"!",
"get_registers",
"(",
"params",
")",
".",
"include?",
"(",
"name",
")",
"else",
"params",
"[",
":enabled_features",
"]",
"=",
":default",
"return",
"!",
"!",
"get_registers",
"(",
"params",
")",
".",
"include?",
"(",
"name",
")",
"end",
"end"
]
| Returns true if the object contains a register matching the given name | [
"Returns",
"true",
"if",
"the",
"object",
"contains",
"a",
"register",
"matching",
"the",
"given",
"name"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/registers.rb#L491-L501 | train |
Origen-SDK/origen | lib/origen/registers.rb | Origen.Registers.reg | def reg(*args, &block)
if block_given? || (args[1].is_a?(Integer) && !try(:_initialized?))
@reg_define_file = define_file(caller[0])
add_reg(*args, &block)
else
# Example use cases:
# reg(:reg2)
# reg(:name => :reg2)
# reg('/reg2/')
if !args.empty? && args.size == 1 && (args[0].class != Hash || (args[0].key?(:name) && args[0].size == 1))
if args[0].class == Hash
name = args[0][:name]
else name = args.first
end
if has_reg(name)
return _registers[name]
elsif name =~ /\/(.+)\//
regex = Regexp.last_match(1)
return match_registers(regex)
else
if Origen.config.strict_errors
puts ''
if regs.empty?
puts "#{self.class} does not have a register named #{name} or it is not enabled."
else
puts "#{self.class} does not have a register named #{name} or it is not enabled."
puts 'You may need to add it. This could also be a typo, these are the valid register names:'
puts regs.keys
end
puts ''
fail 'Missing register error!'
end
end
# Example use cases:
# reg(:enabled_features => :all)
# reg(:name => :reg2, enabled_features => :all)
# reg(:name => :reg2, enabled_features => :fac)
elsif !args.empty? && args.size == 1 && args[0].class == Hash
params = args[0]
# Example use case:
# reg(:name => :reg2, :enabled_features => :all)
if (params.key?(:enabled_features) || params.key?(:enabled_feature)) && params.key?(:name)
name = params[:name]
if has_reg(name, params)
_registers[name]
else
reg_missing_error(params)
end
# Example use case:
# reg(:enabled_features =>[:fac, fac2])
elsif params.size == 1 && params.key?(:enabled_features)
return get_registers(enabled_features: params[:enabled_features])
end
# Example use case:
# reg(:reg2, :enabled_features => :all)
# reg(:reg2, :enabled_features => :default)
# reg(:reg2, :enabled_features => :fac)
elsif !args.empty? && args.size == 2
name = args[0]
params = args[1]
name, params = params, name if name.class == Hash
if has_reg(name, params)
_registers[name]
else
reg_missing_error(params)
end
elsif args.empty?
if _registers.empty?
return _registers
else
return get_registers(enabled_features: :default)
end
else
if Origen.config.strict_errors
fail 'Invalid call to reg method or invalid arguments specified'
end
end
end
end | ruby | def reg(*args, &block)
if block_given? || (args[1].is_a?(Integer) && !try(:_initialized?))
@reg_define_file = define_file(caller[0])
add_reg(*args, &block)
else
# Example use cases:
# reg(:reg2)
# reg(:name => :reg2)
# reg('/reg2/')
if !args.empty? && args.size == 1 && (args[0].class != Hash || (args[0].key?(:name) && args[0].size == 1))
if args[0].class == Hash
name = args[0][:name]
else name = args.first
end
if has_reg(name)
return _registers[name]
elsif name =~ /\/(.+)\//
regex = Regexp.last_match(1)
return match_registers(regex)
else
if Origen.config.strict_errors
puts ''
if regs.empty?
puts "#{self.class} does not have a register named #{name} or it is not enabled."
else
puts "#{self.class} does not have a register named #{name} or it is not enabled."
puts 'You may need to add it. This could also be a typo, these are the valid register names:'
puts regs.keys
end
puts ''
fail 'Missing register error!'
end
end
# Example use cases:
# reg(:enabled_features => :all)
# reg(:name => :reg2, enabled_features => :all)
# reg(:name => :reg2, enabled_features => :fac)
elsif !args.empty? && args.size == 1 && args[0].class == Hash
params = args[0]
# Example use case:
# reg(:name => :reg2, :enabled_features => :all)
if (params.key?(:enabled_features) || params.key?(:enabled_feature)) && params.key?(:name)
name = params[:name]
if has_reg(name, params)
_registers[name]
else
reg_missing_error(params)
end
# Example use case:
# reg(:enabled_features =>[:fac, fac2])
elsif params.size == 1 && params.key?(:enabled_features)
return get_registers(enabled_features: params[:enabled_features])
end
# Example use case:
# reg(:reg2, :enabled_features => :all)
# reg(:reg2, :enabled_features => :default)
# reg(:reg2, :enabled_features => :fac)
elsif !args.empty? && args.size == 2
name = args[0]
params = args[1]
name, params = params, name if name.class == Hash
if has_reg(name, params)
_registers[name]
else
reg_missing_error(params)
end
elsif args.empty?
if _registers.empty?
return _registers
else
return get_registers(enabled_features: :default)
end
else
if Origen.config.strict_errors
fail 'Invalid call to reg method or invalid arguments specified'
end
end
end
end | [
"def",
"reg",
"(",
"*",
"args",
",",
"&",
"block",
")",
"if",
"block_given?",
"||",
"(",
"args",
"[",
"1",
"]",
".",
"is_a?",
"(",
"Integer",
")",
"&&",
"!",
"try",
"(",
":_initialized?",
")",
")",
"@reg_define_file",
"=",
"define_file",
"(",
"caller",
"[",
"0",
"]",
")",
"add_reg",
"(",
"*",
"args",
",",
"&",
"block",
")",
"else",
"if",
"!",
"args",
".",
"empty?",
"&&",
"args",
".",
"size",
"==",
"1",
"&&",
"(",
"args",
"[",
"0",
"]",
".",
"class",
"!=",
"Hash",
"||",
"(",
"args",
"[",
"0",
"]",
".",
"key?",
"(",
":name",
")",
"&&",
"args",
"[",
"0",
"]",
".",
"size",
"==",
"1",
")",
")",
"if",
"args",
"[",
"0",
"]",
".",
"class",
"==",
"Hash",
"name",
"=",
"args",
"[",
"0",
"]",
"[",
":name",
"]",
"else",
"name",
"=",
"args",
".",
"first",
"end",
"if",
"has_reg",
"(",
"name",
")",
"return",
"_registers",
"[",
"name",
"]",
"elsif",
"name",
"=~",
"/",
"\\/",
"\\/",
"/",
"regex",
"=",
"Regexp",
".",
"last_match",
"(",
"1",
")",
"return",
"match_registers",
"(",
"regex",
")",
"else",
"if",
"Origen",
".",
"config",
".",
"strict_errors",
"puts",
"''",
"if",
"regs",
".",
"empty?",
"puts",
"\"#{self.class} does not have a register named #{name} or it is not enabled.\"",
"else",
"puts",
"\"#{self.class} does not have a register named #{name} or it is not enabled.\"",
"puts",
"'You may need to add it. This could also be a typo, these are the valid register names:'",
"puts",
"regs",
".",
"keys",
"end",
"puts",
"''",
"fail",
"'Missing register error!'",
"end",
"end",
"elsif",
"!",
"args",
".",
"empty?",
"&&",
"args",
".",
"size",
"==",
"1",
"&&",
"args",
"[",
"0",
"]",
".",
"class",
"==",
"Hash",
"params",
"=",
"args",
"[",
"0",
"]",
"if",
"(",
"params",
".",
"key?",
"(",
":enabled_features",
")",
"||",
"params",
".",
"key?",
"(",
":enabled_feature",
")",
")",
"&&",
"params",
".",
"key?",
"(",
":name",
")",
"name",
"=",
"params",
"[",
":name",
"]",
"if",
"has_reg",
"(",
"name",
",",
"params",
")",
"_registers",
"[",
"name",
"]",
"else",
"reg_missing_error",
"(",
"params",
")",
"end",
"elsif",
"params",
".",
"size",
"==",
"1",
"&&",
"params",
".",
"key?",
"(",
":enabled_features",
")",
"return",
"get_registers",
"(",
"enabled_features",
":",
"params",
"[",
":enabled_features",
"]",
")",
"end",
"elsif",
"!",
"args",
".",
"empty?",
"&&",
"args",
".",
"size",
"==",
"2",
"name",
"=",
"args",
"[",
"0",
"]",
"params",
"=",
"args",
"[",
"1",
"]",
"name",
",",
"params",
"=",
"params",
",",
"name",
"if",
"name",
".",
"class",
"==",
"Hash",
"if",
"has_reg",
"(",
"name",
",",
"params",
")",
"_registers",
"[",
"name",
"]",
"else",
"reg_missing_error",
"(",
"params",
")",
"end",
"elsif",
"args",
".",
"empty?",
"if",
"_registers",
".",
"empty?",
"return",
"_registers",
"else",
"return",
"get_registers",
"(",
"enabled_features",
":",
":default",
")",
"end",
"else",
"if",
"Origen",
".",
"config",
".",
"strict_errors",
"fail",
"'Invalid call to reg method or invalid arguments specified'",
"end",
"end",
"end",
"end"
]
| Returns
-the register object matching the given name
-or a hash of all registes matching a given regular expression
-or a hash of all registers, associated with a feature, if no name is specified.
Can also be used to define a new register if a block is supplied in which case
it is equivalent to calling add_reg with a block. | [
"Returns",
"-",
"the",
"register",
"object",
"matching",
"the",
"given",
"name",
"-",
"or",
"a",
"hash",
"of",
"all",
"registes",
"matching",
"a",
"given",
"regular",
"expression",
"-",
"or",
"a",
"hash",
"of",
"all",
"registers",
"associated",
"with",
"a",
"feature",
"if",
"no",
"name",
"is",
"specified",
"."
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/registers.rb#L511-L591 | train |
Origen-SDK/origen | lib/origen/regression_manager.rb | Origen.RegressionManager.prepare_targets | def prepare_targets(options)
targets = [options[:target], options[:targets]].flatten.compact
if targets.empty?
puts 'You must supply the targets you are going to run in the options'
puts 'passed to regression_manager.run.'
fail
end
Origen.target.loop(options) { |_options| }
targets
end | ruby | def prepare_targets(options)
targets = [options[:target], options[:targets]].flatten.compact
if targets.empty?
puts 'You must supply the targets you are going to run in the options'
puts 'passed to regression_manager.run.'
fail
end
Origen.target.loop(options) { |_options| }
targets
end | [
"def",
"prepare_targets",
"(",
"options",
")",
"targets",
"=",
"[",
"options",
"[",
":target",
"]",
",",
"options",
"[",
":targets",
"]",
"]",
".",
"flatten",
".",
"compact",
"if",
"targets",
".",
"empty?",
"puts",
"'You must supply the targets you are going to run in the options'",
"puts",
"'passed to regression_manager.run.'",
"fail",
"end",
"Origen",
".",
"target",
".",
"loop",
"(",
"options",
")",
"{",
"|",
"_options",
"|",
"}",
"targets",
"end"
]
| Cycle through all targets in the upcoming run to ensure
that all output directories exist | [
"Cycle",
"through",
"all",
"targets",
"in",
"the",
"upcoming",
"run",
"to",
"ensure",
"that",
"all",
"output",
"directories",
"exist"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/regression_manager.rb#L160-L169 | train |
Origen-SDK/origen | lib/origen/regression_manager.rb | Origen.RegressionManager.regression_command_file | def regression_command_file
first_call = caller.find { |line| line =~ /regression_manager.rb.*run/ }
app_caller_line = caller[caller.index(first_call) + 1]
app_caller_line =~ /(.*\.rb)/
path = Pathname.new(Regexp.last_match[1])
end | ruby | def regression_command_file
first_call = caller.find { |line| line =~ /regression_manager.rb.*run/ }
app_caller_line = caller[caller.index(first_call) + 1]
app_caller_line =~ /(.*\.rb)/
path = Pathname.new(Regexp.last_match[1])
end | [
"def",
"regression_command_file",
"first_call",
"=",
"caller",
".",
"find",
"{",
"|",
"line",
"|",
"line",
"=~",
"/",
"/",
"}",
"app_caller_line",
"=",
"caller",
"[",
"caller",
".",
"index",
"(",
"first_call",
")",
"+",
"1",
"]",
"app_caller_line",
"=~",
"/",
"\\.",
"/",
"path",
"=",
"Pathname",
".",
"new",
"(",
"Regexp",
".",
"last_match",
"[",
"1",
"]",
")",
"end"
]
| Returns a full path to the regression command file within the local application | [
"Returns",
"a",
"full",
"path",
"to",
"the",
"regression",
"command",
"file",
"within",
"the",
"local",
"application"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/regression_manager.rb#L254-L259 | train |
Origen-SDK/origen | lib/origen/componentable.rb | Origen.Componentable._add | def _add(name, options = {}, &block)
# Add the name and parent to the options if they aren't already given
# If the parent isn't available on the includer class, it will remain nil.
options = {
name: name,
parent: parent
}.merge(options)
options = Origen::Utility.collector(hash: options, merge_method: :keep_hash, &block).to_h
# Instantiate the class. This will place the object in the @_componentable_container at the indicated name
_instantiate_class(name, options)
# Create an accessor for the new item, if indicated to do so.
_push_accessor(name, options)
@_componentable_container[name]
end | ruby | def _add(name, options = {}, &block)
# Add the name and parent to the options if they aren't already given
# If the parent isn't available on the includer class, it will remain nil.
options = {
name: name,
parent: parent
}.merge(options)
options = Origen::Utility.collector(hash: options, merge_method: :keep_hash, &block).to_h
# Instantiate the class. This will place the object in the @_componentable_container at the indicated name
_instantiate_class(name, options)
# Create an accessor for the new item, if indicated to do so.
_push_accessor(name, options)
@_componentable_container[name]
end | [
"def",
"_add",
"(",
"name",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"options",
"=",
"{",
"name",
":",
"name",
",",
"parent",
":",
"parent",
"}",
".",
"merge",
"(",
"options",
")",
"options",
"=",
"Origen",
"::",
"Utility",
".",
"collector",
"(",
"hash",
":",
"options",
",",
"merge_method",
":",
":keep_hash",
",",
"&",
"block",
")",
".",
"to_h",
"_instantiate_class",
"(",
"name",
",",
"options",
")",
"_push_accessor",
"(",
"name",
",",
"options",
")",
"@_componentable_container",
"[",
"name",
"]",
"end"
]
| Adds a new item to the componentable container.
@note All options added will be passed to the subclasses instantiation.
@note The options is only valid for the stock :add method.
@note Any extra options provided are still passed to the subclasses instantiation.
@param name [Symbol] Name to reference the new component object.
@param options [Hash] Customizations for both the add method and for the class's instantiation.
@option options [Class, String] class_name The class to instaniate the component at :name as.
@return [ComponentableObject] The instantiated class at :name
@raise [Origen::Componentable::NameInUseError] Raised if :name already points to a component. | [
"Adds",
"a",
"new",
"item",
"to",
"the",
"componentable",
"container",
"."
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/componentable.rb#L430-L447 | train |
Origen-SDK/origen | lib/origen/componentable.rb | Origen.Componentable.move | def move(to_move, new_name, options = {})
overwrite = options[:overwrite] || false
if @_componentable_container.key?(new_name) && !overwrite
# The move location already exists and override was not specified
fail Origen::Componentable::NameInUseError, "#{_singleton_name} name :#{new_name} is already in use"
end
unless @_componentable_container.key?(to_move)
# The to_move name doesn't exist
fail Origen::Componentable::NameDoesNotExistError, "#{_singleton_name} name :#{to_move} does not exist"
end
to_move_object = @_componentable_container.delete(to_move)
@_componentable_container[new_name] = to_move_object
end | ruby | def move(to_move, new_name, options = {})
overwrite = options[:overwrite] || false
if @_componentable_container.key?(new_name) && !overwrite
# The move location already exists and override was not specified
fail Origen::Componentable::NameInUseError, "#{_singleton_name} name :#{new_name} is already in use"
end
unless @_componentable_container.key?(to_move)
# The to_move name doesn't exist
fail Origen::Componentable::NameDoesNotExistError, "#{_singleton_name} name :#{to_move} does not exist"
end
to_move_object = @_componentable_container.delete(to_move)
@_componentable_container[new_name] = to_move_object
end | [
"def",
"move",
"(",
"to_move",
",",
"new_name",
",",
"options",
"=",
"{",
"}",
")",
"overwrite",
"=",
"options",
"[",
":overwrite",
"]",
"||",
"false",
"if",
"@_componentable_container",
".",
"key?",
"(",
"new_name",
")",
"&&",
"!",
"overwrite",
"fail",
"Origen",
"::",
"Componentable",
"::",
"NameInUseError",
",",
"\"#{_singleton_name} name :#{new_name} is already in use\"",
"end",
"unless",
"@_componentable_container",
".",
"key?",
"(",
"to_move",
")",
"fail",
"Origen",
"::",
"Componentable",
"::",
"NameDoesNotExistError",
",",
"\"#{_singleton_name} name :#{to_move} does not exist\"",
"end",
"to_move_object",
"=",
"@_componentable_container",
".",
"delete",
"(",
"to_move",
")",
"@_componentable_container",
"[",
"new_name",
"]",
"=",
"to_move_object",
"end"
]
| Moves a component object from one name to another.
@param to_move [Symbol] Component name to move elsewhere.
@param new_name [Symbol] New name to give to the component from :to_move.
@return [Symbol] The component moved.
@raise [Origen::Componentable::NameInUseError] Raised if :new_name is already in use and the :override option is not specified.
@raise [Origen::Componentable::NameDoesNotExistsError] Raised if :to_move name does not exists. | [
"Moves",
"a",
"component",
"object",
"from",
"one",
"name",
"to",
"another",
"."
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/componentable.rb#L556-L571 | train |
Origen-SDK/origen | lib/origen/componentable.rb | Origen.Componentable.delete | def delete(to_delete)
obj = delete!(to_delete)
fail Origen::Componentable::NameDoesNotExistError, "#{_singleton_name} name :#{to_delete} does not exist" if obj.nil?
obj
end | ruby | def delete(to_delete)
obj = delete!(to_delete)
fail Origen::Componentable::NameDoesNotExistError, "#{_singleton_name} name :#{to_delete} does not exist" if obj.nil?
obj
end | [
"def",
"delete",
"(",
"to_delete",
")",
"obj",
"=",
"delete!",
"(",
"to_delete",
")",
"fail",
"Origen",
"::",
"Componentable",
"::",
"NameDoesNotExistError",
",",
"\"#{_singleton_name} name :#{to_delete} does not exist\"",
"if",
"obj",
".",
"nil?",
"obj",
"end"
]
| Deletes a component from the componentable container
@param name [Symbol] Name of component to delete
@return [Hash(Symbol, <ComponentableItem>)] containing the name of the component deleted and its component.
@raise [Origen::Componentable::NameDoesNotExistsError] Raised if :to_copy name does not exists. | [
"Deletes",
"a",
"component",
"from",
"the",
"componentable",
"container"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/componentable.rb#L577-L581 | train |
Origen-SDK/origen | lib/origen/componentable.rb | Origen.Componentable.delete_all | def delete_all
# delete individual objects one by one, making sure to delete all accessors as well
returns = {}
@_componentable_container.each do |key, val|
delete!(key)
returns[key] = val
end
returns
end | ruby | def delete_all
# delete individual objects one by one, making sure to delete all accessors as well
returns = {}
@_componentable_container.each do |key, val|
delete!(key)
returns[key] = val
end
returns
end | [
"def",
"delete_all",
"returns",
"=",
"{",
"}",
"@_componentable_container",
".",
"each",
"do",
"|",
"key",
",",
"val",
"|",
"delete!",
"(",
"key",
")",
"returns",
"[",
"key",
"]",
"=",
"val",
"end",
"returns",
"end"
]
| Deletes all of the components in the container.
@return [Hash(Symbol, <ComponentableItem>)] Hash containing all of the deleted items. | [
"Deletes",
"all",
"of",
"the",
"components",
"in",
"the",
"container",
"."
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/componentable.rb#L602-L610 | train |
Origen-SDK/origen | lib/origen/sub_blocks.rb | Origen.SubBlocks.init_sub_blocks | def init_sub_blocks(*args)
options = args.find { |a| a.is_a?(Hash) }
@custom_attrs = (options ? options.dup : {}).with_indifferent_access
# Delete these keys which are either meta data added by Origen or are already covered by
# dedicated methods
%w(parent name base_address reg_base_address base).each do |key|
@custom_attrs.delete(key)
end
if options
# Using reg_base_address for storage to avoid class with the original Origen base
# address API, but will accept any of these
@reg_base_address = options.delete(:reg_base_address) ||
options.delete(:base_address) || options.delete(:base) || 0
if options[:_instance] # to be deprecated as part of multi-instance removal below
if @reg_base_address.is_a?(Array)
@reg_base_address = @reg_base_address[options[:_instance]]
elsif options[:base_address_step]
@reg_base_address = @reg_base_address + (options[:_instance] * options[:base_address_step])
end
end
@domain_names = [options.delete(:domain) || options.delete(:domains)].flatten.compact
@domain_specified = !@domain_names.empty?
@path = options.delete(:path)
@abs_path = options.delete(:abs_path) || options.delete(:absolute_path)
end
if is_a?(SubBlock)
options.each do |k, v|
send("#{k}=", v)
end
end
end | ruby | def init_sub_blocks(*args)
options = args.find { |a| a.is_a?(Hash) }
@custom_attrs = (options ? options.dup : {}).with_indifferent_access
# Delete these keys which are either meta data added by Origen or are already covered by
# dedicated methods
%w(parent name base_address reg_base_address base).each do |key|
@custom_attrs.delete(key)
end
if options
# Using reg_base_address for storage to avoid class with the original Origen base
# address API, but will accept any of these
@reg_base_address = options.delete(:reg_base_address) ||
options.delete(:base_address) || options.delete(:base) || 0
if options[:_instance] # to be deprecated as part of multi-instance removal below
if @reg_base_address.is_a?(Array)
@reg_base_address = @reg_base_address[options[:_instance]]
elsif options[:base_address_step]
@reg_base_address = @reg_base_address + (options[:_instance] * options[:base_address_step])
end
end
@domain_names = [options.delete(:domain) || options.delete(:domains)].flatten.compact
@domain_specified = !@domain_names.empty?
@path = options.delete(:path)
@abs_path = options.delete(:abs_path) || options.delete(:absolute_path)
end
if is_a?(SubBlock)
options.each do |k, v|
send("#{k}=", v)
end
end
end | [
"def",
"init_sub_blocks",
"(",
"*",
"args",
")",
"options",
"=",
"args",
".",
"find",
"{",
"|",
"a",
"|",
"a",
".",
"is_a?",
"(",
"Hash",
")",
"}",
"@custom_attrs",
"=",
"(",
"options",
"?",
"options",
".",
"dup",
":",
"{",
"}",
")",
".",
"with_indifferent_access",
"%w(",
"parent",
"name",
"base_address",
"reg_base_address",
"base",
")",
".",
"each",
"do",
"|",
"key",
"|",
"@custom_attrs",
".",
"delete",
"(",
"key",
")",
"end",
"if",
"options",
"@reg_base_address",
"=",
"options",
".",
"delete",
"(",
":reg_base_address",
")",
"||",
"options",
".",
"delete",
"(",
":base_address",
")",
"||",
"options",
".",
"delete",
"(",
":base",
")",
"||",
"0",
"if",
"options",
"[",
":_instance",
"]",
"if",
"@reg_base_address",
".",
"is_a?",
"(",
"Array",
")",
"@reg_base_address",
"=",
"@reg_base_address",
"[",
"options",
"[",
":_instance",
"]",
"]",
"elsif",
"options",
"[",
":base_address_step",
"]",
"@reg_base_address",
"=",
"@reg_base_address",
"+",
"(",
"options",
"[",
":_instance",
"]",
"*",
"options",
"[",
":base_address_step",
"]",
")",
"end",
"end",
"@domain_names",
"=",
"[",
"options",
".",
"delete",
"(",
":domain",
")",
"||",
"options",
".",
"delete",
"(",
":domains",
")",
"]",
".",
"flatten",
".",
"compact",
"@domain_specified",
"=",
"!",
"@domain_names",
".",
"empty?",
"@path",
"=",
"options",
".",
"delete",
"(",
":path",
")",
"@abs_path",
"=",
"options",
".",
"delete",
"(",
":abs_path",
")",
"||",
"options",
".",
"delete",
"(",
":absolute_path",
")",
"end",
"if",
"is_a?",
"(",
"SubBlock",
")",
"options",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"send",
"(",
"\"#{k}=\"",
",",
"v",
")",
"end",
"end",
"end"
]
| This will be called whenever an object that includes this module
is instantiated
@api private | [
"This",
"will",
"be",
"called",
"whenever",
"an",
"object",
"that",
"includes",
"this",
"module",
"is",
"instantiated"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/sub_blocks.rb#L7-L37 | train |
Origen-SDK/origen | lib/origen/sub_blocks.rb | Origen.SubBlocks.owns_registers? | def owns_registers?
if regs
regs.is_a?(Origen::Registers::RegCollection) && !regs.empty?
else
false
end
end | ruby | def owns_registers?
if regs
regs.is_a?(Origen::Registers::RegCollection) && !regs.empty?
else
false
end
end | [
"def",
"owns_registers?",
"if",
"regs",
"regs",
".",
"is_a?",
"(",
"Origen",
"::",
"Registers",
"::",
"RegCollection",
")",
"&&",
"!",
"regs",
".",
"empty?",
"else",
"false",
"end",
"end"
]
| Returns true if the given sub block owns at least one register | [
"Returns",
"true",
"if",
"the",
"given",
"sub",
"block",
"owns",
"at",
"least",
"one",
"register"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/sub_blocks.rb#L257-L263 | train |
Origen-SDK/origen | lib/origen/sub_blocks.rb | Origen.SubBlock.method_missing | def method_missing(method, *args, &block)
super
rescue NoMethodError
return regs(method) if self.has_reg?(method)
return ports(method) if self.has_port?(method)
if method.to_s =~ /=$/
define_singleton_method(method) do |val|
instance_variable_set("@#{method.to_s.sub('=', '')}", val)
end
else
define_singleton_method(method) do
instance_variable_get("@#{method}")
end
end
send(method, *args, &block)
end | ruby | def method_missing(method, *args, &block)
super
rescue NoMethodError
return regs(method) if self.has_reg?(method)
return ports(method) if self.has_port?(method)
if method.to_s =~ /=$/
define_singleton_method(method) do |val|
instance_variable_set("@#{method.to_s.sub('=', '')}", val)
end
else
define_singleton_method(method) do
instance_variable_get("@#{method}")
end
end
send(method, *args, &block)
end | [
"def",
"method_missing",
"(",
"method",
",",
"*",
"args",
",",
"&",
"block",
")",
"super",
"rescue",
"NoMethodError",
"return",
"regs",
"(",
"method",
")",
"if",
"self",
".",
"has_reg?",
"(",
"method",
")",
"return",
"ports",
"(",
"method",
")",
"if",
"self",
".",
"has_port?",
"(",
"method",
")",
"if",
"method",
".",
"to_s",
"=~",
"/",
"/",
"define_singleton_method",
"(",
"method",
")",
"do",
"|",
"val",
"|",
"instance_variable_set",
"(",
"\"@#{method.to_s.sub('=', '')}\"",
",",
"val",
")",
"end",
"else",
"define_singleton_method",
"(",
"method",
")",
"do",
"instance_variable_get",
"(",
"\"@#{method}\"",
")",
"end",
"end",
"send",
"(",
"method",
",",
"*",
"args",
",",
"&",
"block",
")",
"end"
]
| Used to create attribute accessors on the fly.
On first call of a missing method a method is generated to avoid the missing lookup
next time, this should be faster for repeated lookups of the same method, e.g. reg | [
"Used",
"to",
"create",
"attribute",
"accessors",
"on",
"the",
"fly",
"."
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/sub_blocks.rb#L509-L524 | train |
Origen-SDK/origen | lib/origen/specs.rb | Origen.Specs.documentation | def documentation(header_info, selection, applicable_devices, link)
_documentation
# Create a new documenation and place it in the 5-D hash
@_documentation[header_info[:section]][header_info[:subsection]][selection[:interface]][selection[:type]][selection[:sub_type]][selection[:mode]][selection[:audience]] = Documentation.new(header_info, selection, applicable_devices, link)
end | ruby | def documentation(header_info, selection, applicable_devices, link)
_documentation
# Create a new documenation and place it in the 5-D hash
@_documentation[header_info[:section]][header_info[:subsection]][selection[:interface]][selection[:type]][selection[:sub_type]][selection[:mode]][selection[:audience]] = Documentation.new(header_info, selection, applicable_devices, link)
end | [
"def",
"documentation",
"(",
"header_info",
",",
"selection",
",",
"applicable_devices",
",",
"link",
")",
"_documentation",
"@_documentation",
"[",
"header_info",
"[",
":section",
"]",
"]",
"[",
"header_info",
"[",
":subsection",
"]",
"]",
"[",
"selection",
"[",
":interface",
"]",
"]",
"[",
"selection",
"[",
":type",
"]",
"]",
"[",
"selection",
"[",
":sub_type",
"]",
"]",
"[",
"selection",
"[",
":mode",
"]",
"]",
"[",
"selection",
"[",
":audience",
"]",
"]",
"=",
"Documentation",
".",
"new",
"(",
"header_info",
",",
"selection",
",",
"applicable_devices",
",",
"link",
")",
"end"
]
| Adds a new documentation notion to the block | [
"Adds",
"a",
"new",
"documentation",
"notion",
"to",
"the",
"block"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/specs.rb#L137-L141 | train |
Origen-SDK/origen | lib/origen/specs.rb | Origen.Specs.spec_feature | def spec_feature(id, attrs, device, text, internal_comment)
# Welguisz: No idea why this is here, but keeping it here because it follows other blocks
_spec_features
# Create a new feature and place it in the features 2-D Hash
@_spec_features[id][device] = Spec_Features.new(id, attrs, device, text, internal_comment)
end | ruby | def spec_feature(id, attrs, device, text, internal_comment)
# Welguisz: No idea why this is here, but keeping it here because it follows other blocks
_spec_features
# Create a new feature and place it in the features 2-D Hash
@_spec_features[id][device] = Spec_Features.new(id, attrs, device, text, internal_comment)
end | [
"def",
"spec_feature",
"(",
"id",
",",
"attrs",
",",
"device",
",",
"text",
",",
"internal_comment",
")",
"_spec_features",
"@_spec_features",
"[",
"id",
"]",
"[",
"device",
"]",
"=",
"Spec_Features",
".",
"new",
"(",
"id",
",",
"attrs",
",",
"device",
",",
"text",
",",
"internal_comment",
")",
"end"
]
| Adds a new feature to the block | [
"Adds",
"a",
"new",
"feature",
"to",
"the",
"block"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/specs.rb#L144-L149 | train |
Origen-SDK/origen | lib/origen/specs.rb | Origen.Specs.notes | def notes(options = {})
# Create a default 2 item hash and update if options is supplied
options = {
id: nil,
type: nil
}.update(options)
return nil if @_notes.nil?
return nil if @_notes.empty?
# Empty 2-D Hash to be used for notes found based on id and type
notes_found = Hash.new do |h, k|
# h is the id portion of the hash
# k is the type portion of the hash
h[k] = {}
end
# Filter @notes based off of the id
filter_hash(@_notes, options[:id]).each do |id, hash|
# Filter hash based off of the type
filter_hash(hash, options[:type]).each do |type, note|
# Store the note into note_found
notes_found[id][type] = note
end
end
if notes_found.empty?
return nil
elsif notes_found.size == 1
notes_found.values.first.values.first
else
return notes_found
end
end | ruby | def notes(options = {})
# Create a default 2 item hash and update if options is supplied
options = {
id: nil,
type: nil
}.update(options)
return nil if @_notes.nil?
return nil if @_notes.empty?
# Empty 2-D Hash to be used for notes found based on id and type
notes_found = Hash.new do |h, k|
# h is the id portion of the hash
# k is the type portion of the hash
h[k] = {}
end
# Filter @notes based off of the id
filter_hash(@_notes, options[:id]).each do |id, hash|
# Filter hash based off of the type
filter_hash(hash, options[:type]).each do |type, note|
# Store the note into note_found
notes_found[id][type] = note
end
end
if notes_found.empty?
return nil
elsif notes_found.size == 1
notes_found.values.first.values.first
else
return notes_found
end
end | [
"def",
"notes",
"(",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"{",
"id",
":",
"nil",
",",
"type",
":",
"nil",
"}",
".",
"update",
"(",
"options",
")",
"return",
"nil",
"if",
"@_notes",
".",
"nil?",
"return",
"nil",
"if",
"@_notes",
".",
"empty?",
"notes_found",
"=",
"Hash",
".",
"new",
"do",
"|",
"h",
",",
"k",
"|",
"h",
"[",
"k",
"]",
"=",
"{",
"}",
"end",
"filter_hash",
"(",
"@_notes",
",",
"options",
"[",
":id",
"]",
")",
".",
"each",
"do",
"|",
"id",
",",
"hash",
"|",
"filter_hash",
"(",
"hash",
",",
"options",
"[",
":type",
"]",
")",
".",
"each",
"do",
"|",
"type",
",",
"note",
"|",
"notes_found",
"[",
"id",
"]",
"[",
"type",
"]",
"=",
"note",
"end",
"end",
"if",
"notes_found",
".",
"empty?",
"return",
"nil",
"elsif",
"notes_found",
".",
"size",
"==",
"1",
"notes_found",
".",
"values",
".",
"first",
".",
"values",
".",
"first",
"else",
"return",
"notes_found",
"end",
"end"
]
| Returns a Note object from the notes hash | [
"Returns",
"a",
"Note",
"object",
"from",
"the",
"notes",
"hash"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/specs.rb#L223-L252 | train |
Origen-SDK/origen | lib/origen/specs.rb | Origen.Specs.specs_to_table_string | def specs_to_table_string(specs_to_be_shown)
whitespace_padding = 3
table = []
attrs_to_be_shown = {
name: SpecTableAttr.new('Name', true, 'Name'.length + whitespace_padding),
symbol: SpecTableAttr.new('Symbol', false, 'Symbol'.length + whitespace_padding),
mode: SpecTableAttr.new('Mode', true, 'Mode'.length + whitespace_padding),
type: SpecTableAttr.new('Type', true, 'Type'.length + whitespace_padding),
sub_type: SpecTableAttr.new('Sub-Type', false, 'Sub-Type'.length + whitespace_padding),
# spec SpecTableAttribute :description is called parameter in the spec table output to match historical docs
description: SpecTableAttr.new('Parameter', false, 'Parameter'.length + whitespace_padding),
min: SpecTableAttr.new('Min', false, 'Min'.length + whitespace_padding),
typ: SpecTableAttr.new('Typ', false, 'Typ'.length + whitespace_padding),
max: SpecTableAttr.new('Max', false, 'Max'.length + whitespace_padding),
unit: SpecTableAttr.new('Unit', false, 'Unit'.length + whitespace_padding),
audience: SpecTableAttr.new('Audience', false, 'Audience'.length + whitespace_padding)
# notes: SpecTableAttr.new('Notes', false, 'Notes'.length + whitespace_padding)
}
# Calculate the padding needed in the spec table for the longest attr of all specs
specs_to_be_shown.each do |spec|
attrs_to_be_shown.each do |attr_name, attr_struct|
unless spec.send(attr_name).nil?
if spec.send(attr_name).class == Origen::Specs::Spec::Limit
next if spec.send(attr_name).value.nil?
current_padding = spec.send(attr_name).value.to_s.length + whitespace_padding
else
current_padding = spec.send(attr_name).to_s.length + whitespace_padding
end
attr_struct.padding = current_padding if attr_struct.padding < current_padding
attr_struct.show = true # We found real data for this attr on at least one spec so show it in the spec table
end
end
end
# Now that each spec attribute padding construct the spec table header
header = ''
attrs_to_be_shown.each do |_attr_name, attr_struct|
next if attr_struct.show == false
header += "| #{attr_struct.table_text}".ljust(attr_struct.padding)
end
header += '|'
ip_header = "| IP: #{specs_to_be_shown.first.ip_name} ".ljust(header.length - 1)
ip_header += '|'
table << '=' * header.length
table << ip_header
table << '=' * header.length
table << header
table << '-' * header.length
# Create the data lines in the spec table
specs_to_be_shown.each do |spec|
data = ''
attrs_to_be_shown.each do |attr_name, attr_struct|
next if attr_struct.show == false
if spec.send(attr_name).class == Origen::Specs::Spec::Limit
data += "| #{spec.send(attr_name).value}".ljust(attr_struct.padding)
else
data += "| #{spec.send(attr_name)}".ljust(attr_struct.padding)
end
end
table << data += '|'
end
table << '-' * header.length
table.flatten.join("\n")
end | ruby | def specs_to_table_string(specs_to_be_shown)
whitespace_padding = 3
table = []
attrs_to_be_shown = {
name: SpecTableAttr.new('Name', true, 'Name'.length + whitespace_padding),
symbol: SpecTableAttr.new('Symbol', false, 'Symbol'.length + whitespace_padding),
mode: SpecTableAttr.new('Mode', true, 'Mode'.length + whitespace_padding),
type: SpecTableAttr.new('Type', true, 'Type'.length + whitespace_padding),
sub_type: SpecTableAttr.new('Sub-Type', false, 'Sub-Type'.length + whitespace_padding),
# spec SpecTableAttribute :description is called parameter in the spec table output to match historical docs
description: SpecTableAttr.new('Parameter', false, 'Parameter'.length + whitespace_padding),
min: SpecTableAttr.new('Min', false, 'Min'.length + whitespace_padding),
typ: SpecTableAttr.new('Typ', false, 'Typ'.length + whitespace_padding),
max: SpecTableAttr.new('Max', false, 'Max'.length + whitespace_padding),
unit: SpecTableAttr.new('Unit', false, 'Unit'.length + whitespace_padding),
audience: SpecTableAttr.new('Audience', false, 'Audience'.length + whitespace_padding)
# notes: SpecTableAttr.new('Notes', false, 'Notes'.length + whitespace_padding)
}
# Calculate the padding needed in the spec table for the longest attr of all specs
specs_to_be_shown.each do |spec|
attrs_to_be_shown.each do |attr_name, attr_struct|
unless spec.send(attr_name).nil?
if spec.send(attr_name).class == Origen::Specs::Spec::Limit
next if spec.send(attr_name).value.nil?
current_padding = spec.send(attr_name).value.to_s.length + whitespace_padding
else
current_padding = spec.send(attr_name).to_s.length + whitespace_padding
end
attr_struct.padding = current_padding if attr_struct.padding < current_padding
attr_struct.show = true # We found real data for this attr on at least one spec so show it in the spec table
end
end
end
# Now that each spec attribute padding construct the spec table header
header = ''
attrs_to_be_shown.each do |_attr_name, attr_struct|
next if attr_struct.show == false
header += "| #{attr_struct.table_text}".ljust(attr_struct.padding)
end
header += '|'
ip_header = "| IP: #{specs_to_be_shown.first.ip_name} ".ljust(header.length - 1)
ip_header += '|'
table << '=' * header.length
table << ip_header
table << '=' * header.length
table << header
table << '-' * header.length
# Create the data lines in the spec table
specs_to_be_shown.each do |spec|
data = ''
attrs_to_be_shown.each do |attr_name, attr_struct|
next if attr_struct.show == false
if spec.send(attr_name).class == Origen::Specs::Spec::Limit
data += "| #{spec.send(attr_name).value}".ljust(attr_struct.padding)
else
data += "| #{spec.send(attr_name)}".ljust(attr_struct.padding)
end
end
table << data += '|'
end
table << '-' * header.length
table.flatten.join("\n")
end | [
"def",
"specs_to_table_string",
"(",
"specs_to_be_shown",
")",
"whitespace_padding",
"=",
"3",
"table",
"=",
"[",
"]",
"attrs_to_be_shown",
"=",
"{",
"name",
":",
"SpecTableAttr",
".",
"new",
"(",
"'Name'",
",",
"true",
",",
"'Name'",
".",
"length",
"+",
"whitespace_padding",
")",
",",
"symbol",
":",
"SpecTableAttr",
".",
"new",
"(",
"'Symbol'",
",",
"false",
",",
"'Symbol'",
".",
"length",
"+",
"whitespace_padding",
")",
",",
"mode",
":",
"SpecTableAttr",
".",
"new",
"(",
"'Mode'",
",",
"true",
",",
"'Mode'",
".",
"length",
"+",
"whitespace_padding",
")",
",",
"type",
":",
"SpecTableAttr",
".",
"new",
"(",
"'Type'",
",",
"true",
",",
"'Type'",
".",
"length",
"+",
"whitespace_padding",
")",
",",
"sub_type",
":",
"SpecTableAttr",
".",
"new",
"(",
"'Sub-Type'",
",",
"false",
",",
"'Sub-Type'",
".",
"length",
"+",
"whitespace_padding",
")",
",",
"description",
":",
"SpecTableAttr",
".",
"new",
"(",
"'Parameter'",
",",
"false",
",",
"'Parameter'",
".",
"length",
"+",
"whitespace_padding",
")",
",",
"min",
":",
"SpecTableAttr",
".",
"new",
"(",
"'Min'",
",",
"false",
",",
"'Min'",
".",
"length",
"+",
"whitespace_padding",
")",
",",
"typ",
":",
"SpecTableAttr",
".",
"new",
"(",
"'Typ'",
",",
"false",
",",
"'Typ'",
".",
"length",
"+",
"whitespace_padding",
")",
",",
"max",
":",
"SpecTableAttr",
".",
"new",
"(",
"'Max'",
",",
"false",
",",
"'Max'",
".",
"length",
"+",
"whitespace_padding",
")",
",",
"unit",
":",
"SpecTableAttr",
".",
"new",
"(",
"'Unit'",
",",
"false",
",",
"'Unit'",
".",
"length",
"+",
"whitespace_padding",
")",
",",
"audience",
":",
"SpecTableAttr",
".",
"new",
"(",
"'Audience'",
",",
"false",
",",
"'Audience'",
".",
"length",
"+",
"whitespace_padding",
")",
"}",
"specs_to_be_shown",
".",
"each",
"do",
"|",
"spec",
"|",
"attrs_to_be_shown",
".",
"each",
"do",
"|",
"attr_name",
",",
"attr_struct",
"|",
"unless",
"spec",
".",
"send",
"(",
"attr_name",
")",
".",
"nil?",
"if",
"spec",
".",
"send",
"(",
"attr_name",
")",
".",
"class",
"==",
"Origen",
"::",
"Specs",
"::",
"Spec",
"::",
"Limit",
"next",
"if",
"spec",
".",
"send",
"(",
"attr_name",
")",
".",
"value",
".",
"nil?",
"current_padding",
"=",
"spec",
".",
"send",
"(",
"attr_name",
")",
".",
"value",
".",
"to_s",
".",
"length",
"+",
"whitespace_padding",
"else",
"current_padding",
"=",
"spec",
".",
"send",
"(",
"attr_name",
")",
".",
"to_s",
".",
"length",
"+",
"whitespace_padding",
"end",
"attr_struct",
".",
"padding",
"=",
"current_padding",
"if",
"attr_struct",
".",
"padding",
"<",
"current_padding",
"attr_struct",
".",
"show",
"=",
"true",
"end",
"end",
"end",
"header",
"=",
"''",
"attrs_to_be_shown",
".",
"each",
"do",
"|",
"_attr_name",
",",
"attr_struct",
"|",
"next",
"if",
"attr_struct",
".",
"show",
"==",
"false",
"header",
"+=",
"\"| #{attr_struct.table_text}\"",
".",
"ljust",
"(",
"attr_struct",
".",
"padding",
")",
"end",
"header",
"+=",
"'|'",
"ip_header",
"=",
"\"| IP: #{specs_to_be_shown.first.ip_name} \"",
".",
"ljust",
"(",
"header",
".",
"length",
"-",
"1",
")",
"ip_header",
"+=",
"'|'",
"table",
"<<",
"'='",
"*",
"header",
".",
"length",
"table",
"<<",
"ip_header",
"table",
"<<",
"'='",
"*",
"header",
".",
"length",
"table",
"<<",
"header",
"table",
"<<",
"'-'",
"*",
"header",
".",
"length",
"specs_to_be_shown",
".",
"each",
"do",
"|",
"spec",
"|",
"data",
"=",
"''",
"attrs_to_be_shown",
".",
"each",
"do",
"|",
"attr_name",
",",
"attr_struct",
"|",
"next",
"if",
"attr_struct",
".",
"show",
"==",
"false",
"if",
"spec",
".",
"send",
"(",
"attr_name",
")",
".",
"class",
"==",
"Origen",
"::",
"Specs",
"::",
"Spec",
"::",
"Limit",
"data",
"+=",
"\"| #{spec.send(attr_name).value}\"",
".",
"ljust",
"(",
"attr_struct",
".",
"padding",
")",
"else",
"data",
"+=",
"\"| #{spec.send(attr_name)}\"",
".",
"ljust",
"(",
"attr_struct",
".",
"padding",
")",
"end",
"end",
"table",
"<<",
"data",
"+=",
"'|'",
"end",
"table",
"<<",
"'-'",
"*",
"header",
".",
"length",
"table",
".",
"flatten",
".",
"join",
"(",
"\"\\n\"",
")",
"end"
]
| Method to print a spec table to the console | [
"Method",
"to",
"print",
"a",
"spec",
"table",
"to",
"the",
"console"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/specs.rb#L726-L788 | train |
Origen-SDK/origen | lib/origen/application.rb | Origen.Application.maillist_parse | def maillist_parse(file)
maillist = []
# if file doesn't exist, just return empty array, otherwise, parse for emails
if File.exist?(file)
File.readlines(file).each do |line|
if index = (line =~ /\#/)
# line contains some kind of comment
# check if there is any useful info, ignore it not
unless line[0, index].strip.empty?
maillist << Origen::Users::User.new(line[0, index].strip).email
end
else
# if line is not empty, generate an email
unless line.strip.empty?
maillist << Origen::Users::User.new(line.strip).email
end
end
end
end
maillist
end | ruby | def maillist_parse(file)
maillist = []
# if file doesn't exist, just return empty array, otherwise, parse for emails
if File.exist?(file)
File.readlines(file).each do |line|
if index = (line =~ /\#/)
# line contains some kind of comment
# check if there is any useful info, ignore it not
unless line[0, index].strip.empty?
maillist << Origen::Users::User.new(line[0, index].strip).email
end
else
# if line is not empty, generate an email
unless line.strip.empty?
maillist << Origen::Users::User.new(line.strip).email
end
end
end
end
maillist
end | [
"def",
"maillist_parse",
"(",
"file",
")",
"maillist",
"=",
"[",
"]",
"if",
"File",
".",
"exist?",
"(",
"file",
")",
"File",
".",
"readlines",
"(",
"file",
")",
".",
"each",
"do",
"|",
"line",
"|",
"if",
"index",
"=",
"(",
"line",
"=~",
"/",
"\\#",
"/",
")",
"unless",
"line",
"[",
"0",
",",
"index",
"]",
".",
"strip",
".",
"empty?",
"maillist",
"<<",
"Origen",
"::",
"Users",
"::",
"User",
".",
"new",
"(",
"line",
"[",
"0",
",",
"index",
"]",
".",
"strip",
")",
".",
"email",
"end",
"else",
"unless",
"line",
".",
"strip",
".",
"empty?",
"maillist",
"<<",
"Origen",
"::",
"Users",
"::",
"User",
".",
"new",
"(",
"line",
".",
"strip",
")",
".",
"email",
"end",
"end",
"end",
"end",
"maillist",
"end"
]
| Parses maillist file and returns an array of email address | [
"Parses",
"maillist",
"file",
"and",
"returns",
"an",
"array",
"of",
"email",
"address"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/application.rb#L240-L261 | train |
Origen-SDK/origen | lib/origen/application.rb | Origen.Application.server_data | def server_data
if name == :origen
@server_data ||= Origen.client.origen
else
@server_data ||= Origen.client.plugins.find { |p| p[:origen_name].downcase == name.to_s.downcase }
end
end | ruby | def server_data
if name == :origen
@server_data ||= Origen.client.origen
else
@server_data ||= Origen.client.plugins.find { |p| p[:origen_name].downcase == name.to_s.downcase }
end
end | [
"def",
"server_data",
"if",
"name",
"==",
":origen",
"@server_data",
"||=",
"Origen",
".",
"client",
".",
"origen",
"else",
"@server_data",
"||=",
"Origen",
".",
"client",
".",
"plugins",
".",
"find",
"{",
"|",
"p",
"|",
"p",
"[",
":origen_name",
"]",
".",
"downcase",
"==",
"name",
".",
"to_s",
".",
"downcase",
"}",
"end",
"end"
]
| Returns the server data packet available for the given application,
returns nil if none is found | [
"Returns",
"the",
"server",
"data",
"packet",
"available",
"for",
"the",
"given",
"application",
"returns",
"nil",
"if",
"none",
"is",
"found"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/application.rb#L285-L291 | train |
Origen-SDK/origen | lib/origen/application.rb | Origen.Application.release_date | def release_date(version = Origen.app.version.prefixed)
time = release_time(version)
time ? time.to_date : nil
end | ruby | def release_date(version = Origen.app.version.prefixed)
time = release_time(version)
time ? time.to_date : nil
end | [
"def",
"release_date",
"(",
"version",
"=",
"Origen",
".",
"app",
".",
"version",
".",
"prefixed",
")",
"time",
"=",
"release_time",
"(",
"version",
")",
"time",
"?",
"time",
".",
"to_date",
":",
"nil",
"end"
]
| Returns the release date for the current or given application version | [
"Returns",
"the",
"release",
"date",
"for",
"the",
"current",
"or",
"given",
"application",
"version"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/application.rb#L436-L439 | train |
Origen-SDK/origen | lib/origen/application.rb | Origen.Application.dynamic_resource | def dynamic_resource(name, default, options = {})
@static_resources ||= {}
@transient_resources ||= {}
if @load_event == :static ||
(!@load_event && options[:adding])
if options[:set]
@static_resources[name] = default
else
@static_resources[name] ||= default
end
elsif @load_event == :transient
if options[:set]
@transient_resources[name] = default
else
@transient_resources[name] ||= default
end
else
static = @static_resources[name] ||= default
transient = @transient_resources[name] ||= default
if static.respond_to?('+')
static + transient
else
static.merge(transient)
end
end
end | ruby | def dynamic_resource(name, default, options = {})
@static_resources ||= {}
@transient_resources ||= {}
if @load_event == :static ||
(!@load_event && options[:adding])
if options[:set]
@static_resources[name] = default
else
@static_resources[name] ||= default
end
elsif @load_event == :transient
if options[:set]
@transient_resources[name] = default
else
@transient_resources[name] ||= default
end
else
static = @static_resources[name] ||= default
transient = @transient_resources[name] ||= default
if static.respond_to?('+')
static + transient
else
static.merge(transient)
end
end
end | [
"def",
"dynamic_resource",
"(",
"name",
",",
"default",
",",
"options",
"=",
"{",
"}",
")",
"@static_resources",
"||=",
"{",
"}",
"@transient_resources",
"||=",
"{",
"}",
"if",
"@load_event",
"==",
":static",
"||",
"(",
"!",
"@load_event",
"&&",
"options",
"[",
":adding",
"]",
")",
"if",
"options",
"[",
":set",
"]",
"@static_resources",
"[",
"name",
"]",
"=",
"default",
"else",
"@static_resources",
"[",
"name",
"]",
"||=",
"default",
"end",
"elsif",
"@load_event",
"==",
":transient",
"if",
"options",
"[",
":set",
"]",
"@transient_resources",
"[",
"name",
"]",
"=",
"default",
"else",
"@transient_resources",
"[",
"name",
"]",
"||=",
"default",
"end",
"else",
"static",
"=",
"@static_resources",
"[",
"name",
"]",
"||=",
"default",
"transient",
"=",
"@transient_resources",
"[",
"name",
"]",
"||=",
"default",
"if",
"static",
".",
"respond_to?",
"(",
"'+'",
")",
"static",
"+",
"transient",
"else",
"static",
".",
"merge",
"(",
"transient",
")",
"end",
"end",
"end"
]
| Enable for debugging to see what the currently tracked objects are
def object_store
[@load_event, @static_resources, @transient_resources]
end | [
"Enable",
"for",
"debugging",
"to",
"see",
"what",
"the",
"currently",
"tracked",
"objects",
"are",
"def",
"object_store",
"["
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/application.rb#L857-L882 | train |
Origen-SDK/origen | lib/origen/client.rb | Origen.Client.release! | def release!
version = Origen.app.version
body = { version: version.to_s }
if version.production?
body[:type] = :production
else
body[:type] = :development
end
post("plugins/#{Origen.app.name}/release", body: body)
end | ruby | def release!
version = Origen.app.version
body = { version: version.to_s }
if version.production?
body[:type] = :production
else
body[:type] = :development
end
post("plugins/#{Origen.app.name}/release", body: body)
end | [
"def",
"release!",
"version",
"=",
"Origen",
".",
"app",
".",
"version",
"body",
"=",
"{",
"version",
":",
"version",
".",
"to_s",
"}",
"if",
"version",
".",
"production?",
"body",
"[",
":type",
"]",
"=",
":production",
"else",
"body",
"[",
":type",
"]",
"=",
":development",
"end",
"post",
"(",
"\"plugins/#{Origen.app.name}/release\"",
",",
"body",
":",
"body",
")",
"end"
]
| This will be called by the Origen release process to post
the latest app version information to the server | [
"This",
"will",
"be",
"called",
"by",
"the",
"Origen",
"release",
"process",
"to",
"post",
"the",
"latest",
"app",
"version",
"information",
"to",
"the",
"server"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/client.rb#L66-L75 | train |
Origen-SDK/origen | lib/origen/model.rb | Origen.Model.current_mode= | def current_mode=(id)
@current_mode = id.is_a?(ChipMode) ? id.id : id
Origen.app.listeners_for(:on_mode_changed).each do |listener|
listener.on_mode_changed(mode: @current_mode, instance: self)
end
@current_mode
end | ruby | def current_mode=(id)
@current_mode = id.is_a?(ChipMode) ? id.id : id
Origen.app.listeners_for(:on_mode_changed).each do |listener|
listener.on_mode_changed(mode: @current_mode, instance: self)
end
@current_mode
end | [
"def",
"current_mode",
"=",
"(",
"id",
")",
"@current_mode",
"=",
"id",
".",
"is_a?",
"(",
"ChipMode",
")",
"?",
"id",
".",
"id",
":",
"id",
"Origen",
".",
"app",
".",
"listeners_for",
"(",
":on_mode_changed",
")",
".",
"each",
"do",
"|",
"listener",
"|",
"listener",
".",
"on_mode_changed",
"(",
"mode",
":",
"@current_mode",
",",
"instance",
":",
"self",
")",
"end",
"@current_mode",
"end"
]
| Set the current mode configuration of the current model | [
"Set",
"the",
"current",
"mode",
"configuration",
"of",
"the",
"current",
"model"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/model.rb#L219-L225 | train |
Origen-SDK/origen | lib/origen/model.rb | Origen.Model.modes | def modes(id = nil, _options = {})
id = nil if id.is_a?(Hash)
if id
_modes[id]
else
_modes.ids
end
end | ruby | def modes(id = nil, _options = {})
id = nil if id.is_a?(Hash)
if id
_modes[id]
else
_modes.ids
end
end | [
"def",
"modes",
"(",
"id",
"=",
"nil",
",",
"_options",
"=",
"{",
"}",
")",
"id",
"=",
"nil",
"if",
"id",
".",
"is_a?",
"(",
"Hash",
")",
"if",
"id",
"_modes",
"[",
"id",
"]",
"else",
"_modes",
".",
"ids",
"end",
"end"
]
| Returns an array containing the IDs of all known modes if no ID is supplied,
otherwise returns an object representing the given mode ID | [
"Returns",
"an",
"array",
"containing",
"the",
"IDs",
"of",
"all",
"known",
"modes",
"if",
"no",
"ID",
"is",
"supplied",
"otherwise",
"returns",
"an",
"object",
"representing",
"the",
"given",
"mode",
"ID"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/model.rb#L242-L249 | train |
Origen-SDK/origen | lib/origen/model.rb | Origen.Model.with_each_mode | def with_each_mode
begin
orig = current_mode
rescue
orig = nil
end
modes.each do |_id, mode|
self.current_mode = mode
yield mode
end
self.current_mode = orig
end | ruby | def with_each_mode
begin
orig = current_mode
rescue
orig = nil
end
modes.each do |_id, mode|
self.current_mode = mode
yield mode
end
self.current_mode = orig
end | [
"def",
"with_each_mode",
"begin",
"orig",
"=",
"current_mode",
"rescue",
"orig",
"=",
"nil",
"end",
"modes",
".",
"each",
"do",
"|",
"_id",
",",
"mode",
"|",
"self",
".",
"current_mode",
"=",
"mode",
"yield",
"mode",
"end",
"self",
".",
"current_mode",
"=",
"orig",
"end"
]
| Executes the given block of code for each known chip mode, inside the block
the current mode of the top level block will be set to the given mode.
At the end of the block the current mode will be restored to whatever it
was before entering the block. | [
"Executes",
"the",
"given",
"block",
"of",
"code",
"for",
"each",
"known",
"chip",
"mode",
"inside",
"the",
"block",
"the",
"current",
"mode",
"of",
"the",
"top",
"level",
"block",
"will",
"be",
"set",
"to",
"the",
"given",
"mode",
"."
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/model.rb#L265-L276 | train |
Origen-SDK/origen | lib/origen/model.rb | Origen.Model.find_specs | def find_specs
specs_found = []
# Check for specs the object owns
if self.respond_to? :specs
object_specs = specs
unless object_specs.nil?
if object_specs.class == Origen::Specs::Spec
specs_found << object_specs
else
specs_found.concat(object_specs)
end
end
end
sub_blocks.each do |_name, sb|
next unless sb.respond_to? :specs
child_specs = sb.specs
unless child_specs.nil?
if child_specs.class == Origen::Specs::Spec
specs_found << child_specs
else
specs_found.concat(child_specs)
end
end
end
specs_found
end | ruby | def find_specs
specs_found = []
# Check for specs the object owns
if self.respond_to? :specs
object_specs = specs
unless object_specs.nil?
if object_specs.class == Origen::Specs::Spec
specs_found << object_specs
else
specs_found.concat(object_specs)
end
end
end
sub_blocks.each do |_name, sb|
next unless sb.respond_to? :specs
child_specs = sb.specs
unless child_specs.nil?
if child_specs.class == Origen::Specs::Spec
specs_found << child_specs
else
specs_found.concat(child_specs)
end
end
end
specs_found
end | [
"def",
"find_specs",
"specs_found",
"=",
"[",
"]",
"if",
"self",
".",
"respond_to?",
":specs",
"object_specs",
"=",
"specs",
"unless",
"object_specs",
".",
"nil?",
"if",
"object_specs",
".",
"class",
"==",
"Origen",
"::",
"Specs",
"::",
"Spec",
"specs_found",
"<<",
"object_specs",
"else",
"specs_found",
".",
"concat",
"(",
"object_specs",
")",
"end",
"end",
"end",
"sub_blocks",
".",
"each",
"do",
"|",
"_name",
",",
"sb",
"|",
"next",
"unless",
"sb",
".",
"respond_to?",
":specs",
"child_specs",
"=",
"sb",
".",
"specs",
"unless",
"child_specs",
".",
"nil?",
"if",
"child_specs",
".",
"class",
"==",
"Origen",
"::",
"Specs",
"::",
"Spec",
"specs_found",
"<<",
"child_specs",
"else",
"specs_found",
".",
"concat",
"(",
"child_specs",
")",
"end",
"end",
"end",
"specs_found",
"end"
]
| Returns all specs found for the model. if none found it returns an empty array | [
"Returns",
"all",
"specs",
"found",
"for",
"the",
"model",
".",
"if",
"none",
"found",
"it",
"returns",
"an",
"empty",
"array"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/model.rb#L287-L312 | train |
Origen-SDK/origen | lib/origen/model.rb | Origen.Model.delete_all_specs_and_notes | def delete_all_specs_and_notes(obj = nil)
obj = self if obj.nil?
obj.delete_all_specs
obj.delete_all_notes
obj.delete_all_exhibits
obj.children.each do |_name, child|
next unless child.has_specs?
delete_all_specs_and_notes(child)
end
end | ruby | def delete_all_specs_and_notes(obj = nil)
obj = self if obj.nil?
obj.delete_all_specs
obj.delete_all_notes
obj.delete_all_exhibits
obj.children.each do |_name, child|
next unless child.has_specs?
delete_all_specs_and_notes(child)
end
end | [
"def",
"delete_all_specs_and_notes",
"(",
"obj",
"=",
"nil",
")",
"obj",
"=",
"self",
"if",
"obj",
".",
"nil?",
"obj",
".",
"delete_all_specs",
"obj",
".",
"delete_all_notes",
"obj",
".",
"delete_all_exhibits",
"obj",
".",
"children",
".",
"each",
"do",
"|",
"_name",
",",
"child",
"|",
"next",
"unless",
"child",
".",
"has_specs?",
"delete_all_specs_and_notes",
"(",
"child",
")",
"end",
"end"
]
| Delete all specs and notes for self recursively | [
"Delete",
"all",
"specs",
"and",
"notes",
"for",
"self",
"recursively"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/model.rb#L315-L324 | train |
Origen-SDK/origen | lib/origen/model.rb | Origen.Model.method_missing | def method_missing(method, *args, &block)
if controller.respond_to?(method)
define_singleton_method(method) do |*args, &block|
controller.send(method, *args, &block)
end
send(method, *args, &block)
else
super
end
end | ruby | def method_missing(method, *args, &block)
if controller.respond_to?(method)
define_singleton_method(method) do |*args, &block|
controller.send(method, *args, &block)
end
send(method, *args, &block)
else
super
end
end | [
"def",
"method_missing",
"(",
"method",
",",
"*",
"args",
",",
"&",
"block",
")",
"if",
"controller",
".",
"respond_to?",
"(",
"method",
")",
"define_singleton_method",
"(",
"method",
")",
"do",
"|",
"*",
"args",
",",
"&",
"block",
"|",
"controller",
".",
"send",
"(",
"method",
",",
"*",
"args",
",",
"&",
"block",
")",
"end",
"send",
"(",
"method",
",",
"*",
"args",
",",
"&",
"block",
")",
"else",
"super",
"end",
"end"
]
| Used to proxy all method and attribute requests not implemented on the model
to the controller.
On first call of a missing method a method is generated to avoid the missing lookup
next time, this should be faster for repeated lookups of the same method, e.g. reg | [
"Used",
"to",
"proxy",
"all",
"method",
"and",
"attribute",
"requests",
"not",
"implemented",
"on",
"the",
"model",
"to",
"the",
"controller",
"."
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/model.rb#L342-L351 | train |
Origen-SDK/origen | lib/origen/users.rb | Origen.Users.current_user | def current_user
core_id = Origen::Users::User.current_user_id
user = app_users.find { |user| user.core_id == core_id }
user || User.new(core_id)
end | ruby | def current_user
core_id = Origen::Users::User.current_user_id
user = app_users.find { |user| user.core_id == core_id }
user || User.new(core_id)
end | [
"def",
"current_user",
"core_id",
"=",
"Origen",
"::",
"Users",
"::",
"User",
".",
"current_user_id",
"user",
"=",
"app_users",
".",
"find",
"{",
"|",
"user",
"|",
"user",
".",
"core_id",
"==",
"core_id",
"}",
"user",
"||",
"User",
".",
"new",
"(",
"core_id",
")",
"end"
]
| Returns a user object representing the current user, will return a default
user object if the current user is not known to the generator | [
"Returns",
"a",
"user",
"object",
"representing",
"the",
"current",
"user",
"will",
"return",
"a",
"default",
"user",
"object",
"if",
"the",
"current",
"user",
"is",
"not",
"known",
"to",
"the",
"generator"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/users.rb#L19-L23 | train |
Origen-SDK/origen | lib/origen/version_string.rb | Origen.VersionString.numeric | def numeric
if latest?
1_000_000_000_000_000_000_000_000_000
elsif semantic?
# This assumes each counter will never go > 1000
if development?
self =~ /v?(\d+).(\d+).(\d+).(dev|pre)(\d+)/
(Regexp.last_match[1].to_i * 1000 * 1000 * 1000) +
(Regexp.last_match[2].to_i * 1000 * 1000) +
(Regexp.last_match[3].to_i * 1000) +
Regexp.last_match[5].to_i
else
self =~ /v?(\d+).(\d+).(\d+)/
(Regexp.last_match[1].to_i * 1000 * 1000 * 1000) +
(Regexp.last_match[2].to_i * 1000 * 1000) +
(Regexp.last_match[3].to_i * 1000)
end
elsif timestamp?
to_time.to_i
else
validate!
end
end | ruby | def numeric
if latest?
1_000_000_000_000_000_000_000_000_000
elsif semantic?
# This assumes each counter will never go > 1000
if development?
self =~ /v?(\d+).(\d+).(\d+).(dev|pre)(\d+)/
(Regexp.last_match[1].to_i * 1000 * 1000 * 1000) +
(Regexp.last_match[2].to_i * 1000 * 1000) +
(Regexp.last_match[3].to_i * 1000) +
Regexp.last_match[5].to_i
else
self =~ /v?(\d+).(\d+).(\d+)/
(Regexp.last_match[1].to_i * 1000 * 1000 * 1000) +
(Regexp.last_match[2].to_i * 1000 * 1000) +
(Regexp.last_match[3].to_i * 1000)
end
elsif timestamp?
to_time.to_i
else
validate!
end
end | [
"def",
"numeric",
"if",
"latest?",
"1_000_000_000_000_000_000_000_000_000",
"elsif",
"semantic?",
"if",
"development?",
"self",
"=~",
"/",
"\\d",
"\\d",
"\\d",
"\\d",
"/",
"(",
"Regexp",
".",
"last_match",
"[",
"1",
"]",
".",
"to_i",
"*",
"1000",
"*",
"1000",
"*",
"1000",
")",
"+",
"(",
"Regexp",
".",
"last_match",
"[",
"2",
"]",
".",
"to_i",
"*",
"1000",
"*",
"1000",
")",
"+",
"(",
"Regexp",
".",
"last_match",
"[",
"3",
"]",
".",
"to_i",
"*",
"1000",
")",
"+",
"Regexp",
".",
"last_match",
"[",
"5",
"]",
".",
"to_i",
"else",
"self",
"=~",
"/",
"\\d",
"\\d",
"\\d",
"/",
"(",
"Regexp",
".",
"last_match",
"[",
"1",
"]",
".",
"to_i",
"*",
"1000",
"*",
"1000",
"*",
"1000",
")",
"+",
"(",
"Regexp",
".",
"last_match",
"[",
"2",
"]",
".",
"to_i",
"*",
"1000",
"*",
"1000",
")",
"+",
"(",
"Regexp",
".",
"last_match",
"[",
"3",
"]",
".",
"to_i",
"*",
"1000",
")",
"end",
"elsif",
"timestamp?",
"to_time",
".",
"to_i",
"else",
"validate!",
"end",
"end"
]
| Returns a numeric representation of the version, this can be used
for chronological comparison with other versions | [
"Returns",
"a",
"numeric",
"representation",
"of",
"the",
"version",
"this",
"can",
"be",
"used",
"for",
"chronological",
"comparison",
"with",
"other",
"versions"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/version_string.rb#L255-L277 | train |
Origen-SDK/origen | lib/origen/version_string.rb | Origen.VersionString.to_time | def to_time
if latest?
Time.new(10_000, 1, 1)
elsif timestamp?
if development?
self =~ /\w+_(\d\d\d\d)_(\d\d)_(\d\d)_(\d\d)_(\d\d)$/
Time.new(Regexp.last_match[1], Regexp.last_match[2], Regexp.last_match[3], Regexp.last_match[4], Regexp.last_match[5])
else
self =~ /Rel(\d\d\d\d)(\d\d)(\d\d)/
Time.new(Regexp.last_match[1], Regexp.last_match[2], Regexp.last_match[3])
end
else
fail "Version tag #{self} cannot be converted to a time!"
end
end | ruby | def to_time
if latest?
Time.new(10_000, 1, 1)
elsif timestamp?
if development?
self =~ /\w+_(\d\d\d\d)_(\d\d)_(\d\d)_(\d\d)_(\d\d)$/
Time.new(Regexp.last_match[1], Regexp.last_match[2], Regexp.last_match[3], Regexp.last_match[4], Regexp.last_match[5])
else
self =~ /Rel(\d\d\d\d)(\d\d)(\d\d)/
Time.new(Regexp.last_match[1], Regexp.last_match[2], Regexp.last_match[3])
end
else
fail "Version tag #{self} cannot be converted to a time!"
end
end | [
"def",
"to_time",
"if",
"latest?",
"Time",
".",
"new",
"(",
"10_000",
",",
"1",
",",
"1",
")",
"elsif",
"timestamp?",
"if",
"development?",
"self",
"=~",
"/",
"\\w",
"\\d",
"\\d",
"\\d",
"\\d",
"\\d",
"\\d",
"\\d",
"\\d",
"\\d",
"\\d",
"\\d",
"\\d",
"/",
"Time",
".",
"new",
"(",
"Regexp",
".",
"last_match",
"[",
"1",
"]",
",",
"Regexp",
".",
"last_match",
"[",
"2",
"]",
",",
"Regexp",
".",
"last_match",
"[",
"3",
"]",
",",
"Regexp",
".",
"last_match",
"[",
"4",
"]",
",",
"Regexp",
".",
"last_match",
"[",
"5",
"]",
")",
"else",
"self",
"=~",
"/",
"\\d",
"\\d",
"\\d",
"\\d",
"\\d",
"\\d",
"\\d",
"\\d",
"/",
"Time",
".",
"new",
"(",
"Regexp",
".",
"last_match",
"[",
"1",
"]",
",",
"Regexp",
".",
"last_match",
"[",
"2",
"]",
",",
"Regexp",
".",
"last_match",
"[",
"3",
"]",
")",
"end",
"else",
"fail",
"\"Version tag #{self} cannot be converted to a time!\"",
"end",
"end"
]
| Returns the version as a time, only applicable for timestamps,
otherwise an error will be raised | [
"Returns",
"the",
"version",
"as",
"a",
"time",
"only",
"applicable",
"for",
"timestamps",
"otherwise",
"an",
"error",
"will",
"be",
"raised"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/version_string.rb#L281-L295 | train |
Origen-SDK/origen | lib/origen/version_string.rb | Origen.VersionString.validate_condition! | def validate_condition!(condition, tag)
tag = VersionString.new(tag)
tag.validate!("The version condition, #{condition}, is not valid!")
tag
end | ruby | def validate_condition!(condition, tag)
tag = VersionString.new(tag)
tag.validate!("The version condition, #{condition}, is not valid!")
tag
end | [
"def",
"validate_condition!",
"(",
"condition",
",",
"tag",
")",
"tag",
"=",
"VersionString",
".",
"new",
"(",
"tag",
")",
"tag",
".",
"validate!",
"(",
"\"The version condition, #{condition}, is not valid!\"",
")",
"tag",
"end"
]
| Validates the given condition and the extracted tag, returns the
tag wrapped in a VersionString if valid, will raise an error if
not | [
"Validates",
"the",
"given",
"condition",
"and",
"the",
"extracted",
"tag",
"returns",
"the",
"tag",
"wrapped",
"in",
"a",
"VersionString",
"if",
"valid",
"will",
"raise",
"an",
"error",
"if",
"not"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/version_string.rb#L312-L316 | train |
Origen-SDK/origen | lib/origen/remote_manager.rb | Origen.RemoteManager.delete_symlink | def delete_symlink(path)
if Origen.running_on_windows?
# Don't use regular rm on windows symlink, will delete into the remote dir!
system("call cmd /c rmdir #{path.to_s.gsub('/', '\\')}")
FileUtils.rm_f("#{path}_is_a_symlink")
else
FileUtils.rm_f(path)
end
end | ruby | def delete_symlink(path)
if Origen.running_on_windows?
# Don't use regular rm on windows symlink, will delete into the remote dir!
system("call cmd /c rmdir #{path.to_s.gsub('/', '\\')}")
FileUtils.rm_f("#{path}_is_a_symlink")
else
FileUtils.rm_f(path)
end
end | [
"def",
"delete_symlink",
"(",
"path",
")",
"if",
"Origen",
".",
"running_on_windows?",
"system",
"(",
"\"call cmd /c rmdir #{path.to_s.gsub('/', '\\\\')}\"",
")",
"FileUtils",
".",
"rm_f",
"(",
"\"#{path}_is_a_symlink\"",
")",
"else",
"FileUtils",
".",
"rm_f",
"(",
"path",
")",
"end",
"end"
]
| Manually handle symlink deletion to support windows
@api private | [
"Manually",
"handle",
"symlink",
"deletion",
"to",
"support",
"windows"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/remote_manager.rb#L100-L108 | train |
Origen-SDK/origen | lib/origen/remote_manager.rb | Origen.RemoteManager.process_remotes | def process_remotes
remotes.each do |_name, remote|
dir = workspace_of(remote)
rc_url = remote[:rc_url] || remote[:vault]
tag = remote[:tag].nil? ? Origen::VersionString.new(remote[:version]) : Origen::VersionString.new(remote[:tag])
version_file = dir.to_s + '/.current_version'
begin
if File.exist?("#{dir}/.initial_populate_successful")
FileUtils.rm_f(version_file) if File.exist?(version_file)
rc = RevisionControl.new remote: rc_url, local: dir
rc.send rc.remotes_method, version: prefix_tag(tag), force: true
File.open(version_file, 'w') do |f|
f.write tag
end
else
rc = RevisionControl.new remote: rc_url, local: dir
rc.send rc.remotes_method, version: prefix_tag(tag), force: true
FileUtils.touch "#{dir}/.initial_populate_successful"
File.open(version_file, 'w') do |f|
f.write tag
end
end
rescue Origen::GitError, Origen::DesignSyncError, Origen::PerforceError => e
# If Git failed in the remote, its usually easy to see what the problem is, but now *where* it is.
# This will prepend the failing remote along with the error from the revision control system,
# then rethrow the error
e.message.prepend "When updating remotes for #{remote[:importer].name}: "
raise e
end
end
end | ruby | def process_remotes
remotes.each do |_name, remote|
dir = workspace_of(remote)
rc_url = remote[:rc_url] || remote[:vault]
tag = remote[:tag].nil? ? Origen::VersionString.new(remote[:version]) : Origen::VersionString.new(remote[:tag])
version_file = dir.to_s + '/.current_version'
begin
if File.exist?("#{dir}/.initial_populate_successful")
FileUtils.rm_f(version_file) if File.exist?(version_file)
rc = RevisionControl.new remote: rc_url, local: dir
rc.send rc.remotes_method, version: prefix_tag(tag), force: true
File.open(version_file, 'w') do |f|
f.write tag
end
else
rc = RevisionControl.new remote: rc_url, local: dir
rc.send rc.remotes_method, version: prefix_tag(tag), force: true
FileUtils.touch "#{dir}/.initial_populate_successful"
File.open(version_file, 'w') do |f|
f.write tag
end
end
rescue Origen::GitError, Origen::DesignSyncError, Origen::PerforceError => e
# If Git failed in the remote, its usually easy to see what the problem is, but now *where* it is.
# This will prepend the failing remote along with the error from the revision control system,
# then rethrow the error
e.message.prepend "When updating remotes for #{remote[:importer].name}: "
raise e
end
end
end | [
"def",
"process_remotes",
"remotes",
".",
"each",
"do",
"|",
"_name",
",",
"remote",
"|",
"dir",
"=",
"workspace_of",
"(",
"remote",
")",
"rc_url",
"=",
"remote",
"[",
":rc_url",
"]",
"||",
"remote",
"[",
":vault",
"]",
"tag",
"=",
"remote",
"[",
":tag",
"]",
".",
"nil?",
"?",
"Origen",
"::",
"VersionString",
".",
"new",
"(",
"remote",
"[",
":version",
"]",
")",
":",
"Origen",
"::",
"VersionString",
".",
"new",
"(",
"remote",
"[",
":tag",
"]",
")",
"version_file",
"=",
"dir",
".",
"to_s",
"+",
"'/.current_version'",
"begin",
"if",
"File",
".",
"exist?",
"(",
"\"#{dir}/.initial_populate_successful\"",
")",
"FileUtils",
".",
"rm_f",
"(",
"version_file",
")",
"if",
"File",
".",
"exist?",
"(",
"version_file",
")",
"rc",
"=",
"RevisionControl",
".",
"new",
"remote",
":",
"rc_url",
",",
"local",
":",
"dir",
"rc",
".",
"send",
"rc",
".",
"remotes_method",
",",
"version",
":",
"prefix_tag",
"(",
"tag",
")",
",",
"force",
":",
"true",
"File",
".",
"open",
"(",
"version_file",
",",
"'w'",
")",
"do",
"|",
"f",
"|",
"f",
".",
"write",
"tag",
"end",
"else",
"rc",
"=",
"RevisionControl",
".",
"new",
"remote",
":",
"rc_url",
",",
"local",
":",
"dir",
"rc",
".",
"send",
"rc",
".",
"remotes_method",
",",
"version",
":",
"prefix_tag",
"(",
"tag",
")",
",",
"force",
":",
"true",
"FileUtils",
".",
"touch",
"\"#{dir}/.initial_populate_successful\"",
"File",
".",
"open",
"(",
"version_file",
",",
"'w'",
")",
"do",
"|",
"f",
"|",
"f",
".",
"write",
"tag",
"end",
"end",
"rescue",
"Origen",
"::",
"GitError",
",",
"Origen",
"::",
"DesignSyncError",
",",
"Origen",
"::",
"PerforceError",
"=>",
"e",
"e",
".",
"message",
".",
"prepend",
"\"When updating remotes for #{remote[:importer].name}: \"",
"raise",
"e",
"end",
"end",
"end"
]
| Process each remote | [
"Process",
"each",
"remote"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/remote_manager.rb#L131-L161 | train |
Origen-SDK/origen | lib/origen/remote_manager.rb | Origen.RemoteManager.path_enabled? | def path_enabled?(remote)
dir = workspace_of(remote)
File.exist?(dir) && symlink?(dir)
end | ruby | def path_enabled?(remote)
dir = workspace_of(remote)
File.exist?(dir) && symlink?(dir)
end | [
"def",
"path_enabled?",
"(",
"remote",
")",
"dir",
"=",
"workspace_of",
"(",
"remote",
")",
"File",
".",
"exist?",
"(",
"dir",
")",
"&&",
"symlink?",
"(",
"dir",
")",
"end"
]
| Returns true if the given import is currently setup as a path | [
"Returns",
"true",
"if",
"the",
"given",
"import",
"is",
"currently",
"setup",
"as",
"a",
"path"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/remote_manager.rb#L242-L245 | train |
Origen-SDK/origen | lib/origen/remote_manager.rb | Origen.RemoteManager.update! | def update!
ensure_remotes_directory
dirty_remotes.each do |_name, remote|
dir = workspace_of(remote)
if remote[:path] || path_enabled?(remote)
if symlink?(dir)
delete_symlink(dir)
else
FileUtils.rm_rf(dir) if File.exist?(dir)
end
end
if remote[:path]
create_symlink(remote[:path], dir)
else
rc_url = remote[:rc_url] || remote[:vault]
tag = remote[:tag].nil? ? Origen::VersionString.new(remote[:version]) : Origen::VersionString.new(remote[:tag])
version_file = dir.to_s + '/.current_version'
begin
if File.exist?("#{dir}/.initial_populate_successful")
FileUtils.rm_f(version_file) if File.exist?(version_file)
rc = RevisionControl.new remote: rc_url, local: dir
rc.send rc.remotes_method, version: prefix_tag(tag), force: true
File.open(version_file, 'w') do |f|
f.write tag
end
else
rc = RevisionControl.new remote: rc_url, local: dir
rc.send rc.remotes_method, version: prefix_tag(tag), force: true
FileUtils.touch "#{dir}/.initial_populate_successful"
File.open(version_file, 'w') do |f|
f.write tag
end
end
rescue Origen::GitError, Origen::DesignSyncError, Origen::PerforceError => e
# If Git failed in the remote, its usually easy to see what the problem is, but now *where* it is.
# This will prepend the failing remote along with the error from the revision control system,
# then rethrow the error
e.message.prepend "When updating remotes for #{remote[:importer].name}: "
raise e
end
end
end
end | ruby | def update!
ensure_remotes_directory
dirty_remotes.each do |_name, remote|
dir = workspace_of(remote)
if remote[:path] || path_enabled?(remote)
if symlink?(dir)
delete_symlink(dir)
else
FileUtils.rm_rf(dir) if File.exist?(dir)
end
end
if remote[:path]
create_symlink(remote[:path], dir)
else
rc_url = remote[:rc_url] || remote[:vault]
tag = remote[:tag].nil? ? Origen::VersionString.new(remote[:version]) : Origen::VersionString.new(remote[:tag])
version_file = dir.to_s + '/.current_version'
begin
if File.exist?("#{dir}/.initial_populate_successful")
FileUtils.rm_f(version_file) if File.exist?(version_file)
rc = RevisionControl.new remote: rc_url, local: dir
rc.send rc.remotes_method, version: prefix_tag(tag), force: true
File.open(version_file, 'w') do |f|
f.write tag
end
else
rc = RevisionControl.new remote: rc_url, local: dir
rc.send rc.remotes_method, version: prefix_tag(tag), force: true
FileUtils.touch "#{dir}/.initial_populate_successful"
File.open(version_file, 'w') do |f|
f.write tag
end
end
rescue Origen::GitError, Origen::DesignSyncError, Origen::PerforceError => e
# If Git failed in the remote, its usually easy to see what the problem is, but now *where* it is.
# This will prepend the failing remote along with the error from the revision control system,
# then rethrow the error
e.message.prepend "When updating remotes for #{remote[:importer].name}: "
raise e
end
end
end
end | [
"def",
"update!",
"ensure_remotes_directory",
"dirty_remotes",
".",
"each",
"do",
"|",
"_name",
",",
"remote",
"|",
"dir",
"=",
"workspace_of",
"(",
"remote",
")",
"if",
"remote",
"[",
":path",
"]",
"||",
"path_enabled?",
"(",
"remote",
")",
"if",
"symlink?",
"(",
"dir",
")",
"delete_symlink",
"(",
"dir",
")",
"else",
"FileUtils",
".",
"rm_rf",
"(",
"dir",
")",
"if",
"File",
".",
"exist?",
"(",
"dir",
")",
"end",
"end",
"if",
"remote",
"[",
":path",
"]",
"create_symlink",
"(",
"remote",
"[",
":path",
"]",
",",
"dir",
")",
"else",
"rc_url",
"=",
"remote",
"[",
":rc_url",
"]",
"||",
"remote",
"[",
":vault",
"]",
"tag",
"=",
"remote",
"[",
":tag",
"]",
".",
"nil?",
"?",
"Origen",
"::",
"VersionString",
".",
"new",
"(",
"remote",
"[",
":version",
"]",
")",
":",
"Origen",
"::",
"VersionString",
".",
"new",
"(",
"remote",
"[",
":tag",
"]",
")",
"version_file",
"=",
"dir",
".",
"to_s",
"+",
"'/.current_version'",
"begin",
"if",
"File",
".",
"exist?",
"(",
"\"#{dir}/.initial_populate_successful\"",
")",
"FileUtils",
".",
"rm_f",
"(",
"version_file",
")",
"if",
"File",
".",
"exist?",
"(",
"version_file",
")",
"rc",
"=",
"RevisionControl",
".",
"new",
"remote",
":",
"rc_url",
",",
"local",
":",
"dir",
"rc",
".",
"send",
"rc",
".",
"remotes_method",
",",
"version",
":",
"prefix_tag",
"(",
"tag",
")",
",",
"force",
":",
"true",
"File",
".",
"open",
"(",
"version_file",
",",
"'w'",
")",
"do",
"|",
"f",
"|",
"f",
".",
"write",
"tag",
"end",
"else",
"rc",
"=",
"RevisionControl",
".",
"new",
"remote",
":",
"rc_url",
",",
"local",
":",
"dir",
"rc",
".",
"send",
"rc",
".",
"remotes_method",
",",
"version",
":",
"prefix_tag",
"(",
"tag",
")",
",",
"force",
":",
"true",
"FileUtils",
".",
"touch",
"\"#{dir}/.initial_populate_successful\"",
"File",
".",
"open",
"(",
"version_file",
",",
"'w'",
")",
"do",
"|",
"f",
"|",
"f",
".",
"write",
"tag",
"end",
"end",
"rescue",
"Origen",
"::",
"GitError",
",",
"Origen",
"::",
"DesignSyncError",
",",
"Origen",
"::",
"PerforceError",
"=>",
"e",
"e",
".",
"message",
".",
"prepend",
"\"When updating remotes for #{remote[:importer].name}: \"",
"raise",
"e",
"end",
"end",
"end",
"end"
]
| Makes all dirty remotes clean | [
"Makes",
"all",
"dirty",
"remotes",
"clean"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/remote_manager.rb#L323-L365 | train |
Origen-SDK/origen | lib/origen/remote_manager.rb | Origen.RemoteManager.prefix_tag | def prefix_tag(tag)
tag = Origen::VersionString.new(tag)
if tag.semantic?
tag.prefixed
else
tag
end
end | ruby | def prefix_tag(tag)
tag = Origen::VersionString.new(tag)
if tag.semantic?
tag.prefixed
else
tag
end
end | [
"def",
"prefix_tag",
"(",
"tag",
")",
"tag",
"=",
"Origen",
"::",
"VersionString",
".",
"new",
"(",
"tag",
")",
"if",
"tag",
".",
"semantic?",
"tag",
".",
"prefixed",
"else",
"tag",
"end",
"end"
]
| If the supplied tag looks like a semantic version number, then make sure it has the
'v' prefix | [
"If",
"the",
"supplied",
"tag",
"looks",
"like",
"a",
"semantic",
"version",
"number",
"then",
"make",
"sure",
"it",
"has",
"the",
"v",
"prefix"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/remote_manager.rb#L385-L392 | train |
Origen-SDK/origen | lib/origen/top_level.rb | Origen.TopLevel.current_package= | def current_package=(val)
@current_package_id = case val
when ChipPackage
val.id
else
packages.include?(val) ? val : nil
end
end | ruby | def current_package=(val)
@current_package_id = case val
when ChipPackage
val.id
else
packages.include?(val) ? val : nil
end
end | [
"def",
"current_package",
"=",
"(",
"val",
")",
"@current_package_id",
"=",
"case",
"val",
"when",
"ChipPackage",
"val",
".",
"id",
"else",
"packages",
".",
"include?",
"(",
"val",
")",
"?",
"val",
":",
"nil",
"end",
"end"
]
| Use this to specify the current package option for the given SoC.
This allows different pin configurations to be specified by package. | [
"Use",
"this",
"to",
"specify",
"the",
"current",
"package",
"option",
"for",
"the",
"given",
"SoC",
"."
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/top_level.rb#L65-L72 | train |
Origen-SDK/origen | lib/origen/top_level.rb | Origen.TopLevel.packages | def packages(id = nil, _options = {})
id, options = nil, id if id.is_a?(Hash)
if id
_packages[id]
else
_packages.ids
end
end | ruby | def packages(id = nil, _options = {})
id, options = nil, id if id.is_a?(Hash)
if id
_packages[id]
else
_packages.ids
end
end | [
"def",
"packages",
"(",
"id",
"=",
"nil",
",",
"_options",
"=",
"{",
"}",
")",
"id",
",",
"options",
"=",
"nil",
",",
"id",
"if",
"id",
".",
"is_a?",
"(",
"Hash",
")",
"if",
"id",
"_packages",
"[",
"id",
"]",
"else",
"_packages",
".",
"ids",
"end",
"end"
]
| Returns an array containing the IDs of all known configurations if no ID is supplied,
otherwise returns an object representing the given package ID | [
"Returns",
"an",
"array",
"containing",
"the",
"IDs",
"of",
"all",
"known",
"configurations",
"if",
"no",
"ID",
"is",
"supplied",
"otherwise",
"returns",
"an",
"object",
"representing",
"the",
"given",
"package",
"ID"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/top_level.rb#L87-L94 | train |
Origen-SDK/origen | lib/origen/errata.rb | Origen.Errata.erratum | def erratum(id, ip_block, overview = {}, status = {}, sw_workaround = {})
_errata
@_errata[id][ip_block][status[:disposition]] = HwErratum.new(id, ip_block, overview, status, sw_workaround)
end | ruby | def erratum(id, ip_block, overview = {}, status = {}, sw_workaround = {})
_errata
@_errata[id][ip_block][status[:disposition]] = HwErratum.new(id, ip_block, overview, status, sw_workaround)
end | [
"def",
"erratum",
"(",
"id",
",",
"ip_block",
",",
"overview",
"=",
"{",
"}",
",",
"status",
"=",
"{",
"}",
",",
"sw_workaround",
"=",
"{",
"}",
")",
"_errata",
"@_errata",
"[",
"id",
"]",
"[",
"ip_block",
"]",
"[",
"status",
"[",
":disposition",
"]",
"]",
"=",
"HwErratum",
".",
"new",
"(",
"id",
",",
"ip_block",
",",
"overview",
",",
"status",
",",
"sw_workaround",
")",
"end"
]
| Define and instantiate an erratum object | [
"Define",
"and",
"instantiate",
"an",
"erratum",
"object"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/errata.rb#L11-L14 | train |
Origen-SDK/origen | lib/origen/errata.rb | Origen.Errata.errata | def errata(options = {})
options = {
id: nil,
ip_block: nil,
disposition: nil
}.update(options)
return nil if @_errata.nil?
return nil if @_errata.empty?
errata_found = Hash.new do |h, k|
h[k] = Hash.new do |hh, kk|
hh[kk] = {}
end
end
# First filter on id, then ip_block, then disposition
filter_hash(@_errata, options[:id]).each do |id, hash|
filter_hash(hash, options[:ip_block]).each do |ip_block, hash1|
filter_hash(hash1, options[:disposition]).each do |disposition, errata|
errata_found[id][ip_block][disposition] = errata
end
end
end
# Return nil if there are no errata that meet criteria
if errata_found.empty?
return nil
# If only one errata meets criteria, return that HwErratum object
elsif errata_found.size == 1
errata_found.values.first.values.first.values.first
else
return errata_found
end
end | ruby | def errata(options = {})
options = {
id: nil,
ip_block: nil,
disposition: nil
}.update(options)
return nil if @_errata.nil?
return nil if @_errata.empty?
errata_found = Hash.new do |h, k|
h[k] = Hash.new do |hh, kk|
hh[kk] = {}
end
end
# First filter on id, then ip_block, then disposition
filter_hash(@_errata, options[:id]).each do |id, hash|
filter_hash(hash, options[:ip_block]).each do |ip_block, hash1|
filter_hash(hash1, options[:disposition]).each do |disposition, errata|
errata_found[id][ip_block][disposition] = errata
end
end
end
# Return nil if there are no errata that meet criteria
if errata_found.empty?
return nil
# If only one errata meets criteria, return that HwErratum object
elsif errata_found.size == 1
errata_found.values.first.values.first.values.first
else
return errata_found
end
end | [
"def",
"errata",
"(",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"{",
"id",
":",
"nil",
",",
"ip_block",
":",
"nil",
",",
"disposition",
":",
"nil",
"}",
".",
"update",
"(",
"options",
")",
"return",
"nil",
"if",
"@_errata",
".",
"nil?",
"return",
"nil",
"if",
"@_errata",
".",
"empty?",
"errata_found",
"=",
"Hash",
".",
"new",
"do",
"|",
"h",
",",
"k",
"|",
"h",
"[",
"k",
"]",
"=",
"Hash",
".",
"new",
"do",
"|",
"hh",
",",
"kk",
"|",
"hh",
"[",
"kk",
"]",
"=",
"{",
"}",
"end",
"end",
"filter_hash",
"(",
"@_errata",
",",
"options",
"[",
":id",
"]",
")",
".",
"each",
"do",
"|",
"id",
",",
"hash",
"|",
"filter_hash",
"(",
"hash",
",",
"options",
"[",
":ip_block",
"]",
")",
".",
"each",
"do",
"|",
"ip_block",
",",
"hash1",
"|",
"filter_hash",
"(",
"hash1",
",",
"options",
"[",
":disposition",
"]",
")",
".",
"each",
"do",
"|",
"disposition",
",",
"errata",
"|",
"errata_found",
"[",
"id",
"]",
"[",
"ip_block",
"]",
"[",
"disposition",
"]",
"=",
"errata",
"end",
"end",
"end",
"if",
"errata_found",
".",
"empty?",
"return",
"nil",
"elsif",
"errata_found",
".",
"size",
"==",
"1",
"errata_found",
".",
"values",
".",
"first",
".",
"values",
".",
"first",
".",
"values",
".",
"first",
"else",
"return",
"errata_found",
"end",
"end"
]
| Returns an erratum or list of erratum that meet a specific criteria | [
"Returns",
"an",
"erratum",
"or",
"list",
"of",
"erratum",
"that",
"meet",
"a",
"specific",
"criteria"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/errata.rb#L17-L50 | train |
Origen-SDK/origen | lib/origen/errata.rb | Origen.Errata.sw_workaround | def sw_workaround(id, overview = {}, resolution = {})
_sw_workarounds
@_sw_workarounds[id] = SwErratumWorkaround.new(id, overview, resolution)
end | ruby | def sw_workaround(id, overview = {}, resolution = {})
_sw_workarounds
@_sw_workarounds[id] = SwErratumWorkaround.new(id, overview, resolution)
end | [
"def",
"sw_workaround",
"(",
"id",
",",
"overview",
"=",
"{",
"}",
",",
"resolution",
"=",
"{",
"}",
")",
"_sw_workarounds",
"@_sw_workarounds",
"[",
"id",
"]",
"=",
"SwErratumWorkaround",
".",
"new",
"(",
"id",
",",
"overview",
",",
"resolution",
")",
"end"
]
| Define and instantiate a sw_workaround object | [
"Define",
"and",
"instantiate",
"a",
"sw_workaround",
"object"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/errata.rb#L53-L56 | train |
Origen-SDK/origen | lib/origen/errata.rb | Origen.Errata.sw_workarounds | def sw_workarounds(options = {})
options = {
id: nil
}.update(options)
return nil if @_sw_workarounds.nil?
return nil if @_sw_workarounds.empty?
sw_workarounds_found = Hash.new do |h, k|
h[k] = {}
end
# filter on id
filter_hash(@_sw_workarounds, options[:id]).each do |id, workarounds|
sw_workarounds_found[id] = workarounds
end
if sw_workarounds_found.empty?
return nil
elsif sw_workarounds_found.size == 1
sw_workarounds_found.values.first # .values.first
else
return sw_workarounds_found
end
end | ruby | def sw_workarounds(options = {})
options = {
id: nil
}.update(options)
return nil if @_sw_workarounds.nil?
return nil if @_sw_workarounds.empty?
sw_workarounds_found = Hash.new do |h, k|
h[k] = {}
end
# filter on id
filter_hash(@_sw_workarounds, options[:id]).each do |id, workarounds|
sw_workarounds_found[id] = workarounds
end
if sw_workarounds_found.empty?
return nil
elsif sw_workarounds_found.size == 1
sw_workarounds_found.values.first # .values.first
else
return sw_workarounds_found
end
end | [
"def",
"sw_workarounds",
"(",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"{",
"id",
":",
"nil",
"}",
".",
"update",
"(",
"options",
")",
"return",
"nil",
"if",
"@_sw_workarounds",
".",
"nil?",
"return",
"nil",
"if",
"@_sw_workarounds",
".",
"empty?",
"sw_workarounds_found",
"=",
"Hash",
".",
"new",
"do",
"|",
"h",
",",
"k",
"|",
"h",
"[",
"k",
"]",
"=",
"{",
"}",
"end",
"filter_hash",
"(",
"@_sw_workarounds",
",",
"options",
"[",
":id",
"]",
")",
".",
"each",
"do",
"|",
"id",
",",
"workarounds",
"|",
"sw_workarounds_found",
"[",
"id",
"]",
"=",
"workarounds",
"end",
"if",
"sw_workarounds_found",
".",
"empty?",
"return",
"nil",
"elsif",
"sw_workarounds_found",
".",
"size",
"==",
"1",
"sw_workarounds_found",
".",
"values",
".",
"first",
"else",
"return",
"sw_workarounds_found",
"end",
"end"
]
| Returns a sw_workaround object with a specific id | [
"Returns",
"a",
"sw_workaround",
"object",
"with",
"a",
"specific",
"id"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/errata.rb#L59-L81 | train |
Origen-SDK/origen | lib/origen/site_config.rb | Origen.SiteConfig.add_as_highest | def add_as_highest(var, value)
# Don't want to override anything, so just shift in a dummy site config instance at the highest level and
# set the value there.
c = Config.new(path: :runtime, parent: self, values: { var.to_s => value })
configs.prepend(Config.new(path: :runtime, parent: self, values: { var.to_s => value }))
end | ruby | def add_as_highest(var, value)
# Don't want to override anything, so just shift in a dummy site config instance at the highest level and
# set the value there.
c = Config.new(path: :runtime, parent: self, values: { var.to_s => value })
configs.prepend(Config.new(path: :runtime, parent: self, values: { var.to_s => value }))
end | [
"def",
"add_as_highest",
"(",
"var",
",",
"value",
")",
"c",
"=",
"Config",
".",
"new",
"(",
"path",
":",
":runtime",
",",
"parent",
":",
"self",
",",
"values",
":",
"{",
"var",
".",
"to_s",
"=>",
"value",
"}",
")",
"configs",
".",
"prepend",
"(",
"Config",
".",
"new",
"(",
"path",
":",
":runtime",
",",
"parent",
":",
"self",
",",
"values",
":",
"{",
"var",
".",
"to_s",
"=>",
"value",
"}",
")",
")",
"end"
]
| Dynamically add a new site variable at the highest priority. | [
"Dynamically",
"add",
"a",
"new",
"site",
"variable",
"at",
"the",
"highest",
"priority",
"."
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/site_config.rb#L116-L121 | train |
Origen-SDK/origen | lib/origen/site_config.rb | Origen.SiteConfig.add_as_lowest | def add_as_lowest(var, value)
# Don't want to override anything, so just shift in a dummy site config at the lowest level and
# set the value there.
configs.append(Config.new(path: :runtime, parent: self, values: { var.to_s => value }))
end | ruby | def add_as_lowest(var, value)
# Don't want to override anything, so just shift in a dummy site config at the lowest level and
# set the value there.
configs.append(Config.new(path: :runtime, parent: self, values: { var.to_s => value }))
end | [
"def",
"add_as_lowest",
"(",
"var",
",",
"value",
")",
"configs",
".",
"append",
"(",
"Config",
".",
"new",
"(",
"path",
":",
":runtime",
",",
"parent",
":",
"self",
",",
"values",
":",
"{",
"var",
".",
"to_s",
"=>",
"value",
"}",
")",
")",
"end"
]
| Dynamically add a new site variable at the lowest priority.
Essentially, this sets a new default value. | [
"Dynamically",
"add",
"a",
"new",
"site",
"variable",
"at",
"the",
"lowest",
"priority",
".",
"Essentially",
"this",
"sets",
"a",
"new",
"default",
"value",
"."
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/site_config.rb#L126-L130 | train |
Origen-SDK/origen | lib/origen/site_config.rb | Origen.SiteConfig.vars_by_configs | def vars_by_configs
vars = {}
configs.each do |c|
vars = c.values.map { |k, v| [k, c] }.to_h.merge(vars)
end
vars
end | ruby | def vars_by_configs
vars = {}
configs.each do |c|
vars = c.values.map { |k, v| [k, c] }.to_h.merge(vars)
end
vars
end | [
"def",
"vars_by_configs",
"vars",
"=",
"{",
"}",
"configs",
".",
"each",
"do",
"|",
"c",
"|",
"vars",
"=",
"c",
".",
"values",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"[",
"k",
",",
"c",
"]",
"}",
".",
"to_h",
".",
"merge",
"(",
"vars",
")",
"end",
"vars",
"end"
]
| Gets all config variables as a hash, but the hash's values are the Config instances which defines the highest
priority of each var, instead of the var's value itself. | [
"Gets",
"all",
"config",
"variables",
"as",
"a",
"hash",
"but",
"the",
"hash",
"s",
"values",
"are",
"the",
"Config",
"instances",
"which",
"defines",
"the",
"highest",
"priority",
"of",
"each",
"var",
"instead",
"of",
"the",
"var",
"s",
"value",
"itself",
"."
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/site_config.rb#L204-L210 | train |
Origen-SDK/origen | lib/origen/site_config.rb | Origen.SiteConfig.configs! | def configs!
# This global is set when Origen is first required, it generally means that what is considered
# to be the pwd for the purposes of looking for a site_config file is the place from where the
# user invoked Origen. Otherwise if the running app switches the PWD it can lead to confusing
# behavior - this was a particular problem when testing the new app generator which switches the
# pwd to /tmp to build the new app
path = $_origen_invocation_pwd
@configs = []
# Add any site_configs from where we are currently running from, i.e. the application
# directory area
until path.root?
load_directory(path)
path = path.parent
end
# Add and any site_configs from the directory hierarchy where Ruby is installed
path = Pathname.new($LOAD_PATH.last)
until path.root?
load_directory(path)
path = path.parent
end
# Add the one from the Origen core as the lowest priority, this one defines
# the default values
load_directory(File.expand_path('../../../', __FILE__))
# Add the site_config from the user's home directory as highest priority, if it exists
# But, make sure we take the site installation's setup into account.
# That is, if user's home directories are somewhere else, make sure we use that directory to the find
# the user's overwrite file. The user can then override that if they want."
load_directory(File.expand_path(user_install_dir), prepend: true)
# Load any centralized site configs now.
centralized_site_config = find_val('centralized_site_config')
if centralized_site_config
# We know the last two site configs will exists (they are in Origen core) and that they contain the default
# values. We want the centralized config to load right after those.
@configs.insert(-3, Config.new(path: centralized_site_config, parent: self))
end
# After all configs have been populated, see if the centralized needs refreshing
@configs.each { |c| c.refresh if c.needs_refresh? }
@configs
end | ruby | def configs!
# This global is set when Origen is first required, it generally means that what is considered
# to be the pwd for the purposes of looking for a site_config file is the place from where the
# user invoked Origen. Otherwise if the running app switches the PWD it can lead to confusing
# behavior - this was a particular problem when testing the new app generator which switches the
# pwd to /tmp to build the new app
path = $_origen_invocation_pwd
@configs = []
# Add any site_configs from where we are currently running from, i.e. the application
# directory area
until path.root?
load_directory(path)
path = path.parent
end
# Add and any site_configs from the directory hierarchy where Ruby is installed
path = Pathname.new($LOAD_PATH.last)
until path.root?
load_directory(path)
path = path.parent
end
# Add the one from the Origen core as the lowest priority, this one defines
# the default values
load_directory(File.expand_path('../../../', __FILE__))
# Add the site_config from the user's home directory as highest priority, if it exists
# But, make sure we take the site installation's setup into account.
# That is, if user's home directories are somewhere else, make sure we use that directory to the find
# the user's overwrite file. The user can then override that if they want."
load_directory(File.expand_path(user_install_dir), prepend: true)
# Load any centralized site configs now.
centralized_site_config = find_val('centralized_site_config')
if centralized_site_config
# We know the last two site configs will exists (they are in Origen core) and that they contain the default
# values. We want the centralized config to load right after those.
@configs.insert(-3, Config.new(path: centralized_site_config, parent: self))
end
# After all configs have been populated, see if the centralized needs refreshing
@configs.each { |c| c.refresh if c.needs_refresh? }
@configs
end | [
"def",
"configs!",
"path",
"=",
"$_origen_invocation_pwd",
"@configs",
"=",
"[",
"]",
"until",
"path",
".",
"root?",
"load_directory",
"(",
"path",
")",
"path",
"=",
"path",
".",
"parent",
"end",
"path",
"=",
"Pathname",
".",
"new",
"(",
"$LOAD_PATH",
".",
"last",
")",
"until",
"path",
".",
"root?",
"load_directory",
"(",
"path",
")",
"path",
"=",
"path",
".",
"parent",
"end",
"load_directory",
"(",
"File",
".",
"expand_path",
"(",
"'../../../'",
",",
"__FILE__",
")",
")",
"load_directory",
"(",
"File",
".",
"expand_path",
"(",
"user_install_dir",
")",
",",
"prepend",
":",
"true",
")",
"centralized_site_config",
"=",
"find_val",
"(",
"'centralized_site_config'",
")",
"if",
"centralized_site_config",
"@configs",
".",
"insert",
"(",
"-",
"3",
",",
"Config",
".",
"new",
"(",
"path",
":",
"centralized_site_config",
",",
"parent",
":",
"self",
")",
")",
"end",
"@configs",
".",
"each",
"{",
"|",
"c",
"|",
"c",
".",
"refresh",
"if",
"c",
".",
"needs_refresh?",
"}",
"@configs",
"end"
]
| Forces a reparse of the site configs.
This will set the configs along the current path first,
then, using those values, will add a site config at the home directory. | [
"Forces",
"a",
"reparse",
"of",
"the",
"site",
"configs",
".",
"This",
"will",
"set",
"the",
"configs",
"along",
"the",
"current",
"path",
"first",
"then",
"using",
"those",
"values",
"will",
"add",
"a",
"site",
"config",
"at",
"the",
"home",
"directory",
"."
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/site_config.rb#L383-L428 | train |
Origen-SDK/origen | lib/origen/file_handler.rb | Origen.FileHandler.open_list | def open_list(file)
f = clean_path_to(file, allow_missing: true)
if f
f = File.open(f, 'r')
elsif File.exist?("#{Origen.root}/list/#{File.basename(file)}")
f = File.open("#{Origen.root}/list/#{File.basename(file)}", 'r')
elsif @last_opened_list_dir && File.exist?("#{@last_opened_list_dir}/#{file}")
f = File.open("#{@last_opened_list_dir}/#{file}", 'r')
else
fail "Could not find list file: #{file}"
end
lines = f.readlines
f.close
# Before we go save the directory of this list, this will help
# us to resolve any relative path references to other lists that
# it may contain
@last_opened_list_dir = clean_path_to(Pathname.new(f).dirname)
lines
end | ruby | def open_list(file)
f = clean_path_to(file, allow_missing: true)
if f
f = File.open(f, 'r')
elsif File.exist?("#{Origen.root}/list/#{File.basename(file)}")
f = File.open("#{Origen.root}/list/#{File.basename(file)}", 'r')
elsif @last_opened_list_dir && File.exist?("#{@last_opened_list_dir}/#{file}")
f = File.open("#{@last_opened_list_dir}/#{file}", 'r')
else
fail "Could not find list file: #{file}"
end
lines = f.readlines
f.close
# Before we go save the directory of this list, this will help
# us to resolve any relative path references to other lists that
# it may contain
@last_opened_list_dir = clean_path_to(Pathname.new(f).dirname)
lines
end | [
"def",
"open_list",
"(",
"file",
")",
"f",
"=",
"clean_path_to",
"(",
"file",
",",
"allow_missing",
":",
"true",
")",
"if",
"f",
"f",
"=",
"File",
".",
"open",
"(",
"f",
",",
"'r'",
")",
"elsif",
"File",
".",
"exist?",
"(",
"\"#{Origen.root}/list/#{File.basename(file)}\"",
")",
"f",
"=",
"File",
".",
"open",
"(",
"\"#{Origen.root}/list/#{File.basename(file)}\"",
",",
"'r'",
")",
"elsif",
"@last_opened_list_dir",
"&&",
"File",
".",
"exist?",
"(",
"\"#{@last_opened_list_dir}/#{file}\"",
")",
"f",
"=",
"File",
".",
"open",
"(",
"\"#{@last_opened_list_dir}/#{file}\"",
",",
"'r'",
")",
"else",
"fail",
"\"Could not find list file: #{file}\"",
"end",
"lines",
"=",
"f",
".",
"readlines",
"f",
".",
"close",
"@last_opened_list_dir",
"=",
"clean_path_to",
"(",
"Pathname",
".",
"new",
"(",
"f",
")",
".",
"dirname",
")",
"lines",
"end"
]
| Returns the contents of the given list file in an array, if it
can be found, if not will raise an error | [
"Returns",
"the",
"contents",
"of",
"the",
"given",
"list",
"file",
"in",
"an",
"array",
"if",
"it",
"can",
"be",
"found",
"if",
"not",
"will",
"raise",
"an",
"error"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/file_handler.rb#L44-L62 | train |
Origen-SDK/origen | lib/origen/file_handler.rb | Origen.FileHandler.clean_path_to | def clean_path_to(file, options = {})
# Allow individual calls to this method to specify additional custom load paths to consider
if options[:load_paths]
[options[:load_paths]].each do |root|
if File.exist?("#{root}/#{file}")
return Pathname.new("#{root}/#{file}")
end
end
end
if File.exist?(file)
if Pathname.new(file).absolute?
Pathname.new(file)
else
Pathname.new("#{Pathname.pwd}/#{file}")
end
# Is it a relative reference within a list file?
elsif @last_opened_list_dir && File.exist?("#{@last_opened_list_dir}/#{file}")
Pathname.new("#{@last_opened_list_dir}/#{file}")
# Is it a relative reference to the current base directory?
elsif File.exist?("#{base_directory}/#{file}")
Pathname.new("#{base_directory}/#{file}")
# Is it a path relative to Origen.root?
elsif File.exist?("#{Origen.root}/#{file}")
Pathname.new("#{Origen.root}/#{file}")
# Is it a path relative to the current directory?
elsif current_directory && File.exist?("#{current_directory}/#{file}")
Pathname.new("#{current_directory}/#{file}")
# Is it a path relative to the current plugin's Origen.root?
elsif Origen.app.plugins.current && File.exist?("#{Origen.app.plugins.current.root}/#{file}")
Pathname.new("#{Origen.app.plugins.current.root}/#{file}")
elsif options[:default_dir]
m = all_matches(file, options)
if m
Pathname.new(m)
else
if options[:allow_missing]
return nil
else
fail "Can't find: #{file}"
end
end
else
if options[:allow_missing]
return nil
else
fail "Can't find: #{file}"
end
end
end | ruby | def clean_path_to(file, options = {})
# Allow individual calls to this method to specify additional custom load paths to consider
if options[:load_paths]
[options[:load_paths]].each do |root|
if File.exist?("#{root}/#{file}")
return Pathname.new("#{root}/#{file}")
end
end
end
if File.exist?(file)
if Pathname.new(file).absolute?
Pathname.new(file)
else
Pathname.new("#{Pathname.pwd}/#{file}")
end
# Is it a relative reference within a list file?
elsif @last_opened_list_dir && File.exist?("#{@last_opened_list_dir}/#{file}")
Pathname.new("#{@last_opened_list_dir}/#{file}")
# Is it a relative reference to the current base directory?
elsif File.exist?("#{base_directory}/#{file}")
Pathname.new("#{base_directory}/#{file}")
# Is it a path relative to Origen.root?
elsif File.exist?("#{Origen.root}/#{file}")
Pathname.new("#{Origen.root}/#{file}")
# Is it a path relative to the current directory?
elsif current_directory && File.exist?("#{current_directory}/#{file}")
Pathname.new("#{current_directory}/#{file}")
# Is it a path relative to the current plugin's Origen.root?
elsif Origen.app.plugins.current && File.exist?("#{Origen.app.plugins.current.root}/#{file}")
Pathname.new("#{Origen.app.plugins.current.root}/#{file}")
elsif options[:default_dir]
m = all_matches(file, options)
if m
Pathname.new(m)
else
if options[:allow_missing]
return nil
else
fail "Can't find: #{file}"
end
end
else
if options[:allow_missing]
return nil
else
fail "Can't find: #{file}"
end
end
end | [
"def",
"clean_path_to",
"(",
"file",
",",
"options",
"=",
"{",
"}",
")",
"if",
"options",
"[",
":load_paths",
"]",
"[",
"options",
"[",
":load_paths",
"]",
"]",
".",
"each",
"do",
"|",
"root",
"|",
"if",
"File",
".",
"exist?",
"(",
"\"#{root}/#{file}\"",
")",
"return",
"Pathname",
".",
"new",
"(",
"\"#{root}/#{file}\"",
")",
"end",
"end",
"end",
"if",
"File",
".",
"exist?",
"(",
"file",
")",
"if",
"Pathname",
".",
"new",
"(",
"file",
")",
".",
"absolute?",
"Pathname",
".",
"new",
"(",
"file",
")",
"else",
"Pathname",
".",
"new",
"(",
"\"#{Pathname.pwd}/#{file}\"",
")",
"end",
"elsif",
"@last_opened_list_dir",
"&&",
"File",
".",
"exist?",
"(",
"\"#{@last_opened_list_dir}/#{file}\"",
")",
"Pathname",
".",
"new",
"(",
"\"#{@last_opened_list_dir}/#{file}\"",
")",
"elsif",
"File",
".",
"exist?",
"(",
"\"#{base_directory}/#{file}\"",
")",
"Pathname",
".",
"new",
"(",
"\"#{base_directory}/#{file}\"",
")",
"elsif",
"File",
".",
"exist?",
"(",
"\"#{Origen.root}/#{file}\"",
")",
"Pathname",
".",
"new",
"(",
"\"#{Origen.root}/#{file}\"",
")",
"elsif",
"current_directory",
"&&",
"File",
".",
"exist?",
"(",
"\"#{current_directory}/#{file}\"",
")",
"Pathname",
".",
"new",
"(",
"\"#{current_directory}/#{file}\"",
")",
"elsif",
"Origen",
".",
"app",
".",
"plugins",
".",
"current",
"&&",
"File",
".",
"exist?",
"(",
"\"#{Origen.app.plugins.current.root}/#{file}\"",
")",
"Pathname",
".",
"new",
"(",
"\"#{Origen.app.plugins.current.root}/#{file}\"",
")",
"elsif",
"options",
"[",
":default_dir",
"]",
"m",
"=",
"all_matches",
"(",
"file",
",",
"options",
")",
"if",
"m",
"Pathname",
".",
"new",
"(",
"m",
")",
"else",
"if",
"options",
"[",
":allow_missing",
"]",
"return",
"nil",
"else",
"fail",
"\"Can't find: #{file}\"",
"end",
"end",
"else",
"if",
"options",
"[",
":allow_missing",
"]",
"return",
"nil",
"else",
"fail",
"\"Can't find: #{file}\"",
"end",
"end",
"end"
]
| Returns a full path to the given file or directory, raises an error if it
can't be resolved | [
"Returns",
"a",
"full",
"path",
"to",
"the",
"given",
"file",
"or",
"directory",
"raises",
"an",
"error",
"if",
"it",
"can",
"t",
"be",
"resolved"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/file_handler.rb#L100-L148 | train |
Origen-SDK/origen | lib/origen/file_handler.rb | Origen.FileHandler.relative_to_absolute | def relative_to_absolute(path)
if Pathname.new(path).absolute?
Pathname.new(path)
else
Pathname.new("#{Pathname.pwd}/#{path}")
end
end | ruby | def relative_to_absolute(path)
if Pathname.new(path).absolute?
Pathname.new(path)
else
Pathname.new("#{Pathname.pwd}/#{path}")
end
end | [
"def",
"relative_to_absolute",
"(",
"path",
")",
"if",
"Pathname",
".",
"new",
"(",
"path",
")",
".",
"absolute?",
"Pathname",
".",
"new",
"(",
"path",
")",
"else",
"Pathname",
".",
"new",
"(",
"\"#{Pathname.pwd}/#{path}\"",
")",
"end",
"end"
]
| Returns an absolute path for the given | [
"Returns",
"an",
"absolute",
"path",
"for",
"the",
"given"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/file_handler.rb#L198-L204 | train |
Origen-SDK/origen | lib/origen/file_handler.rb | Origen.FileHandler.inject_import_path | def inject_import_path(path, options = {})
path = path.to_s unless path.is_a?(String)
if path =~ /(.*?)\/.*/
import_name = Regexp.last_match[1].downcase.to_sym
if import_name == :origen || import_name == :origen_core || Origen.app.plugins.names.include?(import_name) ||
import_name == :doc_helpers
# Special case to allow a shortcut for this common import plugin and to also handle legacy
# code from when it was called doc_helpers instead of origen_doc_helpers
if import_name == :doc_helpers
root = Origen.app(:origen_doc_helpers).root
else
unless import_name == :origen || import_name == :origen_core
root = Origen.app(import_name).root
end
end
if options[:type] == :template
if import_name == :origen || import_name == :origen_core
path.sub! 'origen', "#{Origen.top}/templates/shared"
else
path.sub! Regexp.last_match[1], "#{root}/templates/shared"
end
else
fail 'Unknown import path type!'
end
end
end
path
end | ruby | def inject_import_path(path, options = {})
path = path.to_s unless path.is_a?(String)
if path =~ /(.*?)\/.*/
import_name = Regexp.last_match[1].downcase.to_sym
if import_name == :origen || import_name == :origen_core || Origen.app.plugins.names.include?(import_name) ||
import_name == :doc_helpers
# Special case to allow a shortcut for this common import plugin and to also handle legacy
# code from when it was called doc_helpers instead of origen_doc_helpers
if import_name == :doc_helpers
root = Origen.app(:origen_doc_helpers).root
else
unless import_name == :origen || import_name == :origen_core
root = Origen.app(import_name).root
end
end
if options[:type] == :template
if import_name == :origen || import_name == :origen_core
path.sub! 'origen', "#{Origen.top}/templates/shared"
else
path.sub! Regexp.last_match[1], "#{root}/templates/shared"
end
else
fail 'Unknown import path type!'
end
end
end
path
end | [
"def",
"inject_import_path",
"(",
"path",
",",
"options",
"=",
"{",
"}",
")",
"path",
"=",
"path",
".",
"to_s",
"unless",
"path",
".",
"is_a?",
"(",
"String",
")",
"if",
"path",
"=~",
"/",
"\\/",
"/",
"import_name",
"=",
"Regexp",
".",
"last_match",
"[",
"1",
"]",
".",
"downcase",
".",
"to_sym",
"if",
"import_name",
"==",
":origen",
"||",
"import_name",
"==",
":origen_core",
"||",
"Origen",
".",
"app",
".",
"plugins",
".",
"names",
".",
"include?",
"(",
"import_name",
")",
"||",
"import_name",
"==",
":doc_helpers",
"if",
"import_name",
"==",
":doc_helpers",
"root",
"=",
"Origen",
".",
"app",
"(",
":origen_doc_helpers",
")",
".",
"root",
"else",
"unless",
"import_name",
"==",
":origen",
"||",
"import_name",
"==",
":origen_core",
"root",
"=",
"Origen",
".",
"app",
"(",
"import_name",
")",
".",
"root",
"end",
"end",
"if",
"options",
"[",
":type",
"]",
"==",
":template",
"if",
"import_name",
"==",
":origen",
"||",
"import_name",
"==",
":origen_core",
"path",
".",
"sub!",
"'origen'",
",",
"\"#{Origen.top}/templates/shared\"",
"else",
"path",
".",
"sub!",
"Regexp",
".",
"last_match",
"[",
"1",
"]",
",",
"\"#{root}/templates/shared\"",
"end",
"else",
"fail",
"'Unknown import path type!'",
"end",
"end",
"end",
"path",
"end"
]
| If the current path looks like it is a reference to an import, the
path will be replaced with the absolute path to the local import directory | [
"If",
"the",
"current",
"path",
"looks",
"like",
"it",
"is",
"a",
"reference",
"to",
"an",
"import",
"the",
"path",
"will",
"be",
"replaced",
"with",
"the",
"absolute",
"path",
"to",
"the",
"local",
"import",
"directory"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/file_handler.rb#L248-L275 | train |
Origen-SDK/origen | lib/origen/file_handler.rb | Origen.FileHandler.add_underscore_to | def add_underscore_to(file)
f = Pathname.new(file)
if f.basename.to_s =~ /^_/
file
else
"#{f.dirname}/_#{f.basename}"
end
end | ruby | def add_underscore_to(file)
f = Pathname.new(file)
if f.basename.to_s =~ /^_/
file
else
"#{f.dirname}/_#{f.basename}"
end
end | [
"def",
"add_underscore_to",
"(",
"file",
")",
"f",
"=",
"Pathname",
".",
"new",
"(",
"file",
")",
"if",
"f",
".",
"basename",
".",
"to_s",
"=~",
"/",
"/",
"file",
"else",
"\"#{f.dirname}/_#{f.basename}\"",
"end",
"end"
]
| Insert _ in file name if not present | [
"Insert",
"_",
"in",
"file",
"name",
"if",
"not",
"present"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/file_handler.rb#L284-L291 | train |
Origen-SDK/origen | lib/origen/file_handler.rb | Origen.FileHandler.sub_dir_of | def sub_dir_of(file, base = base_directory)
file = Pathname.new(file) unless file.respond_to?(:relative_path_from)
base = Pathname.new(base) unless base.respond_to?(:relative_path_from)
rel = file.relative_path_from(base)
if file.directory?
rel
else
rel.dirname
end
end | ruby | def sub_dir_of(file, base = base_directory)
file = Pathname.new(file) unless file.respond_to?(:relative_path_from)
base = Pathname.new(base) unless base.respond_to?(:relative_path_from)
rel = file.relative_path_from(base)
if file.directory?
rel
else
rel.dirname
end
end | [
"def",
"sub_dir_of",
"(",
"file",
",",
"base",
"=",
"base_directory",
")",
"file",
"=",
"Pathname",
".",
"new",
"(",
"file",
")",
"unless",
"file",
".",
"respond_to?",
"(",
":relative_path_from",
")",
"base",
"=",
"Pathname",
".",
"new",
"(",
"base",
")",
"unless",
"base",
".",
"respond_to?",
"(",
":relative_path_from",
")",
"rel",
"=",
"file",
".",
"relative_path_from",
"(",
"base",
")",
"if",
"file",
".",
"directory?",
"rel",
"else",
"rel",
".",
"dirname",
"end",
"end"
]
| Returns the sub directory of the current base directory that the
given file is in | [
"Returns",
"the",
"sub",
"directory",
"of",
"the",
"current",
"base",
"directory",
"that",
"the",
"given",
"file",
"is",
"in"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/file_handler.rb#L429-L438 | train |
Origen-SDK/origen | lib/origen/file_handler.rb | Origen.FileHandler.open_for_write | def open_for_write(path)
dir = Pathname.new(path).dirname
FileUtils.mkdir_p(dir) unless File.exist?(dir)
File.open(path, 'w') do |f|
yield f
end
end | ruby | def open_for_write(path)
dir = Pathname.new(path).dirname
FileUtils.mkdir_p(dir) unless File.exist?(dir)
File.open(path, 'w') do |f|
yield f
end
end | [
"def",
"open_for_write",
"(",
"path",
")",
"dir",
"=",
"Pathname",
".",
"new",
"(",
"path",
")",
".",
"dirname",
"FileUtils",
".",
"mkdir_p",
"(",
"dir",
")",
"unless",
"File",
".",
"exist?",
"(",
"dir",
")",
"File",
".",
"open",
"(",
"path",
",",
"'w'",
")",
"do",
"|",
"f",
"|",
"yield",
"f",
"end",
"end"
]
| Convenience method to use when you want to write to a file, this takes
care of ensuring that the directory exists prior to attempting to open
the file | [
"Convenience",
"method",
"to",
"use",
"when",
"you",
"want",
"to",
"write",
"to",
"a",
"file",
"this",
"takes",
"care",
"of",
"ensuring",
"that",
"the",
"directory",
"exists",
"prior",
"to",
"attempting",
"to",
"open",
"the",
"file"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/file_handler.rb#L443-L449 | train |
Origen-SDK/origen | lib/origen/bugs.rb | Origen.Bugs.has_bug? | def has_bug?(name, _options = {})
unless self.respond_to?(:version) && version
puts 'To test for the presence of a bug the object must implement an attribute'
puts "called 'version' which returns the IP version represented by the the object."
fail 'Version undefined!'
end
name = name.to_s.downcase.to_sym
if bugs[name]
bugs[name].present_on_version?(version)
else
false
end
end | ruby | def has_bug?(name, _options = {})
unless self.respond_to?(:version) && version
puts 'To test for the presence of a bug the object must implement an attribute'
puts "called 'version' which returns the IP version represented by the the object."
fail 'Version undefined!'
end
name = name.to_s.downcase.to_sym
if bugs[name]
bugs[name].present_on_version?(version)
else
false
end
end | [
"def",
"has_bug?",
"(",
"name",
",",
"_options",
"=",
"{",
"}",
")",
"unless",
"self",
".",
"respond_to?",
"(",
":version",
")",
"&&",
"version",
"puts",
"'To test for the presence of a bug the object must implement an attribute'",
"puts",
"\"called 'version' which returns the IP version represented by the the object.\"",
"fail",
"'Version undefined!'",
"end",
"name",
"=",
"name",
".",
"to_s",
".",
"downcase",
".",
"to_sym",
"if",
"bugs",
"[",
"name",
"]",
"bugs",
"[",
"name",
"]",
".",
"present_on_version?",
"(",
"version",
")",
"else",
"false",
"end",
"end"
]
| Returns true if the version of the IP represented by the object has the bug of the
given name | [
"Returns",
"true",
"if",
"the",
"version",
"of",
"the",
"IP",
"represented",
"by",
"the",
"object",
"has",
"the",
"bug",
"of",
"the",
"given",
"name"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/bugs.rb#L25-L37 | train |
Origen-SDK/origen | lib/origen/log.rb | Origen.Log.level= | def level=(val)
unless LEVELS.include?(val)
fail "Unknown log level, valid values are: #{LEVELS}"
end
# Map the log4r levels to our simplified 3 level system
# log4r level order is DEBUG < INFO < WARN < ERROR < FATAL
case val
when :normal
# Output everything except debug statements
console.level = Logger::INFO
# Output everything
log_files(:level=, Logger::DEBUG) unless console_only?
when :verbose
console.level = Logger::DEBUG
log_files(:level=, Logger::DEBUG) unless console_only?
when :silent
# We don't use any fatal messages, so this is effectively OFF
console.level = Logger::FATAL
log_files(:level=, Logger::DEBUG) unless console_only?
end
@level = val
end | ruby | def level=(val)
unless LEVELS.include?(val)
fail "Unknown log level, valid values are: #{LEVELS}"
end
# Map the log4r levels to our simplified 3 level system
# log4r level order is DEBUG < INFO < WARN < ERROR < FATAL
case val
when :normal
# Output everything except debug statements
console.level = Logger::INFO
# Output everything
log_files(:level=, Logger::DEBUG) unless console_only?
when :verbose
console.level = Logger::DEBUG
log_files(:level=, Logger::DEBUG) unless console_only?
when :silent
# We don't use any fatal messages, so this is effectively OFF
console.level = Logger::FATAL
log_files(:level=, Logger::DEBUG) unless console_only?
end
@level = val
end | [
"def",
"level",
"=",
"(",
"val",
")",
"unless",
"LEVELS",
".",
"include?",
"(",
"val",
")",
"fail",
"\"Unknown log level, valid values are: #{LEVELS}\"",
"end",
"case",
"val",
"when",
":normal",
"console",
".",
"level",
"=",
"Logger",
"::",
"INFO",
"log_files",
"(",
":level=",
",",
"Logger",
"::",
"DEBUG",
")",
"unless",
"console_only?",
"when",
":verbose",
"console",
".",
"level",
"=",
"Logger",
"::",
"DEBUG",
"log_files",
"(",
":level=",
",",
"Logger",
"::",
"DEBUG",
")",
"unless",
"console_only?",
"when",
":silent",
"console",
".",
"level",
"=",
"Logger",
"::",
"FATAL",
"log_files",
"(",
":level=",
",",
"Logger",
"::",
"DEBUG",
")",
"unless",
"console_only?",
"end",
"@level",
"=",
"val",
"end"
]
| Set the logger level, for valid values see LEVELS | [
"Set",
"the",
"logger",
"level",
"for",
"valid",
"values",
"see",
"LEVELS"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/log.rb#L54-L76 | train |
Origen-SDK/origen | lib/origen/log.rb | Origen.Log.log_files | def log_files(method, *args)
# When running remotely on an LSF client, the LSF manager will capture STDOUT (i.e. the console log output)
# and save it to a log file.
# Don't write to the last log file in that case because we would have multiple processes all vying to
# write to it at the same time.
last_file.send(method, *args) unless Origen.running_remotely?
@job_file.send(method, *args) if @job_file
end | ruby | def log_files(method, *args)
# When running remotely on an LSF client, the LSF manager will capture STDOUT (i.e. the console log output)
# and save it to a log file.
# Don't write to the last log file in that case because we would have multiple processes all vying to
# write to it at the same time.
last_file.send(method, *args) unless Origen.running_remotely?
@job_file.send(method, *args) if @job_file
end | [
"def",
"log_files",
"(",
"method",
",",
"*",
"args",
")",
"last_file",
".",
"send",
"(",
"method",
",",
"*",
"args",
")",
"unless",
"Origen",
".",
"running_remotely?",
"@job_file",
".",
"send",
"(",
"method",
",",
"*",
"args",
")",
"if",
"@job_file",
"end"
]
| Sends the given method and arguments to all file logger instances | [
"Sends",
"the",
"given",
"method",
"and",
"arguments",
"to",
"all",
"file",
"logger",
"instances"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/log.rb#L332-L339 | train |
Origen-SDK/origen | lib/origen/pins.rb | Origen.Pins.pin_pattern_order | def pin_pattern_order(*pin_ids)
if pin_ids.last.is_a?(Hash)
options = pin_ids.pop
else
options = {}
end
pin_ids.each do |id|
if pin_aliases[id]
Origen.app.pin_names[pin_aliases[id].first] = id
id = pin_aliases[id].first
end
Origen.app.pin_pattern_order << id
end
Origen.app.pin_pattern_order << options unless options.empty?
end | ruby | def pin_pattern_order(*pin_ids)
if pin_ids.last.is_a?(Hash)
options = pin_ids.pop
else
options = {}
end
pin_ids.each do |id|
if pin_aliases[id]
Origen.app.pin_names[pin_aliases[id].first] = id
id = pin_aliases[id].first
end
Origen.app.pin_pattern_order << id
end
Origen.app.pin_pattern_order << options unless options.empty?
end | [
"def",
"pin_pattern_order",
"(",
"*",
"pin_ids",
")",
"if",
"pin_ids",
".",
"last",
".",
"is_a?",
"(",
"Hash",
")",
"options",
"=",
"pin_ids",
".",
"pop",
"else",
"options",
"=",
"{",
"}",
"end",
"pin_ids",
".",
"each",
"do",
"|",
"id",
"|",
"if",
"pin_aliases",
"[",
"id",
"]",
"Origen",
".",
"app",
".",
"pin_names",
"[",
"pin_aliases",
"[",
"id",
"]",
".",
"first",
"]",
"=",
"id",
"id",
"=",
"pin_aliases",
"[",
"id",
"]",
".",
"first",
"end",
"Origen",
".",
"app",
".",
"pin_pattern_order",
"<<",
"id",
"end",
"Origen",
".",
"app",
".",
"pin_pattern_order",
"<<",
"options",
"unless",
"options",
".",
"empty?",
"end"
]
| Specify the order that pins will appear in the output pattern, unspecified
pins will appear in an arbitrary order at the end
API v2, deprecated | [
"Specify",
"the",
"order",
"that",
"pins",
"will",
"appear",
"in",
"the",
"output",
"pattern",
"unspecified",
"pins",
"will",
"appear",
"in",
"an",
"arbitrary",
"order",
"at",
"the",
"end"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/pins.rb#L323-L337 | train |
Origen-SDK/origen | lib/origen/pins.rb | Origen.Pins.all_power_pins | def all_power_pins(id = nil, _options = {}, &_block)
if id
pin = Origen.pin_bank.find(id, ignore_context: true, power_pin: true)
else
Origen.pin_bank.all_power_pins
end
end | ruby | def all_power_pins(id = nil, _options = {}, &_block)
if id
pin = Origen.pin_bank.find(id, ignore_context: true, power_pin: true)
else
Origen.pin_bank.all_power_pins
end
end | [
"def",
"all_power_pins",
"(",
"id",
"=",
"nil",
",",
"_options",
"=",
"{",
"}",
",",
"&",
"_block",
")",
"if",
"id",
"pin",
"=",
"Origen",
".",
"pin_bank",
".",
"find",
"(",
"id",
",",
"ignore_context",
":",
"true",
",",
"power_pin",
":",
"true",
")",
"else",
"Origen",
".",
"pin_bank",
".",
"all_power_pins",
"end",
"end"
]
| Equivalent to the all_pins method but considers power pins rather than regular pins | [
"Equivalent",
"to",
"the",
"all_pins",
"method",
"but",
"considers",
"power",
"pins",
"rather",
"than",
"regular",
"pins"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/pins.rb#L552-L558 | train |
Origen-SDK/origen | lib/origen/pins.rb | Origen.Pins.all_other_pins | def all_other_pins(id = nil, _options = {}, &_block)
if id
pin = Origen.pin_bank.find(id, ignore_context: true, other_pin: true)
else
Origen.pin_bank.all_other_pins
end
end | ruby | def all_other_pins(id = nil, _options = {}, &_block)
if id
pin = Origen.pin_bank.find(id, ignore_context: true, other_pin: true)
else
Origen.pin_bank.all_other_pins
end
end | [
"def",
"all_other_pins",
"(",
"id",
"=",
"nil",
",",
"_options",
"=",
"{",
"}",
",",
"&",
"_block",
")",
"if",
"id",
"pin",
"=",
"Origen",
".",
"pin_bank",
".",
"find",
"(",
"id",
",",
"ignore_context",
":",
"true",
",",
"other_pin",
":",
"true",
")",
"else",
"Origen",
".",
"pin_bank",
".",
"all_other_pins",
"end",
"end"
]
| Equivalent to the all_pins method but considers other pins rather than regular pins | [
"Equivalent",
"to",
"the",
"all_pins",
"method",
"but",
"considers",
"other",
"pins",
"rather",
"than",
"regular",
"pins"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/pins.rb#L570-L576 | train |
Origen-SDK/origen | lib/origen/pins.rb | Origen.Pins.power_pins | def power_pins(id = nil, options = {}, &block)
id, options = nil, id if id.is_a?(Hash)
options = {
power_pin: true
}.merge(options)
pins(id, options, &block)
end | ruby | def power_pins(id = nil, options = {}, &block)
id, options = nil, id if id.is_a?(Hash)
options = {
power_pin: true
}.merge(options)
pins(id, options, &block)
end | [
"def",
"power_pins",
"(",
"id",
"=",
"nil",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"id",
",",
"options",
"=",
"nil",
",",
"id",
"if",
"id",
".",
"is_a?",
"(",
"Hash",
")",
"options",
"=",
"{",
"power_pin",
":",
"true",
"}",
".",
"merge",
"(",
"options",
")",
"pins",
"(",
"id",
",",
"options",
",",
"&",
"block",
")",
"end"
]
| Equivalent to the pins method but considers power pins rather than regular pins | [
"Equivalent",
"to",
"the",
"pins",
"method",
"but",
"considers",
"power",
"pins",
"rather",
"than",
"regular",
"pins"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/pins.rb#L734-L740 | train |
Origen-SDK/origen | lib/origen/pins.rb | Origen.Pins.ground_pins | def ground_pins(id = nil, options = {}, &block)
id, options = nil, id if id.is_a?(Hash)
options = {
ground_pin: true
}.merge(options)
pins(id, options, &block)
end | ruby | def ground_pins(id = nil, options = {}, &block)
id, options = nil, id if id.is_a?(Hash)
options = {
ground_pin: true
}.merge(options)
pins(id, options, &block)
end | [
"def",
"ground_pins",
"(",
"id",
"=",
"nil",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"id",
",",
"options",
"=",
"nil",
",",
"id",
"if",
"id",
".",
"is_a?",
"(",
"Hash",
")",
"options",
"=",
"{",
"ground_pin",
":",
"true",
"}",
".",
"merge",
"(",
"options",
")",
"pins",
"(",
"id",
",",
"options",
",",
"&",
"block",
")",
"end"
]
| Equivalent to the pins method but considers ground pins rather than regular pins | [
"Equivalent",
"to",
"the",
"pins",
"method",
"but",
"considers",
"ground",
"pins",
"rather",
"than",
"regular",
"pins"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/pins.rb#L744-L750 | train |
Origen-SDK/origen | lib/origen/pins.rb | Origen.Pins.other_pins | def other_pins(id = nil, options = {}, &block)
id, options = nil, id if id.is_a?(Hash)
options = {
other_pin: true
}.merge(options)
pins(id, options, &block)
end | ruby | def other_pins(id = nil, options = {}, &block)
id, options = nil, id if id.is_a?(Hash)
options = {
other_pin: true
}.merge(options)
pins(id, options, &block)
end | [
"def",
"other_pins",
"(",
"id",
"=",
"nil",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"id",
",",
"options",
"=",
"nil",
",",
"id",
"if",
"id",
".",
"is_a?",
"(",
"Hash",
")",
"options",
"=",
"{",
"other_pin",
":",
"true",
"}",
".",
"merge",
"(",
"options",
")",
"pins",
"(",
"id",
",",
"options",
",",
"&",
"block",
")",
"end"
]
| Equivalent to the pins method but considers other pins rather than regular pins | [
"Equivalent",
"to",
"the",
"pins",
"method",
"but",
"considers",
"other",
"pins",
"rather",
"than",
"regular",
"pins"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/pins.rb#L754-L760 | train |
Origen-SDK/origen | lib/origen/pins.rb | Origen.Pins.virtual_pins | def virtual_pins(id = nil, options = {}, &block)
id, options = nil, id if id.is_a?(Hash)
options = {
virtual_pin: true
}.merge(options)
pins(id, options, &block)
end | ruby | def virtual_pins(id = nil, options = {}, &block)
id, options = nil, id if id.is_a?(Hash)
options = {
virtual_pin: true
}.merge(options)
pins(id, options, &block)
end | [
"def",
"virtual_pins",
"(",
"id",
"=",
"nil",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"id",
",",
"options",
"=",
"nil",
",",
"id",
"if",
"id",
".",
"is_a?",
"(",
"Hash",
")",
"options",
"=",
"{",
"virtual_pin",
":",
"true",
"}",
".",
"merge",
"(",
"options",
")",
"pins",
"(",
"id",
",",
"options",
",",
"&",
"block",
")",
"end"
]
| Equivalent to the pins method but considers virtual pins rather than regular pins | [
"Equivalent",
"to",
"the",
"pins",
"method",
"but",
"considers",
"virtual",
"pins",
"rather",
"than",
"regular",
"pins"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/pins.rb#L764-L770 | train |
Origen-SDK/origen | lib/origen/pins.rb | Origen.Pins.delete_pin | def delete_pin(id, options = {})
id = id.to_sym
# Check if this is a Pin or a PinGroup
if pin_groups.key? id
Origen.pin_bank.delete_pingroup(Origen.pin_bank.find_pin_group(id, options))
elsif pins(id).class.to_s.match(/Pin/)
Origen.pin_bank.delete_pin(Origen.pin_bank.find(id, options))
else
fail "Error: the object #{id} you tried to delete is not a pin or pingroup"
end
end | ruby | def delete_pin(id, options = {})
id = id.to_sym
# Check if this is a Pin or a PinGroup
if pin_groups.key? id
Origen.pin_bank.delete_pingroup(Origen.pin_bank.find_pin_group(id, options))
elsif pins(id).class.to_s.match(/Pin/)
Origen.pin_bank.delete_pin(Origen.pin_bank.find(id, options))
else
fail "Error: the object #{id} you tried to delete is not a pin or pingroup"
end
end | [
"def",
"delete_pin",
"(",
"id",
",",
"options",
"=",
"{",
"}",
")",
"id",
"=",
"id",
".",
"to_sym",
"if",
"pin_groups",
".",
"key?",
"id",
"Origen",
".",
"pin_bank",
".",
"delete_pingroup",
"(",
"Origen",
".",
"pin_bank",
".",
"find_pin_group",
"(",
"id",
",",
"options",
")",
")",
"elsif",
"pins",
"(",
"id",
")",
".",
"class",
".",
"to_s",
".",
"match",
"(",
"/",
"/",
")",
"Origen",
".",
"pin_bank",
".",
"delete_pin",
"(",
"Origen",
".",
"pin_bank",
".",
"find",
"(",
"id",
",",
"options",
")",
")",
"else",
"fail",
"\"Error: the object #{id} you tried to delete is not a pin or pingroup\"",
"end",
"end"
]
| Delete any pin or pin group. If arg is a pin then delete the pin and any instances
of it in any pin groups | [
"Delete",
"any",
"pin",
"or",
"pin",
"group",
".",
"If",
"arg",
"is",
"a",
"pin",
"then",
"delete",
"the",
"pin",
"and",
"any",
"instances",
"of",
"it",
"in",
"any",
"pin",
"groups"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/pins.rb#L779-L789 | train |
Origen-SDK/origen | lib/origen/global_methods.rb | Origen.GlobalMethods.render | def render(*args, &block)
if $_compiler_stack && $_compiler_stack.last
$_compiler_stack.last.render(*args, &block)
else
Origen.generator.compiler.render(*args, &block)
end
end | ruby | def render(*args, &block)
if $_compiler_stack && $_compiler_stack.last
$_compiler_stack.last.render(*args, &block)
else
Origen.generator.compiler.render(*args, &block)
end
end | [
"def",
"render",
"(",
"*",
"args",
",",
"&",
"block",
")",
"if",
"$_compiler_stack",
"&&",
"$_compiler_stack",
".",
"last",
"$_compiler_stack",
".",
"last",
".",
"render",
"(",
"*",
"args",
",",
"&",
"block",
")",
"else",
"Origen",
".",
"generator",
".",
"compiler",
".",
"render",
"(",
"*",
"args",
",",
"&",
"block",
")",
"end",
"end"
]
| Render an ERB template | [
"Render",
"an",
"ERB",
"template"
]
| f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac | https://github.com/Origen-SDK/origen/blob/f05e9dd190fcb90284084ba6e2bd4b0fe0c7f4ac/lib/origen/global_methods.rb#L33-L39 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.