cfoundry 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ module CFoundry
2
+ class ChattyHash
3
+ include Enumerable
4
+
5
+ def initialize(callback, hash = {})
6
+ @callback = callback
7
+ @hash = hash
8
+ end
9
+
10
+ def [](name)
11
+ @hash[name]
12
+ end
13
+
14
+ def []=(name, value)
15
+ @hash[name] = value
16
+ @callback.call(self)
17
+ value
18
+ end
19
+
20
+ def each(&blk)
21
+ @hash.each(&blk)
22
+ end
23
+
24
+ def delete(key)
25
+ value = @hash.delete(key)
26
+ @callback.call(self)
27
+ value
28
+ end
29
+
30
+ def to_json(*args)
31
+ @hash.to_json(*args)
32
+ end
33
+ end
34
+ end
@@ -4,6 +4,7 @@ require "pathname"
4
4
  require "tmpdir"
5
5
 
6
6
  require "cfoundry/zip"
7
+ require "cfoundry/chatty_hash"
7
8
 
8
9
  require "cfoundry/v1/framework"
9
10
  require "cfoundry/v1/runtime"
@@ -183,13 +184,29 @@ module CFoundry::V1
183
184
  state == "STARTED"
184
185
  end
185
186
 
187
+ def env
188
+ e = manifest[:env] || []
189
+
190
+ env = {}
191
+ e.each do |pair|
192
+ name, val = pair.split("=", 2)
193
+ env[name] = val
194
+ end
195
+
196
+ CFoundry::ChattyHash.new(method(:env=), env)
197
+ end
198
+
199
+ def env=(hash)
200
+ @manifest ||= {}
201
+ @manifest[:env] = hash.collect { |k, v| "#{k}=#{v}" }
202
+ end
203
+
186
204
  { :total_instances => :instances,
187
205
  :state => :state,
188
206
  :status => :state,
189
207
  :services => :services,
190
208
  :uris => :uris,
191
- :urls => :uris,
192
- :env => :env
209
+ :urls => :uris
193
210
  }.each do |meth, attr|
194
211
  define_method(meth) do
195
212
  manifest[attr]
@@ -189,7 +189,12 @@ module CFoundry::V1
189
189
 
190
190
  # TODO: remove once v2 allows filtering by name
191
191
  # see V2::Client#app_by_name
192
- alias :app_by_name :app
192
+ def app_by_name(name)
193
+ app = app(name)
194
+ if app.exists?
195
+ app
196
+ end
197
+ end
193
198
 
194
199
  # Retrieve all of the current user's services.
195
200
  def service_instances
@@ -2,8 +2,11 @@ require "fileutils"
2
2
  require "digest/sha1"
3
3
  require "pathname"
4
4
  require "tmpdir"
5
+ require "json"
5
6
 
6
7
  require "cfoundry/zip"
8
+ require "cfoundry/chatty_hash"
9
+
7
10
  require "cfoundry/v2/model"
8
11
 
9
12
  module CFoundry::V2
@@ -36,6 +39,20 @@ module CFoundry::V2
36
39
  alias :space :app_space
37
40
  alias :space= :app_space=
38
41
 
42
+ private :environment_json, :environment_json=
43
+
44
+ def env
45
+ @env ||= CFoundry::ChattyHash.new(
46
+ method(:env=),
47
+ JSON.parse(environment_json))
48
+ end
49
+
50
+ def env=(hash)
51
+ @env = hash
52
+ @diff["environment_json"] = hash
53
+ hash
54
+ end
55
+
39
56
  def debug_mode # TODO v2
40
57
  nil
41
58
  end
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.3.3"
3
+ VERSION = "0.3.4"
4
4
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfoundry
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 3
10
- version: 0.3.3
9
+ - 4
10
+ version: 0.3.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Suraci
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-07-14 00:00:00 Z
18
+ date: 2012-07-15 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rest-client
@@ -106,6 +106,7 @@ files:
106
106
  - LICENSE
107
107
  - Rakefile
108
108
  - lib/cfoundry/baseclient.rb
109
+ - lib/cfoundry/chatty_hash.rb
109
110
  - lib/cfoundry/client.rb
110
111
  - lib/cfoundry/errors.rb
111
112
  - lib/cfoundry/uaaclient.rb