Sha256: ba0010fc6354debcd9c4afd99bee1142105d15bd02298fac8db719c47299838c
Contents?: true
Size: 1.93 KB
Versions: 1
Compression:
Stored size: 1.93 KB
Contents
# encoding: UTF-8 require 'digest/sha1' module Rosette module Core # Takes snapshots and caches the results. Take a look at # +ActiveSupport::Cache+ for a good set of cache stores that conform to the # right interface. # # @see http://api.rubyonrails.org/classes/ActiveSupport/Cache.html # # @!attribute [r] cache # @return [#fetch] the cache store. This can be any object that responds # to +#fetch+ (and passes a block). class CachedSnapshotFactory attr_reader :cache # Creates a new cached snapshot factory that uses the given cache. # # @param [#fetch] cache The cache to use. def initialize(cache) @cache = cache end # Takes the snapshot. # # @param [RepoConfig] repo_config The repo config for the repo to take # the snapshot for. # @param [String] commit_id The commit id to take the snapshot of. # @param [Array<String>] paths The list of paths to include in the # snapshot. If +paths+ is empty, this method will return a snapshot # that contains all paths. # @return [Hash<String, String>] The snapshot hash (path to commit id # pairs). def take_snapshot(repo_config, commit_id, paths = []) paths = Array(paths) cache_key = snapshot_cache_key(repo_config.name, commit_id, paths) cache.fetch(cache_key) do factory = snapshot_factory.new .set_repo_config(repo_config) .set_start_commit_id(commit_id) factory.set_paths(paths) if paths.size > 0 factory.take_snapshot end end private def snapshot_cache_key(repo_name, commit_id, paths) ['snapshots', repo_name, commit_id, path_digest(paths)].join('/') end def path_digest(paths) Digest::MD5.hexdigest(paths.join) end def snapshot_factory Rosette::Core::SnapshotFactory end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rosette-core-1.0.1 | lib/rosette/core/snapshots/cached_snapshot_factory.rb |