Class: P4::P4
- Inherits:
-
Object
show all
- Defined in:
- lib/p4/p4.rb
Instance Method Summary
collapse
Constructor Details
#initialize(p4port, p4user, p4client) ⇒ P4
Returns a new instance of P4.
3
4
5
|
# File 'lib/p4/p4.rb', line 3
def initialize(p4port, p4user, p4client)
@env = {'p4port' => p4port, 'p4user' => p4user, 'p4client' => p4client}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *params) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/p4/p4.rb', line 35
def method_missing(sym, *params)
cmd = "p4.exe #{sym.to_s} #{params.join(' ')}"
puts cmd
IO.popen(@env, cmd) do |pipe|
stdout = pipe.read
puts stdout
block_given? ? yield(stdout) : stdout
end
end
|
Instance Method Details
#client_changelist ⇒ Object
7
8
9
10
11
12
13
14
|
# File 'lib/p4/p4.rb', line 7
def client_changelist
self.changes("-m1 @#{@env['p4client']}") do |stdout|
m = /^Change (?<changelist>\d+) on/.match(stdout)
raise stdout unless m
m[:changelist].to_i
end
end
|
#client_root ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'lib/p4/p4.rb', line 16
def client_root
self.clients("-e #{@env['p4client']}") do |stdout|
m = /^Client #{@env['p4client']} \d+\/\d+\/\d+ root (?<root>.+) 'Created by /.match(stdout)
raise stdout unless m
m[:root]
end
end
|
#submit(*params) ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/p4/p4.rb', line 26
def submit(*params)
self.method_missing(:submit, params) do |stdout|
m = /Change (?<changelist>\d+) submitted./.match(stdout)
raise stdout unless m
m[:changelist].to_i
end
end
|