Class: Germinate::Librarian::VariableStore

Inherits:
OrderedHash
  • Object
show all
Defined in:
lib/germinate/librarian.rb

Instance Method Summary collapse

Constructor Details

#initialize(librarian) ⇒ VariableStore

Returns a new instance of VariableStore.



14
15
16
17
# File 'lib/germinate/librarian.rb', line 14

def initialize(librarian)
  super()
  @librarian = librarian
end

Instance Method Details

#[]=(key, value) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/germinate/librarian.rb', line 19

def []=(key, value)
  if key?(key)
    variable = fetch(key)
    variable.replace(value.to_s)
    variable.update_source_line!(@librarian.comment_prefix)
  else
    variable = 
      case value
      when Germinate::Variable
        value
      else
        line_number = @librarian.lines.length + 1
        line        = ""
        Germinate::Variable.new(
          key, value, line, @librarian.source_path, line_number)
      end
    variable.update_source_line!(@librarian.comment_prefix)
    store(key, variable)
    @librarian.log.debug "Appending #{variable.line.inspect} to lines"
    @librarian.lines << variable.line
  end
  @librarian.updated = true
end