Sha256: 51da7d802547fd26c7bceae5b3bde944ca85a68fffd6a425ddb41959d544ce63

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'circleci'
require 'circle/cli/build'

module Circle
  module CLI
    class Project
      attr_reader :repo

      def initialize(repo)
        @repo = repo
        configure
      end

      def build!
        request CircleCi::Project, :build_branch, repo.branch_name
      end

      def builds
        @builds ||= to_builds(request(CircleCi::Project, :recent_builds_branch, repo.branch_name))
      end

      def recent_builds
        @recent_builds ||= to_builds(request(CircleCi::Project, :recent_builds))
      end

      def latest
        builds.first
      end

      def clear_cache!
        @builds = nil
        @recent_builds = nil
      end

      def request(klass, action, *args)
        klass.send(action, repo.user_name, repo.project, *args).body
      end

      private

      def configure
        CircleCi.configure do |config|
          config.token = repo.circle_token
        end
      end

      def to_builds(arr)
        arr.map { |build| Build.new(self, build) }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
circle-cli-0.1.0 lib/circle/cli/project.rb