Class: RailsSpotlight::Storage
- Inherits:
-
Object
- Object
- RailsSpotlight::Storage
- Defined in:
- lib/rails_spotlight/storage.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(key) ⇒ Storage
constructor
A new instance of Storage.
- #read ⇒ Object
- #write(value) ⇒ Object
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
#key ⇒ Object (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
#read ⇒ Object
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 |