Class: HelixSync::ClientService

Inherits:
Object
  • Object
show all
Defined in:
lib/helix_sync/client_service.rb

Overview

Provides a mechanism for managing client workspaces for projects.

Constant Summary

@@handle_create_client =
[]

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (ClientService) initialize(env: nil)

Returns a new instance of ClientService



8
9
10
# File 'lib/helix_sync/client_service.rb', line 8

def initialize(env: nil)
  @env = env
end

Instance Attribute Details

- (Object) env

Rack environment



6
7
8
# File 'lib/helix_sync/client_service.rb', line 6

def env
  @env
end

Class Method Details

+ (Object) handle_create_client

Callback methods that can implement client workspace creation based on projects.

Each callback should take 4 parameters:

  • project [String] The project ID.

  • device [String] A device ID (like a hostname or MAC address) that we'll associate with the client.

  • root [String] The Root field of the client, the base directory for the new setting.

  • env [Hash] The rack environment

Your callback should return the new client name if it's been handled.

It's assumed that your implementation will handle other defaults responsibly.

Example:

HelixSync::ClientService.handle_create_client << lambda do |project, device, root, env|
  client_name = go_make_client()
  return client_name if client_name # Just return nil if you can't handle it
end


40
41
42
# File 'lib/helix_sync/client_service.rb', line 40

def self.handle_create_client
  @@handle_create_client
end

Instance Method Details

- (Object) create_client(project, device, root)

Create a client for the project.

Returns the new client name if successful, nil otherwise.



47
48
49
50
51
52
53
54
55
# File 'lib/helix_sync/client_service.rb', line 47

def create_client(project, device, root)
  client_id = nil
  @@handle_create_client.find do |handler|
    id = handler.call(project, device, root, env)
    client_id = id if id
    id
  end
  client_id
end

- (Object) p4



57
58
59
# File 'lib/helix_sync/client_service.rb', line 57

def p4
  env['p4']
end