Sha256: a8dee334a2492834581fbfbacfbc959aed8f596796c807ad818e91089f301d13

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 KB

Contents

module Git
  module Semaphore
    class API
      class Cache

        def self.projects auth_token
          @projects ||= Git::Semaphore.from_json_cache(projects_cache) do
            API::Enrich.projects auth_token
          end
        end

        def self.branches project_hash_id, auth_token
          @branches ||= Git::Semaphore.from_json_cache(branches_cache(project_hash_id)) do
            API.branches project_hash_id, auth_token
          end
        end

        def self.status project_hash_id, branch_id, auth_token
          @status ||= Git::Semaphore.from_json_cache(status_cache(project_hash_id, branch_id)) do
            API.status project_hash_id, branch_id, auth_token
          end
        end

        def self.history project_hash_id, branch_id, auth_token
          @history ||= Git::Semaphore.from_json_cache(history_cache(project_hash_id, branch_id)) do
            API::Enrich.history project_hash_id, branch_id, auth_token
          end
        end

        # private helper functions

        def self.projects_cache
          File.join(Git::Semaphore.cache_dir, 'projects.json')
        end

        private_class_method :projects_cache

        def self.branches_cache project_hash_id
          File.join(Git::Semaphore.cache_dir_for(project_hash_id), 'branches.json')
        end

        private_class_method :branches_cache

        def self.status_cache project_hash_id, branch_id
          File.join(Git::Semaphore.cache_dir_for(project_hash_id), "#{branch_id}_status.json")
        end

        private_class_method :status_cache

        def self.history_cache project_hash_id, branch_id
          File.join(Git::Semaphore.cache_dir_for(project_hash_id), "#{branch_id}_history.json")
        end

        private_class_method :history_cache

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git-semaphore-1.0.0 lib/git/semaphore/api_cache.rb