Class: Measured::Cache::Json
- Inherits:
-
Object
- Object
- Measured::Cache::Json
- Defined in:
- lib/measured/cache/json.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #exist? ⇒ Boolean
-
#initialize(filename) ⇒ Json
constructor
A new instance of Json.
- #read ⇒ Object
- #write(table) ⇒ Object
Constructor Details
#initialize(filename) ⇒ Json
Returns a new instance of Json.
6 7 8 9 |
# File 'lib/measured/cache/json.rb', line 6 def initialize(filename) @filename = filename @path = Pathname.new(File.join(File.dirname(__FILE__), "../../../cache", @filename)).cleanpath end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
4 5 6 |
# File 'lib/measured/cache/json.rb', line 4 def filename @filename end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/measured/cache/json.rb', line 4 def path @path end |
Instance Method Details
#exist? ⇒ Boolean
11 12 13 |
# File 'lib/measured/cache/json.rb', line 11 def exist? File.exist?(@path) end |
#read ⇒ Object
15 16 17 18 |
# File 'lib/measured/cache/json.rb', line 15 def read return unless exist? decode(JSON.load(File.read(@path), nil, freeze: true)) end |
#write(table) ⇒ Object
20 21 22 |
# File 'lib/measured/cache/json.rb', line 20 def write(table) raise ArgumentError, "Cannot overwrite file cache at runtime." end |