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.
7 8 9 |
# File 'lib/sqltorial/query_cache.rb', line 7 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.
5 6 7 |
# File 'lib/sqltorial/query_cache.rb', line 5 def query_to_md @query_to_md end |
Instance Method Details
#cache_file ⇒ Object
23 24 25 |
# File 'lib/sqltorial/query_cache.rb', line 23 def cache_file @cache_file ||= Pathname.pwd + '.cache' + cache_file_name end |
#cache_file_name ⇒ Object
27 28 29 |
# File 'lib/sqltorial/query_cache.rb', line 27 def cache_file_name @cache_file_name ||= Digest::SHA256.hexdigest("#{input_str}") + ".md" end |
#input_str ⇒ Object
31 32 33 34 35 |
# File 'lib/sqltorial/query_cache.rb', line 31 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
18 19 20 21 |
# File 'lib/sqltorial/query_cache.rb', line 18 def make_cache_file cache_file.dirname.mkpath cache_file.write(query_to_md.get_md) end |
#to_md ⇒ Object
11 12 13 14 15 16 |
# File 'lib/sqltorial/query_cache.rb', line 11 def to_md unless cache_file.exist? make_cache_file end cache_file.read end |