Class: Kafo::ParserCacheReader
- Inherits:
-
Object
- Object
- Kafo::ParserCacheReader
- Defined in:
- lib/kafo/parser_cache_reader.rb
Class Method Summary collapse
Instance Method Summary collapse
- #get(key, manifest_path) ⇒ Object
-
#initialize(cache) ⇒ ParserCacheReader
constructor
A new instance of ParserCacheReader.
- #logger ⇒ Object
Constructor Details
#initialize(cache) ⇒ ParserCacheReader
Returns a new instance of ParserCacheReader.
28 29 30 |
# File 'lib/kafo/parser_cache_reader.rb', line 28 def initialize(cache) @cache = cache end |
Class Method Details
.logger ⇒ Object
24 25 26 |
# File 'lib/kafo/parser_cache_reader.rb', line 24 def self.logger KafoConfigure.logger end |
.new_from_file(cache_path) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/kafo/parser_cache_reader.rb', line 3 def self.new_from_file(cache_path) if cache_path.nil? || cache_path.empty? logger.debug "No parser cache configured in :parser_cache_path, skipping setup" return nil end unless File.exist?(cache_path) logger.warn "Parser cache configured at #{cache_path} is missing, skipping setup" return nil end parsed = YAML.load(File.read(cache_path)) if !parsed.is_a?(Hash) || parsed[:version] != 1 || !parsed[:files].is_a?(Hash) logger.warn "Parser cache is from a different version of Kafo, skipping setup" return nil end logger.debug "Using #{cache_path} cache with parsed modules" new(parsed) end |
Instance Method Details
#get(key, manifest_path) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/kafo/parser_cache_reader.rb', line 36 def get(key, manifest_path) return nil unless @cache[:files].has_key?(key) if @cache[:files][key][:mtime] && File.mtime(manifest_path).to_i > @cache[:files][key][:mtime] logger.debug "Parser cache for #{manifest_path} is outdated, ignoring cache entry" return nil end @cache[:files][key][:data] end |
#logger ⇒ Object
32 33 34 |
# File 'lib/kafo/parser_cache_reader.rb', line 32 def logger KafoConfigure.logger end |