Module: Origen::Parameters

Extended by:
ActiveSupport::Concern
Defined in:
lib/origen/parameters.rb,
lib/origen/parameters/set.rb,
lib/origen/parameters/live.rb,
lib/origen/parameters/missing.rb

Defined Under Namespace

Modules: ClassMethods Classes: Live, Missing, Set

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#currentObject

Returns the value of attribute current.



9
10
11
# File 'lib/origen/parameters.rb', line 9

def current
  @current
end

Instance Method Details

#_live_parameter_requested?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


109
110
111
# File 'lib/origen/parameters.rb', line 109

def _live_parameter_requested?
  @_live_parameter_requested
end

#_parameter_currentObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/origen/parameters.rb', line 85

def _parameter_current
  if path = self.class.parameters_context
    case path
    when :top, :dut
      Origen.top_level._parameter_current
    else
      eval(path)._parameter_current
    end
  else
    @_parameter_current || :default
  end
end

#_parameter_setsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



99
100
101
# File 'lib/origen/parameters.rb', line 99

def _parameter_sets
  @_parameter_sets ||= {}
end

#_request_live_parameterObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



104
105
106
# File 'lib/origen/parameters.rb', line 104

def _request_live_parameter
  @_live_parameter_requested = true
end

#define_params(name, options = {}, &block) ⇒ Object Also known as: define_parameters



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/origen/parameters.rb', line 28

def define_params(name, options = {}, &block)
  if _parameter_sets[name]
    fail 'Parameter sets cannot be re-opened once originally defined!'
  else
    _parameter_sets[name] = Set.new(top_level: true, owner: self)
    if options[:inherit]
      kontext = _validate_parameter_set_name(options[:inherit])
      parent = kontext[:obj]._parameter_sets[kontext[:context]]
      _parameter_sets[name].copy_defaults_from(parent)
      _parameter_sets[name].define(parent, &block)
    else
      _parameter_sets[name].define(&block)
    end
  end
end

#has_params?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/origen/parameters.rb', line 68

def has_params?
  _parameter_sets.empty? ? false : true
end

#param?(name) ⇒ Boolean

Return value of param if it exists, nil otherwise.

Returns:

  • (Boolean)


73
74
75
76
77
78
79
80
81
82
# File 'lib/origen/parameters.rb', line 73

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

#params(context = nil) ⇒ Object Also known as: parameters



52
53
54
55
56
# File 'lib/origen/parameters.rb', line 52

def params(context = nil)
  @_live_parameter_requested = false
  context ||= _parameter_current
  _parameter_sets[context] || Missing.new(owner: self)
end

#params=(name) ⇒ Object Also known as: parameters=



59
60
61
62
63
64
65
# File 'lib/origen/parameters.rb', line 59

def params=(name)
  # Don't validate on setting this as this object could be used to set
  # the context on some other object, therefore validate later if someone tries
  # to access the params on this object
  # _validate_parameter_set_name(name)
  @_parameter_current = name
end

#with_params(name, _options = {}) ⇒ Object



45
46
47
48
49
50
# File 'lib/origen/parameters.rb', line 45

def with_params(name, _options = {})
  orig = _parameter_current
  self.params = name
  yield
  self.params = orig
end