Class: Circle::CLI::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/circle/cli/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo) ⇒ Project

Returns a new instance of Project.



9
10
11
12
# File 'lib/circle/cli/project.rb', line 9

def initialize(repo)
  @repo = repo
  configure
end

Instance Attribute Details

#repoObject (readonly)

Returns the value of attribute repo.



7
8
9
# File 'lib/circle/cli/project.rb', line 7

def repo
  @repo
end

Instance Method Details

#build!Object



14
15
16
# File 'lib/circle/cli/project.rb', line 14

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

#buildsObject



18
19
20
# File 'lib/circle/cli/project.rb', line 18

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

#clear_cache!Object



30
31
32
33
# File 'lib/circle/cli/project.rb', line 30

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

#latestObject



26
27
28
# File 'lib/circle/cli/project.rb', line 26

def latest
  builds.first
end

#recent_buildsObject



22
23
24
# File 'lib/circle/cli/project.rb', line 22

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

#request(klass, action, *args) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/circle/cli/project.rb', line 35

def request(klass, action, *args)
  response = klass.send(action, repo.user_name, repo.project, *args)

  if response.success?
    response.body
  else
    $stderr.puts 'One or more errors occurred:'

    response.errors.each do |error|
      $stderr.puts "+ #{error.message}"
    end

    exit 1
  end
end