Class: RailsSpotlight::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_spotlight/storage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Storage

Returns a new instance of Storage.



7
8
9
# File 'lib/rails_spotlight/storage.rb', line 7

def initialize(key)
  @key = key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/rails_spotlight/storage.rb', line 5

def key
  @key
end

Instance Method Details

#readObject



18
19
20
21
# File 'lib/rails_spotlight/storage.rb', line 18

def read
  # avoid FileNotFound error
  File.exist?(json_file) ? File.read(json_file) : '[]'
end

#write(value) ⇒ Object



11
12
13
14
15
16
# File 'lib/rails_spotlight/storage.rb', line 11

def write(value)
  FileUtils.mkdir_p dir_path
  # Use File.binwrite instead File.open(json_file, 'wb') { |file| file.write(value) }
  File.binwrite(json_file, value)
  maintain_file_pool(RailsSpotlight.config.storage_pool_size)
end