Class: SQLtorial::QueryCache
- Inherits:
-
Object
- Object
- SQLtorial::QueryCache
- Defined in:
- lib/sqltorial/query_cache.rb
Instance Attribute Summary collapse
-
#query_to_md ⇒ Object
readonly
Returns the value of attribute query_to_md.
Instance Method Summary collapse
- #cache_file ⇒ Object
- #cache_file_name ⇒ Object
-
#initialize(query_to_md) ⇒ QueryCache
constructor
A new instance of QueryCache.
- #input_str ⇒ Object
- #make_cache_file ⇒ Object
- #to_md ⇒ Object
Constructor Details
#initialize(query_to_md) ⇒ QueryCache
Returns a new instance of QueryCache.
5 6 7 |
# File 'lib/sqltorial/query_cache.rb', line 5 def initialize(query_to_md) @query_to_md = query_to_md end |
Instance Attribute Details
#query_to_md ⇒ Object (readonly)
Returns the value of attribute query_to_md.
3 4 5 |
# File 'lib/sqltorial/query_cache.rb', line 3 def query_to_md @query_to_md end |
Instance Method Details
#cache_file ⇒ Object
21 22 23 |
# File 'lib/sqltorial/query_cache.rb', line 21 def cache_file @cache_file ||= Pathname.pwd + '.cache' + cache_file_name end |
#cache_file_name ⇒ Object
25 26 27 |
# File 'lib/sqltorial/query_cache.rb', line 25 def cache_file_name @cache_file_name ||= Digest::SHA256.hexdigest("#{input_str}") + ".md" end |
#input_str ⇒ Object
29 30 31 32 33 |
# File 'lib/sqltorial/query_cache.rb', line 29 def input_str @input_str ||= %w(query row_limit validation_directives other_directives).inject("") do |s, meth| s + query_to_md.send(meth).inspect end end |
#make_cache_file ⇒ Object
16 17 18 19 |
# File 'lib/sqltorial/query_cache.rb', line 16 def make_cache_file cache_file.dirname.mkpath cache_file.write(query_to_md.get_md) end |
#to_md ⇒ Object
9 10 11 12 13 14 |
# File 'lib/sqltorial/query_cache.rb', line 9 def to_md unless cache_file.exist? make_cache_file end cache_file.read end |