etcd-discovery 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/etcd-discovery/host.rb +17 -21
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c22d9ff32c7372703f77f239c45b9a35fa1ec569
4
- data.tar.gz: 80e47d7f2a449ff8b2bf25b8b8f7a2e69f38a5b2
3
+ metadata.gz: 163c6cc3af01710f2998906408bcc4b90e88820c
4
+ data.tar.gz: 149f5d852f18ccdeec8660049083e5b5fc532765
5
5
  SHA512:
6
- metadata.gz: 2ad41dc2d9a4b5c3baa848db55fa3943f326d3999ca4b94b18ebdcb0acc0cf20c27b609faa7dc03a920f746fce44be5814a41f2c3ea8318edffd28ac1c1dcb9a
7
- data.tar.gz: f7552e575cf892c624814f8b75557c4c486ad192369f59c873a117aa463f577622b59e5fb1237699e1b4a18e650930a4dc45430d5202ad744b2996541f898eb3
6
+ metadata.gz: a5af9928c529cdf705473a1dcf650e0286343456546a5cb55c6ad23f1c0210b349f5f2b0305550c8c491dfe383c8e76e00faea5dbf28fbda332d0ea489d21575
7
+ data.tar.gz: fbfcfce924f3ec3b739134128dfa987698209fbb52adce68cd32a7340d56981f10ce5e0195f6ab557892a5a43365e5f182ddf436ca1a9bc3e2200a7acf85db20
@@ -1,41 +1,37 @@
1
- class Hash
2
- def capitalize_keys
3
- new_hash = {}
4
- self.each do |k,v|
5
- new_hash[k.to_s.capitalize] = v
6
- end
7
- return new_hash
1
+ module EtcdDiscovery
2
+ class InvalidHost < RuntimeError
8
3
  end
9
- end
10
4
 
11
- module EtcdDiscovery
12
5
  class Host
13
- attr_accessor :hostname, :port, :user, :password
6
+ attr_accessor :attributes
14
7
 
15
8
  def initialize(arg)
16
9
  if arg.is_a? Etcd::Node
17
- params = JSON.parse arg.value
10
+ @attributes = JSON.parse arg.value
18
11
  elsif arg.is_a? Hash
19
- params = arg.capitalize_keys
12
+ @attributes = arg
20
13
  else
21
14
  raise TypeError, "requires a Etcd::Node or a Hash, not a #{arg.class}"
22
15
  end
23
- @hostname = params['Name']
24
- @port = params['Port']
25
- @user = params['User']
26
- @password = params['Password']
27
-
28
- if @hostname.nil? or @hostname.empty?
29
- @hostname = Socket.gethostname
16
+ if !attributes.has_key? 'name' or !attributes.has_key? 'port'
17
+ raise InvalidHost, "attributes 'name' and 'port' should be defined"
30
18
  end
19
+ @user = params['user'] || ""
20
+ @password = params['password'] || ""
21
+ @scheme = params['scheme'] || "http"
31
22
  end
32
23
 
33
24
  def to_json
34
- {"Name" => @hostname, "Port" => @port, "User" => @user, "Password" => @password}.to_json
25
+ attributes.to_json
35
26
  end
36
27
 
37
28
  def to_uri
38
- URI("http://#{user}:#{password}@#{hostname}:#{port}")
29
+ a = attributes # Shorten name
30
+ URI("#{a['scheme']}://#{a['user']}:#{a['password']}@#{a['name']}:#{a['port']}")
31
+ end
32
+
33
+ def to_s
34
+ self.to_uri.to_s
39
35
  end
40
36
  end
41
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etcd-discovery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Léo Unbekandt