Class: Bricolage::ResolvedVariables

Inherits:
Object
  • Object
show all
Defined in:
lib/bricolage/variables.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResolvedVariables

Returns a new instance of ResolvedVariables.



121
122
123
# File 'lib/bricolage/variables.rb', line 121

def initialize
  @vars = {}
end

Class Method Details

.defineObject



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

Returns:

  • (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 expand(str)
  Variable.expand_string(str) {|name| self[name] }
end

#freezeObject



133
134
135
136
# File 'lib/bricolage/variables.rb', line 133

def freeze
  @vars.freeze
  super
end

#inspectObject



125
126
127
# File 'lib/bricolage/variables.rb', line 125

def inspect
  "\#<#{self.class} #{@vars.inspect}>"
end

#keysObject



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

Returns:

  • (Boolean)


129
130
131
# File 'lib/bricolage/variables.rb', line 129

def resolved?
  true
end