Class: Origen::Parameters::Set

Inherits:
Hash show all
Defined in:
lib/origen/parameters/set.rb

Constant Summary collapse

OVERRIDE_HASH_METHODS =

Allow these parameter names to be valid. When used, they will override the methods of the same name provided by the Hash class.

[:min, :max]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

#filter, #ids, #intersect?, #intersections, #longest_key, #longest_value, #recursive_find_by_key, #update_common

Constructor Details

#initialize(options = {}) ⇒ Set

Returns a new instance of Set



12
13
14
15
16
17
18
# File 'lib/origen/parameters/set.rb', line 12

def initialize(options = {})
  if options[:top_level]
    @top_level = self
    @path = ''
    @owner = options[:owner]
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/origen/parameters/set.rb', line 49

def method_missing(method, *args, &block)
  if defining?
    if args.length == 0
      self[method] ||= new_subset(method)
    elsif args.length > 1
      super
    else
      m = method.to_s.sub('=', '').to_sym
      self[m] = args.first
    end
  else
    if args.length != 0
      super
    else
      val = self[method]
      if !val
        super
      else
        if val.is_a?(Set)
          val
        else
          if live?
            Live.new(owner: owner, path: path, name: method)
          else
            if val.is_a?(Proc)
              val.call(*args)
            else
              val
            end
          end
        end
      end
    end
  end
end

Instance Attribute Details

#nameObject

Returns the value of attribute name



5
6
7
# File 'lib/origen/parameters/set.rb', line 5

def name
  @name
end

#pathObject

Returns the value of attribute path



6
7
8
# File 'lib/origen/parameters/set.rb', line 6

def path
  @path
end

#top_levelObject

Returns the value of attribute top_level



4
5
6
# File 'lib/origen/parameters/set.rb', line 4

def top_level
  @top_level
end

Instance Method Details

#[](key) ⇒ Object



105
106
107
108
# File 'lib/origen/parameters/set.rb', line 105

def [](key)
  val = super
  val.is_a?(Proc) ? val.call : val
end

#available_contextsObject Also known as: contexts



33
34
35
# File 'lib/origen/parameters/set.rb', line 33

def available_contexts
  owner._parameter_sets.keys
end

#contextObject Also known as: current_context

Returns the current parameter context



28
29
30
# File 'lib/origen/parameters/set.rb', line 28

def context
  owner._parameter_current
end

#copy_defaults_from(set) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/origen/parameters/set.rb', line 38

def copy_defaults_from(set)
  set.each do |name, val|
    if val.is_a?(Set)
      self[name] = new_subset(name)
      self[name].copy_defaults_from(val)
    else
      self[name] = val
    end
  end
end

#define(parent = nil) {|_self, parent| ... } ⇒ Object

Yields:

  • (_self, parent)

Yield Parameters:



20
21
22
23
24
25
# File 'lib/origen/parameters/set.rb', line 20

def define(parent = nil, &_block)
  @defining = true
  yield self, parent
  @defining = false
  finalize
end

#defining?Boolean

Returns:

  • (Boolean)


116
117
118
119
120
121
122
# File 'lib/origen/parameters/set.rb', line 116

def defining?
  if top_level?
    @defining
  else
    top_level.defining?
  end
end

#eachObject



95
96
97
98
99
100
101
102
103
# File 'lib/origen/parameters/set.rb', line 95

def each
  super do |key, val|
    if val.is_a?(Proc)
      yield key, val.call
    else
      yield key, val
    end
  end
end

#finalizeObject



136
137
138
139
# File 'lib/origen/parameters/set.rb', line 136

def finalize
  freeze
  each { |_name, val| val.finalize if val.is_a? Set }
end

#liveObject



157
158
159
160
# File 'lib/origen/parameters/set.rb', line 157

def live
  owner._request_live_parameter
  self
end

#live?Boolean

Returns:

  • (Boolean)


153
154
155
# File 'lib/origen/parameters/set.rb', line 153

def live?
  owner._live_parameter_requested?
end

#new_subset(name) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
# File 'lib/origen/parameters/set.rb', line 141

def new_subset(name)
  set = Set.new
  set.name = name
  set.top_level = top_level
  if path == ''
    set.path = name.to_s
  else
    set.path = "#{path}.#{name}"
  end
  set
end

#ownerObject



124
125
126
127
128
129
130
# File 'lib/origen/parameters/set.rb', line 124

def owner
  if top_level?
    @owner
  else
    top_level.owner
  end
end

#test(*args, &block) ⇒ Object

Test seems to be some kind of reserved word, that doesn't trigger the method_missing, so re-defining it here to allow a param group called 'test'



112
113
114
# File 'lib/origen/parameters/set.rb', line 112

def test(*args, &block)
  method_missing(:test, *args, &block)
end

#to_flat_hash(options = {}) ⇒ Object



162
163
164
165
166
167
# File 'lib/origen/parameters/set.rb', line 162

def to_flat_hash(options = {})
  options = {
    delimiter: '.'
  }.update(options)
  flatten_params(self, options[:delimiter]).first
end

#top_level?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/origen/parameters/set.rb', line 132

def top_level?
  top_level == self
end