Class: Svp::P4

Inherits:
Object
  • Object
show all
Defined in:
lib/svp/p4.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(depot_uri, local_dir) ⇒ P4

Returns a new instance of P4.



15
16
17
18
19
# File 'lib/svp/p4.rb', line 15

def initialize(depot_uri, local_dir)
  @depot_uri = depot_uri
  @local_dir = local_dir
  @client_name = "tmp_#{Socket.gethostname}"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



41
42
43
# File 'lib/svp/p4.rb', line 41

def method_missing(name, *args, &block)
  execute("#{name.to_s} #{args.join(' ')}")
end

Class Method Details

.execute(depot_uri, local_dir, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/svp/p4.rb', line 5

def self.execute(depot_uri, local_dir, &block)
  p4 = P4.new(depot_uri, local_dir)
  p4.create_client
  begin
    yield p4
  ensure
    p4.delete_client
  end
end

Instance Method Details

#create_clientObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/svp/p4.rb', line 25

def create_client
  execute("client -i", <<-EOS)
Client:	#{@client_name}
Owner: #{@depot_uri.user}
Root: #{@local_dir}
Options: allwrite noclobber compress unlocked nomodtime rmdir
LineEnd: share
View:
  #{@depot_uri.path}/... //#{@client_name}/...
EOS
end

#delete_clientObject



37
38
39
# File 'lib/svp/p4.rb', line 37

def delete_client
  execute("client -d #{@client_name}")
end

#success?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/svp/p4.rb', line 21

def success?
  @success
end