Class: Pachyderm::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(address, token = nil) ⇒ Client

Returns a new instance of Client.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pachyderm.rb', line 20

def initialize(address, token=nil)
    @clients = {}
    clients = Pachyderm.constants
    # Omit the enterprise client
    # It has a collision w the 'auth.activate' call
    # and really you only use enterprise to administrate, and 
    # make that activate call once
    # And. If you really need to call it via the ruby client,
    # you can do so explicitly a la `Pachyderm::Enterprise::API::Stub.new ...`
    clients.delete(:Enterprise)
    clients.each do |sub_client_name|
        sub_client = Pachyderm.const_get sub_client_name
        next unless sub_client.const_defined? :API
        @clients[sub_client_name] = sub_client.const_get(:API).const_get(:Stub).new(address, :this_channel_is_insecure)
    end
    @token = token
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Raises:

  • (Exception)


46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/pachyderm.rb', line 46

def method_missing(m, *args, &block)
    result = nil
    method_found = false
    @clients.each do |name, client|
        if client.respond_to? m
            method_found = true
            args <<  unless @token.nil?
            result = client.send(m, *args, &block)
        end
    end
    raise Exception.new("method #{m} not found") unless method_found
    result
end

Instance Method Details

#delete_allObject

The one ‘sugar’ method we provide, since it needs to make a call to both Pfs + Pps



40
41
42
43
44
# File 'lib/pachyderm.rb', line 40

def delete_all
		    req = Google::Protobuf::Empty.new
    @clients[:Pfs].delete_all(req)
    @clients[:Pps].delete_all(req)
end

#metadataObject



60
61
62
63
64
65
# File 'lib/pachyderm.rb', line 60

def ()
	# The 'authn-token' is a keyname hardcoded at:
	# https://github.com/pachyderm/pachyderm/blob/master/src/client/auth/auth.go#L14
	# TODO - as part of the 'make sync' build task, pull in this value
	{:metadata => {'authn-token' => @token}}
end