Sha256: 0a8dfbcd88dfb3d7104f325b511dc8b091000a2f97e0099e00c6c210acb08c55

Contents?: true

Size: 937 Bytes

Versions: 6

Compression:

Stored size: 937 Bytes

Contents

module EacLauncher
  module Instances
    class Base < ::EacLauncher::Path
      module Cache
        def cache_path(subpath)
          File.join(cache_root, subpath)
        end

        def cache_key(key, &block)
          v = cache_key_get(key)
          return v if v.present? || block.nil?
          v = yield
          cache_key_write(key, v)
          v
        end

        private

        def cache_key_get(key)
          File.file?(cache_key_path(key)) ? File.read(cache_key_path(key)) : nil
        end

        def cache_key_write(key, value)
          FileUtils.mkdir_p(File.dirname(cache_key_path(key)))
          File.write(cache_key_path(key), value)
        end

        def cache_key_path(key)
          File.join(cache_root, 'keys', key.parameterize)
        end

        def cache_root
          File.join(::EacLauncher::Context.current.cache_root, to_root_path.parameterize)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
eac_launcher-0.1.5 lib/eac_launcher/instances/base/cache.rb
eac_launcher-0.1.3 lib/eac_launcher/instances/base/cache.rb
eac_launcher-0.1.4 lib/eac_launcher/instances/base/cache.rb
eac_launcher-0.1.2 lib/eac_launcher/instances/base/cache.rb
eac_launcher-0.1.1 lib/eac_launcher/instances/base/cache.rb
eac_launcher-0.1.0 lib/eac_launcher/instances/base/cache.rb