Class: Bricolage::ResolvedVariables
- Inherits:
-
Object
- Object
- Bricolage::ResolvedVariables
- Defined in:
- lib/bricolage/variables.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](name) ⇒ Object
- #add(var) ⇒ Object
- #bind_declarations(decls) ⇒ Object
- #bound?(name) ⇒ Boolean
- #each_variable(&block) ⇒ Object
- #expand(str) ⇒ Object
- #freeze ⇒ Object
-
#initialize ⇒ ResolvedVariables
constructor
A new instance of ResolvedVariables.
- #inspect ⇒ Object
- #keys ⇒ Object
- #resolve_update(unresolved) ⇒ Object
- #resolved? ⇒ Boolean
Constructor Details
#initialize ⇒ ResolvedVariables
Returns a new instance of ResolvedVariables.
121 122 123 |
# File 'lib/bricolage/variables.rb', line 121 def initialize @vars = {} end |
Class Method Details
.define ⇒ Object
114 115 116 117 118 119 |
# File 'lib/bricolage/variables.rb', line 114 def ResolvedVariables.define new.tap {|vars| yield vars vars.freeze } end |
Instance Method Details
#[](name) ⇒ Object
154 155 156 157 |
# File 'lib/bricolage/variables.rb', line 154 def [](name) var = @vars[name.to_s] or raise ParameterError, "undefined parameter: #{name}" var.value end |
#add(var) ⇒ Object
138 139 140 141 |
# File 'lib/bricolage/variables.rb', line 138 def add(var) raise "[BUG] unresolved variable: #{var.name}" unless var.resolved? @vars[var.name] = var end |
#bind_declarations(decls) ⇒ Object
171 172 173 174 175 176 177 |
# File 'lib/bricolage/variables.rb', line 171 def bind_declarations(decls) decls.each do |decl| unless bound?(decl.name) raise ParameterError, "script parameter not given: #{decl.name}" end end end |
#bound?(name) ⇒ Boolean
150 151 152 |
# File 'lib/bricolage/variables.rb', line 150 def bound?(name) @vars.key?(name.to_s) end |
#each_variable(&block) ⇒ Object
163 164 165 |
# File 'lib/bricolage/variables.rb', line 163 def each_variable(&block) @vars.each_value(&block) end |
#expand(str) ⇒ Object
167 168 169 |
# File 'lib/bricolage/variables.rb', line 167 def (str) Variable.(str) {|name| self[name] } end |
#freeze ⇒ Object
133 134 135 136 |
# File 'lib/bricolage/variables.rb', line 133 def freeze @vars.freeze super end |
#inspect ⇒ Object
125 126 127 |
# File 'lib/bricolage/variables.rb', line 125 def inspect "\#<#{self.class} #{@vars.inspect}>" end |
#keys ⇒ Object
159 160 161 |
# File 'lib/bricolage/variables.rb', line 159 def keys @vars.keys end |
#resolve_update(unresolved) ⇒ Object
143 144 145 146 147 148 |
# File 'lib/bricolage/variables.rb', line 143 def resolve_update(unresolved) raise "[BUG] already resolved variables given" if unresolved.resolved? unresolved.resolve_with(self).each_variable do |var| add var end end |
#resolved? ⇒ Boolean
129 130 131 |
# File 'lib/bricolage/variables.rb', line 129 def resolved? true end |