cf-app-utils 0.4 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7c74061e68cd361e8c46c461906b9a187ef1efb
4
- data.tar.gz: 55bf5352c5cb652fd3b14b62d6c54cb68f5410ef
3
+ metadata.gz: 4b06c1f28aaf815c8d05d16ca2bfa75ba89afb53
4
+ data.tar.gz: b929438f367b7fc1ebf01851403ce98914e3e8f0
5
5
  SHA512:
6
- metadata.gz: 62fa32eea74739117c19db4474c55720aae8960fef4795b84d4f347652070889fa96bd69abe5f9111bd5524b619442d017535123626abcf63715910f54cf17f7
7
- data.tar.gz: e0a9c7557397e177e0f687556a4c7b1b6393211e76e6f87a347c76cdafd9ec9a721e991ec8fce94ecdd7cafed30616a4f8602e8acd96d7b951cabceb4e88c37a
6
+ metadata.gz: 2d50b5c16ab0c2751e1a35f8c9f2bb3485fd100cddfb2cef469fd2d6e1f6342fdb777ebe5d72d1037be54772ed80f9bf216a6201d587eb47e237a192ac8400d5
7
+ data.tar.gz: b2bfe53032e67d817c674705367c3c47f29c2bc92c3f8186c3888a9c43bb8a83ce5283c195fc52a15e2a9e0cb3737cb157d2694ccd02589ed3cb40e798d6cf1b
data/README.md CHANGED
@@ -40,7 +40,7 @@ CF::App::Credentials.find_by_service_name('master-db')
40
40
  CF::App::Credentials.find_by_service_tag('relational')
41
41
 
42
42
  # Get credentials for all service instances with the given tag
43
- CF::APP::Credentials.find_all_by_service_tag('relational')
43
+ CF::App::Credentials.find_all_by_service_tag('relational')
44
44
 
45
45
  # Get credentials for all service instances that match all of the given tags
46
46
  CF::App::Credentials.find_all_by_all_service_tags(['cleardb', 'relational'])
@@ -57,3 +57,8 @@ The keys in the hash are strings. For example, to get the `uri` value you can do
57
57
  ```ruby
58
58
  cleardb_url = credentials['uri']
59
59
  ```
60
+
61
+ ```ruby
62
+ # Inject your own environment variables
63
+ CF::App::Credentials.new(my_env)
64
+ ```
@@ -1,45 +1,87 @@
1
1
  module CF::App
2
2
  class Credentials
3
3
  class << self
4
- # Returns credentials for the service instance with the given +name+.
5
4
  def find_by_service_name(name)
6
- service = Service.find_by_name(name)
7
- service['credentials'] if service
8
- end
9
-
10
- # Returns credentials for the first service instance with the given +tag+.
11
- def find_by_service_tag(tag)
12
- service = Service.find_by_tag(tag)
13
- service['credentials'] if service
5
+ credentials.find_by_service_name(name)
14
6
  end
15
7
 
16
8
  def find_all_by_service_tag(tag)
17
- services = Service.find_all_by_tag(tag)
18
- services.map do |service|
19
- service['credentials']
20
- end
9
+ credentials.find_all_by_service_tag(tag)
21
10
  end
22
11
 
23
12
  # Returns credentials for the service instances with all the given +tags+.
24
13
  def find_all_by_all_service_tags(tags)
25
- return [] if tags.empty?
14
+ credentials.find_all_by_all_service_tags(tags)
15
+ end
26
16
 
27
- Service.find_all_by_tags(tags).map { |service| service['credentials'] }
17
+ # Returns credentials for the first service instance with the given +tag+.
18
+ def find_by_service_tag(tag)
19
+ credentials.find_by_service_tag(tag)
28
20
  end
29
21
 
30
22
  # Returns credentials for the first service instance with the given +label+.
31
23
  def find_by_service_label(label)
32
- service = Service.find_by_label(label)
33
- service['credentials'] if service
24
+ credentials.find_by_service_label(label)
34
25
  end
35
26
 
36
27
  # Returns credentials for all service instances with the given +label+.
37
28
  def find_all_by_service_label(label)
38
- services = Service.find_all_by_label(label)
39
- services.map do |service|
40
- service['credentials']
41
- end
29
+ credentials.find_all_by_service_label(label)
42
30
  end
31
+
32
+ def credentials
33
+ Credentials.new(ENV)
34
+ end
35
+ private :credentials
36
+ end
37
+
38
+ def initialize(env)
39
+ @locator = Service.new(env)
40
+ end
41
+
42
+ # Returns credentials for the service instance with the given +name+.
43
+ def find_by_service_name(name)
44
+ service = locator.find_by_name(name)
45
+ service['credentials'] if service
46
+ end
47
+
48
+ # Returns credentials for the first service instance with the given +tag+.
49
+ def find_by_service_tag(tag)
50
+ service = locator.find_by_tag(tag)
51
+ service['credentials'] if service
43
52
  end
53
+
54
+ def find_all_by_service_tag(tag)
55
+ services = locator.find_all_by_tag(tag)
56
+ services.map do |service|
57
+ service['credentials']
58
+ end
59
+ end
60
+
61
+ # Returns credentials for the service instances with all the given +tags+.
62
+ def find_all_by_all_service_tags(tags)
63
+ return [] if tags.empty?
64
+
65
+ locator.find_all_by_tags(tags).map { |service| service['credentials'] }
66
+ end
67
+
68
+ # Returns credentials for the first service instance with the given +label+.
69
+ def find_by_service_label(label)
70
+ service = locator.find_by_label(label)
71
+ service['credentials'] if service
72
+ end
73
+
74
+ # Returns credentials for all service instances with the given +label+.
75
+ def find_all_by_service_label(label)
76
+ services = locator.find_all_by_label(label)
77
+ services.map do |service|
78
+ service['credentials']
79
+ end
80
+ end
81
+
82
+ private
83
+
84
+ attr_reader :locator
85
+
44
86
  end
45
87
  end
@@ -2,7 +2,10 @@ require 'json'
2
2
 
3
3
  module CF::App
4
4
  class Service #:nodoc:
5
- class << self
5
+ def initialize(env = ENV)
6
+ @env = env
7
+ end
8
+
6
9
  def find_by_name(name)
7
10
  all.detect do |service|
8
11
  service['name'] == name
@@ -40,8 +43,7 @@ module CF::App
40
43
  private
41
44
 
42
45
  def all
43
- @services ||= JSON.parse(ENV['VCAP_SERVICES']).values.flatten
46
+ @services ||= JSON.parse(@env['VCAP_SERVICES']).values.flatten
44
47
  end
45
- end
46
48
  end
47
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cf-app-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: '0.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cloud Foundry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-15 00:00:00.000000000 Z
11
+ date: 2015-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  requirements: []
87
87
  rubyforge_project:
88
- rubygems_version: 2.2.2
88
+ rubygems_version: 2.2.3
89
89
  signing_key:
90
90
  specification_version: 4
91
91
  summary: Helper methods for apps running on Cloud Foundry