cfoundry 0.3.23 → 0.3.24

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,7 @@ module CFoundry
9
9
  client_id = "vmc")
10
10
  @target = target
11
11
  @client_id = client_id
12
- @redirect_uri = "http://uaa.cloudfoundry.com/redirect/vmc"
12
+ @redirect_uri = "https://uaa.cloudfoundry.com/redirect/vmc"
13
13
  end
14
14
 
15
15
  def prompts
@@ -17,17 +17,17 @@ module CFoundry::V2
17
17
  class App < Model
18
18
  include CFoundry::UploadHelpers
19
19
 
20
- attribute :name
21
- attribute :production
20
+ attribute :name, :string
21
+ attribute :production, :boolean, :default => false
22
22
  to_one :space
23
23
  to_one :runtime
24
24
  to_one :framework
25
- attribute :environment_json, :default => {}
26
- attribute :memory, :default => 256
27
- attribute :instances, :default => 1
28
- attribute :file_descriptors, :default => 256
29
- attribute :disk_quota, :default => 256
30
- attribute :state, :default => "STOPPED"
25
+ attribute :environment_json, :hash, :default => {}
26
+ attribute :memory, :integer, :default => 256
27
+ attribute :instances, :integer, :default => 1
28
+ attribute :file_descriptors, :integer, :default => 256
29
+ attribute :disk_quota, :integer, :default => 256
30
+ attribute :state, :integer, :default => "STOPPED"
31
31
  to_many :service_bindings
32
32
 
33
33
  alias :total_instances :instances
@@ -2,7 +2,7 @@ require "cfoundry/v2/model"
2
2
 
3
3
  module CFoundry::V2
4
4
  class Domain < Model
5
- attribute :name
5
+ attribute :name, :string
6
6
  to_one :organization
7
7
  end
8
8
  end
@@ -2,8 +2,8 @@ require "cfoundry/v2/model"
2
2
 
3
3
  module CFoundry::V2
4
4
  class Framework < Model
5
- attribute :name
6
- attribute :description
5
+ attribute :name, :string
6
+ attribute :description, :string
7
7
  to_many :apps
8
8
 
9
9
  def detection
@@ -3,19 +3,57 @@ require "multi_json"
3
3
  module CFoundry::V2
4
4
  class Model
5
5
  class << self
6
+ def value_matches?(val, type)
7
+ case type
8
+ when Class
9
+ val.is_a?(type)
10
+ when Regexp
11
+ val.is_a?(String) && val =~ type
12
+ when :url
13
+ value_matches?(val, URI::regexp(%w(http https)))
14
+ when :https_url
15
+ value_matches?(val, URI::regexp("https"))
16
+ when :boolean
17
+ val.is_a?(TrueClass) || val.is_a?(FalseClass)
18
+ when Array
19
+ val.all? do |x|
20
+ value_matches?(x, type.first)
21
+ end
22
+ when Hash
23
+ val.is_a?(Hash) &&
24
+ type.all? { |name, subtype|
25
+ val.key?(name) && value_matches?(val[name], subtype)
26
+ }
27
+ else
28
+ val.is_a?(Object.const_get(type.to_s.capitalize))
29
+ end
30
+ end
31
+
32
+ def validate_type(val, type)
33
+ unless value_matches?(val, type)
34
+ raise "invalid attribute; expected #{type.inspect} but got #{val.inspect}"
35
+ end
36
+ end
37
+
6
38
  def defaults
7
39
  @defaults ||= {}
8
40
  end
9
41
 
10
- def attribute(name, opts = {})
42
+ def attribute(name, type, opts = {})
11
43
  default = opts[:default] || nil
12
- defaults[name] = default if default
44
+
45
+ has_default = opts.key?(:default)
46
+ defaults[name] = default if has_default
13
47
 
14
48
  define_method(name) {
15
49
  manifest[:entity][name] || default
16
50
  }
17
51
 
18
52
  define_method(:"#{name}=") { |val|
53
+ unless has_default && val == default
54
+ Model.validate_type(val, type)
55
+ end
56
+
19
57
  @manifest ||= {}
20
58
  @manifest[:entity] ||= {}
21
59
  @manifest[:entity][name] = val
@@ -25,6 +63,7 @@ module CFoundry::V2
25
63
 
26
64
  def to_one(name, opts = {})
27
65
  obj = opts[:as] || name
66
+ kls = obj.to_s.capitalize
28
67
 
29
68
  define_method(name) {
30
69
  if @manifest && @manifest[:entity].key?(name)
@@ -42,6 +81,8 @@ module CFoundry::V2
42
81
  }
43
82
 
44
83
  define_method(:"#{name}=") { |x|
84
+ Model.validate_type(x, CFoundry::V2.const_get(kls))
85
+
45
86
  @manifest ||= {}
46
87
  @manifest[:entity] ||= {}
47
88
  @manifest[:entity][:"#{name}_guid"] =
@@ -51,6 +92,7 @@ module CFoundry::V2
51
92
 
52
93
  def to_many(plural, opts = {})
53
94
  singular = plural.to_s.sub(/s$/, "").to_sym
95
+ kls = singular.to_s.capitalize
54
96
 
55
97
  object = opts[:as] || singular
56
98
  plural_object = :"#{object}s"
@@ -85,6 +127,8 @@ module CFoundry::V2
85
127
 
86
128
  # TODO: these are hacky
87
129
  define_method(:"add_#{singular}") { |x|
130
+ Model.validate_type(x, CFoundry::V2.const_get(kls))
131
+
88
132
  @client.base.request_path(
89
133
  :put,
90
134
  ["v2", "#{object_name}s", @guid, plural, x.guid],
@@ -99,6 +143,8 @@ module CFoundry::V2
99
143
  }
100
144
 
101
145
  define_method(:"#{plural}=") { |xs|
146
+ Model.validate_type(x, [CFoundry::V2.const_get(kls)])
147
+
102
148
  @manifest ||= {}
103
149
  @manifest[:entity] ||= {}
104
150
  @manifest[:entity][:"#{singular}_guids"] =
@@ -2,7 +2,7 @@ require "cfoundry/v2/model"
2
2
 
3
3
  module CFoundry::V2
4
4
  class Organization < Model
5
- attribute :name
5
+ attribute :name, :string
6
6
  to_many :spaces
7
7
  to_many :domains
8
8
  to_many :users
@@ -2,8 +2,8 @@ require "cfoundry/v2/model"
2
2
 
3
3
  module CFoundry::V2
4
4
  class Runtime < Model
5
- attribute :name
6
- attribute :description
5
+ attribute :name, :string
6
+ attribute :description, :string
7
7
  to_many :apps
8
8
  end
9
9
  end
@@ -2,15 +2,16 @@ require "cfoundry/v2/model"
2
2
 
3
3
  module CFoundry::V2
4
4
  class Service < Model
5
- attribute :label
6
- attribute :provider
7
- attribute :url
8
- attribute :description
9
- attribute :version
10
- attribute :info_url
11
- attribute :acls
12
- attribute :timeout
13
- attribute :active
5
+ attribute :label, String
6
+ attribute :provider, String
7
+ attribute :url, :url
8
+ attribute :description, String
9
+ attribute :version, String
10
+ attribute :info_url, :url
11
+ attribute :acls, { "users" => [String], "wildcards" => [String] },
12
+ :default => nil
13
+ attribute :timeout, Integer, :default => nil
14
+ attribute :active, :boolean, :default => false
14
15
  to_many :service_plans
15
16
  end
16
17
  end
@@ -2,8 +2,8 @@ require "cfoundry/v2/model"
2
2
 
3
3
  module CFoundry::V2
4
4
  class ServiceAuthToken < Model
5
- attribute :label
6
- attribute :provider
7
- attribute :token
5
+ attribute :label, :string
6
+ attribute :provider, :string
7
+ attribute :token, :string
8
8
  end
9
9
  end
@@ -2,7 +2,7 @@ require "cfoundry/v2/model"
2
2
 
3
3
  module CFoundry::V2
4
4
  class ServiceInstance < Model
5
- attribute :name
5
+ attribute :name, :string
6
6
  to_one :space
7
7
  to_one :service_plan
8
8
  to_many :service_bindings
@@ -2,8 +2,8 @@ require "cfoundry/v2/model"
2
2
 
3
3
  module CFoundry::V2
4
4
  class ServicePlan < Model
5
- attribute :name
6
- attribute :description
5
+ attribute :name, :string
6
+ attribute :description, :string
7
7
  to_one :service
8
8
  to_many :service_instances
9
9
  end
@@ -2,7 +2,7 @@ require "cfoundry/v2/model"
2
2
 
3
3
  module CFoundry::V2
4
4
  class Space < Model
5
- attribute :name
5
+ attribute :name, :string
6
6
  to_one :organization
7
7
  to_many :developers, :as => :user
8
8
  to_many :managers, :as => :user
@@ -9,10 +9,10 @@ module CFoundry::V2
9
9
  to_many :audited_organizations, :as => :organization
10
10
  to_many :managed_spaces, :as => :space
11
11
  to_many :audited_spaces, :as => :space
12
- attribute :admin
12
+ attribute :admin, :boolean
13
13
  to_one :default_space, :as => :space
14
14
 
15
- attribute :guid # guid is explicitly set for users
15
+ attribute :guid, :string # guid is explicitly set for users
16
16
 
17
17
  def guid
18
18
  @guid
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.3.23"
3
+ VERSION = "0.3.24"
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: 61
4
+ hash: 35
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 23
10
- version: 0.3.23
9
+ - 24
10
+ version: 0.3.24
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-08-21 00:00:00 Z
18
+ date: 2012-08-29 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rest-client
@@ -71,12 +71,15 @@ dependencies:
71
71
  requirement: &id004 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
- - - ">="
74
+ - - ~>
75
75
  - !ruby/object:Gem::Version
76
- hash: 3
76
+ hash: 11
77
77
  segments:
78
78
  - 0
79
- version: "0"
79
+ - 9
80
+ - 2
81
+ - 2
82
+ version: 0.9.2.2
80
83
  type: :development
81
84
  version_requirements: *id004
82
85
  - !ruby/object:Gem::Dependency
@@ -85,12 +88,14 @@ dependencies:
85
88
  requirement: &id005 !ruby/object:Gem::Requirement
86
89
  none: false
87
90
  requirements:
88
- - - ">="
91
+ - - ~>
89
92
  - !ruby/object:Gem::Version
90
- hash: 3
93
+ hash: 35
91
94
  segments:
95
+ - 2
96
+ - 11
92
97
  - 0
93
- version: "0"
98
+ version: 2.11.0
94
99
  type: :development
95
100
  version_requirements: *id005
96
101
  description: