mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
implementing lazy_load
This commit is contained in:
parent
bc8690c27d
commit
daec413bd1
2 changed files with 28 additions and 9 deletions
|
@ -28,6 +28,26 @@ module Fog
|
||||||
service.networks(:organization => self)
|
service.networks(:organization => self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def initialize(attrs={})
|
||||||
|
super(attrs)
|
||||||
|
[:description].each do |attr|
|
||||||
|
attributes[attr]='<non_set>' if attributes[attr].nil?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def description
|
||||||
|
reload if ( attributes[:description] == '<non_set>' and @inspecting == false )
|
||||||
|
attributes[:description]
|
||||||
|
end
|
||||||
|
|
||||||
|
def inspect
|
||||||
|
puts 'inspecting'
|
||||||
|
@inspecting = true
|
||||||
|
out = super
|
||||||
|
@inspecting = false
|
||||||
|
out
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,8 +8,8 @@ module Fog
|
||||||
class Organizations < Fog::Collection
|
class Organizations < Fog::Collection
|
||||||
model Fog::Compute::Vcloudng::Organization
|
model Fog::Compute::Vcloudng::Organization
|
||||||
|
|
||||||
def all(details=false)
|
def all(everyone=false)
|
||||||
details ? all_with_details : index
|
everyone ? get_everyone : index
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(org_id)
|
def get(org_id)
|
||||||
|
@ -21,14 +21,14 @@ module Fog
|
||||||
def get_by_name(org_name)
|
def get_by_name(org_name)
|
||||||
org = org_links.detect{|org| org[:name] == org_name}
|
org = org_links.detect{|org| org[:name] == org_name}
|
||||||
return nil unless org
|
return nil unless org
|
||||||
new(org)
|
get(org[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
load(org_links)
|
load(org_links)
|
||||||
end
|
end
|
||||||
|
|
||||||
def all_with_details
|
def get_everyone
|
||||||
orgs = org_links.map{|org| get_by_id(org[:id]) }
|
orgs = org_links.map{|org| get_by_id(org[:id]) }
|
||||||
load(orgs)
|
load(orgs)
|
||||||
end
|
end
|
||||||
|
@ -36,16 +36,15 @@ module Fog
|
||||||
# private
|
# private
|
||||||
|
|
||||||
def get_by_id(org_id)
|
def get_by_id(org_id)
|
||||||
data = service.get_organization(org_id).body
|
org = service.get_organization(org_id).body
|
||||||
data.delete(:Link)
|
org.delete(:Link)
|
||||||
service.add_id_from_href!(data)
|
service.add_id_from_href!(org)
|
||||||
data
|
org
|
||||||
end
|
end
|
||||||
|
|
||||||
def org_links
|
def org_links
|
||||||
data = service.get_organizations.body
|
data = service.get_organizations.body
|
||||||
org = data[:Org] # there is only a single Org
|
org = data[:Org] # there is only a single Org
|
||||||
org[:description]='<reload to see it>'
|
|
||||||
service.add_id_from_href!(org)
|
service.add_id_from_href!(org)
|
||||||
[org]
|
[org]
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue