Class: Duke::Project

Inherits:
Thor::Group
  • Object
show all
Extended by:
Forwardable
Includes:
Thor::Actions
Defined in:
lib/duke/project.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Project

Returns a new instance of Project.



29
30
31
32
33
34
35
36
# File 'lib/duke/project.rb', line 29

def initialize(opts)
  args = []
  options = {}
  config = {}
  super
  @repo_url = opts[:repo_url] if opts[:repo_url]
  @repo_dir = opts[:repo_dir] || opts[:repo_url].repo_dir
end

Instance Attribute Details

#controllerObject



46
47
48
# File 'lib/duke/project.rb', line 46

def controller
  @controller ||= Controller.new(repo_dir)
end

#repo_dirObject (readonly)

Returns the value of attribute repo_dir.



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

def repo_dir
  @repo_dir
end

#repo_urlObject (readonly)

Returns the value of attribute repo_url.



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

def repo_url
  @repo_url
end

Class Method Details

.allObject



10
11
12
13
14
# File 'lib/duke/project.rb', line 10

def self.all
  Dir['*'].collect do |repo_dir|
    find(:repo_dir => repo_dir)
  end.compact
end

.create(repo_url) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/duke/project.rb', line 16

def self.create(repo_url)
  p = new(repo_url)
  p.clone
  p.set_runner Config.runner
  p.set_campfire Config.campfire
  p
end

.find(opts) ⇒ Object



24
25
26
27
# File 'lib/duke/project.rb', line 24

def self.find(opts)
  p = new(opts)
  p if p.repo_dir?
end

Instance Method Details

#buildObject



104
105
106
107
# File 'lib/duke/project.rb', line 104

def build
  uri = URI.parse("#{url}/")
  Net::HTTP.post_form(uri, {})
end

#built?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/duke/project.rb', line 109

def built?
  !cijoe.last_build.nil?
end

#cijoeObject



38
39
40
41
42
43
44
# File 'lib/duke/project.rb', line 38

def cijoe
  @cijoe ||= begin
    ci = CIJoe.new(repo_dir)
    ci.restore
    ci
  end if repo_dir?
end

#cloneObject



63
64
65
# File 'lib/duke/project.rb', line 63

def clone
  run "git clone #{repo_url}"
end

#git_dirObject



55
56
57
# File 'lib/duke/project.rb', line 55

def git_dir
  File.join(repo_dir, '.git')
end

#passing?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/duke/project.rb', line 113

def passing?
  !cijoe.last_build.failed?
end


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/duke/project.rb', line 84

def print_status_msg
  fields = []
  fields << repo_dir
  if running?
    fields += ["port #{port}", "pid #{pid}"]
    if building?
      fields << 'building...'
    elsif built?
      fields << if passing?
        "passing"
      else
        "failing"
      end
    end
  else
    fields << "stopped"
  end
  puts fields.join(", ")
end

#repo_dir?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/duke/project.rb', line 59

def repo_dir?
  File.exist?(git_dir)
end

#set_campfire(campfire) ⇒ Object



78
79
80
81
82
# File 'lib/duke/project.rb', line 78

def set_campfire(campfire)
  campfire.each do |k, v|
    set_config("campfire.#{k}", v)
  end
end

#set_config(key, value) ⇒ Object



67
68
69
70
71
72
# File 'lib/duke/project.rb', line 67

def set_config(key, value)
  inside(repo_dir) do
    run "git config --unset-all \"#{key}\""
    run "git config \"#{key}\" \"#{value}\""
  end
end

#set_runner(runner) ⇒ Object



74
75
76
# File 'lib/duke/project.rb', line 74

def set_runner(runner)
  set_config("cijoe.runner", runner)
end

#start(port) ⇒ Object



50
51
52
53
# File 'lib/duke/project.rb', line 50

def start(port)
  self.controller = Controller.new(repo_dir, port)
  controller.start
end

#urlObject



117
118
119
# File 'lib/duke/project.rb', line 117

def url
  "http://#{Config.host}:#{port}"
end