lib/cfoundry/v2/app.rb in cfoundry-0.3.54 vs lib/cfoundry/v2/app.rb in cfoundry-0.3.55

- old
+ new

@@ -25,18 +25,55 @@ attribute :environment_json, :hash, :default => {} attribute :memory, :integer, :default => 256 attribute :instances, :integer, :default => 1 attribute :file_descriptors, :integer, :default => 256 attribute :disk_quota, :integer, :default => 256 - attribute :state, :integer, :default => "STOPPED" + attribute :state, :string, :default => "STOPPED" attribute :command, :string, :default => nil attribute :console, :boolean, :default => false to_many :service_bindings to_many :routes scoped_to_space + has_summary :urls => proc { |x| self.cache[:uris] = x }, + :running_instances => proc { |x| + self.cache[:running_instances] = x + }, + + # TODO: remove these when cc consistently returns nested hashes + :framework_guid => proc { |x| + if f = self.cache[:framework] + f.guid = x + else + self.framework = @client.framework(x, true) + end + }, + :framework_name => proc { |x| + if f = self.cache[:framework] + f.name = x + else + self.framework = @client.framework(nil, true) + self.framework.name = x + end + }, + :runtime_guid => proc { |x| + if f = self.cache[:runtime] + f.guid = x + else + self.runtime = @client.runtime(x, true) + end + }, + :runtime_name => proc { |x| + if f = self.cache[:runtime] + f.name = x + else + self.runtime = @client.runtime(nil, true) + self.runtime.name = x + end + } + alias :total_instances :instances alias :total_instances= :instances= private :environment_json @@ -79,10 +116,12 @@ def debug_mode # TODO v2 nil end def uris + return @cache[:uris] if @cache[:uris] + routes.collect do |r| "#{r.host}.#{r.domain.name}" end end alias :urls :uris @@ -119,10 +158,14 @@ end end alias :create_route :create_routes def uri + if uris = @cache[:uris] + return uris.first + end + if route = routes.first "#{route.host}.#{route.domain.name}" end end alias :url :uri @@ -173,9 +216,11 @@ state end end def running_instances + return @cache[:running_instances] if @cache[:running_instances] + running = 0 instances.each do |i| running += 1 if i.state == "RUNNING" end