lib/cfoundry/v2/app.rb in cfoundry-0.3.33 vs lib/cfoundry/v2/app.rb in cfoundry-0.3.34
- old
+ new
@@ -32,11 +32,11 @@
to_many :routes
alias :total_instances :instances
alias :total_instances= :instances=
- private :environment_json, :environment_json=
+ private :environment_json
def instances
@client.base.instances(@guid).collect do |i, m|
Instance.new(self, i.to_s, @client, m)
end
@@ -51,18 +51,14 @@
end
def env
@env ||= CFoundry::ChattyHash.new(
method(:env=),
- MultiJson.load(environment_json))
+ environment_json)
end
- def env=(hash)
- @env = hash
- @diff["environment_json"] = hash
- hash
- end
+ alias :env= :environment_json=
def command # TODO v2
nil
end
@@ -79,20 +75,53 @@
"#{r.host}.#{r.domain.name}"
end
end
alias :urls :uris
- def uris=(x)
+ def uris=(uris)
raise "App#uris= is invalid against V2 APIs. Use add/remove_route."
end
alias :urls= :uris=
+ def create_routes(*uris)
+ uris.each do |uri|
+ host, domain_name = uri.split(".", 2)
+
+ domain =
+ @client.current_space.domains.find { |d|
+ d.name == domain_name
+ }
+
+ raise "Invalid domain '#{domain_name}'" unless domain
+
+ route = @client.routes.find { |r|
+ r.host == host && r.domain == domain
+ }
+
+ unless route
+ route = @client.route
+ route.host = host
+ route.domain = domain
+ route.organization = @client.current_organization
+ route.create!
+ end
+
+ add_route(route)
+ end
+ end
+ alias :create_route :create_routes
+
def uri
uris[0]
end
alias :url :uri
+ def uri=(x)
+ self.uris = [x]
+ end
+ alias :url= :uri=
+
# Stop the application.
def stop!
update! :state => "STOPPED"
end
@@ -119,10 +148,14 @@
# Check that all application instances are running.
def healthy?
# invalidate cache so the check is fresh
@manifest = nil
- health == "RUNNING"
+
+ case health
+ when "RUNNING", "STARTED"
+ true
+ end
end
alias_method :running?, :healthy?
# Is the application stopped?
def stopped?