cf-app-utils 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,23 +1,39 @@
1
1
  module CF::App
2
2
  class Credentials
3
3
  class << self
4
- # Returns credentials for the service with the given +name+.
4
+ # Returns credentials for the service instance with the given +name+.
5
5
  def find_by_service_name(name)
6
6
  service = Service.find_by_name(name)
7
7
  service['credentials'] if service
8
8
  end
9
9
 
10
- # Returns credentials for the first service with the given +tag+.
10
+ # Returns credentials for the first service instance with the given +tag+.
11
11
  def find_by_service_tag(tag)
12
12
  service = Service.find_by_tag(tag)
13
13
  service['credentials'] if service
14
14
  end
15
15
 
16
- # Returns credentials for the first service with the given +label+.
16
+ 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
21
+ end
22
+
23
+
24
+ # Returns credentials for the first service instance with the given +label+.
17
25
  def find_by_service_label(label)
18
26
  service = Service.find_by_label(label)
19
27
  service['credentials'] if service
20
28
  end
29
+
30
+ # Returns credentials for all service instances with the given +label+.
31
+ def find_all_by_service_label(label)
32
+ services = Service.find_all_by_label(label)
33
+ services.map do |service|
34
+ service['credentials']
35
+ end
36
+ end
21
37
  end
22
38
  end
23
39
  end
@@ -10,30 +10,29 @@ module CF::App
10
10
  end
11
11
 
12
12
  def find_by_tag(tag)
13
- all.detect do |service|
13
+ find_all_by_tag(tag).first
14
+ end
15
+
16
+ def find_all_by_tag(tag)
17
+ all.select do |service|
14
18
  service['tags'].include?(tag)
15
19
  end
16
20
  end
17
21
 
18
22
  def find_by_label(label)
19
- all.detect do |service|
20
- service['label'] == label
23
+ find_all_by_label(label).first
24
+ end
25
+
26
+ def find_all_by_label(label)
27
+ all.select do |service|
28
+ service['label'].match /^#{label}(-.*)?$/
21
29
  end
22
30
  end
23
31
 
24
32
  private
25
33
 
26
34
  def all
27
- @services ||= begin
28
- services = JSON.parse(ENV['VCAP_SERVICES']).map(&:last).flatten
29
- services.map do |service|
30
- service['label'] =~ /^(.*)-(.*)$/
31
- label, version = $1, $2
32
- service['label'] = label
33
- service['version'] = version
34
- service
35
- end
36
- end
35
+ @services ||= JSON.parse(ENV['VCAP_SERVICES']).values.flatten
37
36
  end
38
37
  end
39
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cf-app-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-28 00:00:00.000000000 Z
12
+ date: 2014-01-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -85,18 +85,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
85
  - - ! '>='
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
- segments:
89
- - 0
90
- hash: 1116896598145755807
91
88
  required_rubygems_version: !ruby/object:Gem::Requirement
92
89
  none: false
93
90
  requirements:
94
91
  - - ! '>='
95
92
  - !ruby/object:Gem::Version
96
93
  version: '0'
97
- segments:
98
- - 0
99
- hash: 1116896598145755807
100
94
  requirements: []
101
95
  rubyforge_project:
102
96
  rubygems_version: 1.8.23