module HelixSync # Provides a mechanism for managing client workspaces for projects. class ClientService # Rack environment attr_accessor :env def initialize(env: nil) @env = env end @@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 def self.handle_create_client @@handle_create_client end # Create a client for the project. # # Returns the new client name if successful, nil otherwise. 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 def p4 env['p4'] end end end