Class: BlocklyInterpreter::ProgramCache

Inherits:
Object
  • Object
show all
Includes:
MonitorMixin
Defined in:
lib/blockly_interpreter/program_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ ProgramCache

Returns a new instance of ProgramCache.



8
9
10
11
12
# File 'lib/blockly_interpreter/program_cache.rb', line 8

def initialize(parser)
  @parser = parser
  @cache = {}
  super()
end

Instance Attribute Details

#parserObject (readonly)

Returns the value of attribute parser.



6
7
8
# File 'lib/blockly_interpreter/program_cache.rb', line 6

def parser
  @parser
end

Instance Method Details

#load_program(xml) ⇒ Object



14
15
16
17
18
# File 'lib/blockly_interpreter/program_cache.rb', line 14

def load_program(xml)
  synchronize do
    @cache[Digest::SHA1.hexdigest(xml || '')] ||= @parser.parse(xml)
  end
end