Class: IdStore
- Inherits:
-
Object
- Object
- IdStore
- Defined in:
- lib/ea_support/id_store.rb
Instance Method Summary collapse
- #idHash ⇒ Object
-
#initialize(fileName = nil) ⇒ IdStore
constructor
A new instance of IdStore.
- #load ⇒ Object
- #store ⇒ Object
Constructor Details
#initialize(fileName = nil) ⇒ IdStore
Returns a new instance of IdStore.
4 5 6 7 8 9 10 11 |
# File 'lib/ea_support/id_store.rb', line 4 def initialize(fileName=nil) if fileName raise "Base directory does not exist: #{File.dirname(fileName)}" \ unless File.exist?(File.dirname(fileName)) @idsFileName = fileName end @idHash = nil end |
Instance Method Details
#idHash ⇒ Object
13 14 15 16 |
# File 'lib/ea_support/id_store.rb', line 13 def idHash load unless @idHash @idHash end |
#load ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/ea_support/id_store.rb', line 18 def load if @idsFileName && File.exist?(@idsFileName) @idHash = YAML.load_file(@idsFileName) || {} else @idHash = {} end end |
#store ⇒ Object
26 27 28 29 30 31 |
# File 'lib/ea_support/id_store.rb', line 26 def store return unless @idsFileName File.open(@idsFileName,"w") do |f| YAML.dump(@idHash, f) end end |