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]
- OVERRIDE_METHODS =
Allow these parameter names to be valid. When used, they will override the methods of the same name provided by another class.
[:chain]
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.
16
17
18
19
20
21
22
|
# File 'lib/origen/parameters/set.rb', line 16
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
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
84
85
86
87
|
# File 'lib/origen/parameters/set.rb', line 53
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
if !key?(method)
nil
else
val = self[method]
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
Returns the value of attribute name.
5
6
7
|
# File 'lib/origen/parameters/set.rb', line 5
def name
@name
end
|
Returns the value of attribute path.
6
7
8
|
# File 'lib/origen/parameters/set.rb', line 6
def path
@path
end
|
#top_level ⇒ Object
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
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_contexts ⇒ Object
Also known as:
contexts
37
38
39
|
# File 'lib/origen/parameters/set.rb', line 37
def available_contexts
owner._parameter_sets.keys
end
|
#context ⇒ Object
Also known as:
current_context
Returns the current parameter context
32
33
34
|
# File 'lib/origen/parameters/set.rb', line 32
def context
owner._parameter_current
end
|
#copy_defaults_from(set) ⇒ Object
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/origen/parameters/set.rb', line 42
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
24
25
26
27
28
29
|
# File 'lib/origen/parameters/set.rb', line 24
def define(parent = nil, &_block)
@defining = true
yield self, parent
@defining = false
finalize unless Origen::Parameters.transaction_open
end
|
#defining? ⇒ Boolean
116
117
118
119
120
121
122
123
124
|
# File 'lib/origen/parameters/set.rb', line 116
def defining?
return true if Origen::Parameters.transaction_open
if top_level?
@defining
else
top_level.defining?
end
end
|
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
|
138
139
140
141
|
# File 'lib/origen/parameters/set.rb', line 138
def finalize
freeze
each { |_name, val| val.finalize if val.is_a? Set }
end
|
159
160
161
162
|
# File 'lib/origen/parameters/set.rb', line 159
def live
owner._request_live_parameter
self
end
|
#live? ⇒ Boolean
155
156
157
|
# File 'lib/origen/parameters/set.rb', line 155
def live?
owner._live_parameter_requested?
end
|
#new_subset(name) ⇒ Object
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/origen/parameters/set.rb', line 143
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
|
126
127
128
129
130
131
132
|
# File 'lib/origen/parameters/set.rb', line 126
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
164
165
166
167
168
169
|
# File 'lib/origen/parameters/set.rb', line 164
def to_flat_hash(options = {})
options = {
delimiter: '.'
}.update(options)
flatten_params(self, options[:delimiter]).first
end
|
#top_level? ⇒ Boolean
134
135
136
|
# File 'lib/origen/parameters/set.rb', line 134
def top_level?
top_level == self
end
|