Sha256: 7e394e19ccaa262f5790da58f40669420ec3c76bdcbb1afa493ad59aeb8cc9a5

Contents?: true

Size: 1.22 KB

Versions: 31

Compression:

Stored size: 1.22 KB

Contents

require 'drb'
require 'drb/ssl'
require 'uri'

module Capricorn
  class Client
    
    autoload :AuthToken, File.dirname(__FILE__)+'/client/auth_token'
    
    # return a DRb uri for the given Capricorn uri.
    def self.parse_uri(uri)
      uri     = URI.parse(uri)
      use_ssl = (uri.scheme == 'ssl+capricorn')
      uri.scheme = 'druby'
      return use_ssl, uri.to_s
    end
    
    # return an potentialy initialize the client to the given token.
    def self.current(token=nil)
      @client = connect(token) unless @client
      @client
    end
    
    # connect to the server referenced by the given token.
    def self.connect(token=nil)
      token ||= 'core.token'
      
      [Capricorn::DEFAULT_ROOT_SYSTEM_DIR,
       Capricorn::DEFAULT_USER_SYSTEM_DIR,
       File.join(Capricorn::DEFAULT_USER_SYSTEM_DIR, 'tokens'),
       '.'].each do |path|
        path = File.expand_path(File.join(path, token))
        if File.file? path
          token = path
          break
        end
      end
      
      unless File.file? token
        raise "Unable to read the token at: #{token}"
      end
      
      token = Capricorn::Client::AuthToken.load_file(token) if String === token
      token.connect if token
    end
    
  end
end

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
simonmenke-capricorn-0.2.00 lib/capricorn/client.rb
simonmenke-capricorn-0.2.03 lib/capricorn/client.rb
simonmenke-capricorn-0.2.07 lib/capricorn/client.rb
simonmenke-capricorn-0.2.25 lib/capricorn/client.rb
simonmenke-capricorn-0.2.26 lib/capricorn/client.rb
capricorn-0.2.25 lib/capricorn/client.rb
capricorn-0.2.24 lib/capricorn/client.rb
capricorn-0.2.23 lib/capricorn/client.rb
capricorn-0.2.22 lib/capricorn/client.rb
capricorn-0.2.21 lib/capricorn/client.rb
capricorn-0.2.20 lib/capricorn/client.rb
capricorn-0.2.19 lib/capricorn/client.rb
capricorn-0.2.18 lib/capricorn/client.rb
capricorn-0.2.17 lib/capricorn/client.rb
capricorn-0.2.16 lib/capricorn/client.rb
capricorn-0.2.15 lib/capricorn/client.rb
capricorn-0.2.14 lib/capricorn/client.rb
capricorn-0.2.13 lib/capricorn/client.rb
capricorn-0.2.12 lib/capricorn/client.rb
capricorn-0.2.11 lib/capricorn/client.rb