virtengine_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.travis.yml +11 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +27 -0
- data/Rakefile +10 -0
- data/lib/megam/api.rb +329 -0
- data/lib/megam/api/accounts.rb +96 -0
- data/lib/megam/api/addons.rb +27 -0
- data/lib/megam/api/assemblies.rb +49 -0
- data/lib/megam/api/assembly.rb +56 -0
- data/lib/megam/api/backups.rb +57 -0
- data/lib/megam/api/balances.rb +45 -0
- data/lib/megam/api/billedhistories.rb +35 -0
- data/lib/megam/api/billingtransactions.rb +25 -0
- data/lib/megam/api/components.rb +24 -0
- data/lib/megam/api/credits.rb +34 -0
- data/lib/megam/api/disks.rb +44 -0
- data/lib/megam/api/domains.rb +25 -0
- data/lib/megam/api/errors.rb +29 -0
- data/lib/megam/api/eventsall.rb +36 -0
- data/lib/megam/api/eventsbilling.rb +35 -0
- data/lib/megam/api/eventscontainer.rb +35 -0
- data/lib/megam/api/eventsmarketplace.rb +35 -0
- data/lib/megam/api/eventsstorage.rb +24 -0
- data/lib/megam/api/eventsvm.rb +35 -0
- data/lib/megam/api/flavors.rb +56 -0
- data/lib/megam/api/license.rb +26 -0
- data/lib/megam/api/marketplaces.rb +68 -0
- data/lib/megam/api/organizations.rb +50 -0
- data/lib/megam/api/promos.rb +18 -0
- data/lib/megam/api/quotas.rb +47 -0
- data/lib/megam/api/rawimages.rb +36 -0
- data/lib/megam/api/reports.rb +24 -0
- data/lib/megam/api/requests.rb +36 -0
- data/lib/megam/api/sensors.rb +35 -0
- data/lib/megam/api/snapshots.rb +46 -0
- data/lib/megam/api/sshkeys.rb +35 -0
- data/lib/megam/api/subscriptions.rb +26 -0
- data/lib/megam/api/version.rb +6 -0
- data/lib/megam/core/account.rb +245 -0
- data/lib/megam/core/account_collection.rb +122 -0
- data/lib/megam/core/addons.rb +169 -0
- data/lib/megam/core/addons_collection.rb +121 -0
- data/lib/megam/core/assemblies.rb +191 -0
- data/lib/megam/core/assemblies_collection.rb +122 -0
- data/lib/megam/core/assembly.rb +226 -0
- data/lib/megam/core/assembly_collection.rb +122 -0
- data/lib/megam/core/backups.rb +259 -0
- data/lib/megam/core/backups_collection.rb +122 -0
- data/lib/megam/core/balances.rb +187 -0
- data/lib/megam/core/balances_collection.rb +121 -0
- data/lib/megam/core/billedhistories.rb +190 -0
- data/lib/megam/core/billedhistories_collection.rb +121 -0
- data/lib/megam/core/billingtransactions.rb +214 -0
- data/lib/megam/core/billingtransactions_collection.rb +122 -0
- data/lib/megam/core/components.rb +326 -0
- data/lib/megam/core/components_collection.rb +123 -0
- data/lib/megam/core/credits.rb +146 -0
- data/lib/megam/core/credits_collection.rb +121 -0
- data/lib/megam/core/disks.rb +199 -0
- data/lib/megam/core/disks_collection.rb +122 -0
- data/lib/megam/core/domain_collection.rb +122 -0
- data/lib/megam/core/domains.rb +118 -0
- data/lib/megam/core/error.rb +70 -0
- data/lib/megam/core/eventsall.rb +186 -0
- data/lib/megam/core/eventsall_collection.rb +122 -0
- data/lib/megam/core/eventsbilling.rb +174 -0
- data/lib/megam/core/eventsbilling_collection.rb +122 -0
- data/lib/megam/core/eventscontainer.rb +187 -0
- data/lib/megam/core/eventscontainer_collection.rb +122 -0
- data/lib/megam/core/eventsmarketplace.rb +187 -0
- data/lib/megam/core/eventsmarketplace_collection.rb +122 -0
- data/lib/megam/core/eventsstorage.rb +156 -0
- data/lib/megam/core/eventsstorage_collection.rb +122 -0
- data/lib/megam/core/eventsvm.rb +187 -0
- data/lib/megam/core/eventsvm_collection.rb +122 -0
- data/lib/megam/core/flavors.rb +294 -0
- data/lib/megam/core/flavors_collection.rb +121 -0
- data/lib/megam/core/json_compat.rb +289 -0
- data/lib/megam/core/konipai.rb +42 -0
- data/lib/megam/core/license.rb +101 -0
- data/lib/megam/core/license_collection.rb +122 -0
- data/lib/megam/core/log.rb +19 -0
- data/lib/megam/core/marketplace.rb +308 -0
- data/lib/megam/core/marketplace_collection.rb +123 -0
- data/lib/megam/core/monologger.rb +89 -0
- data/lib/megam/core/organizations.rb +142 -0
- data/lib/megam/core/organizations_collection.rb +121 -0
- data/lib/megam/core/promos.rb +145 -0
- data/lib/megam/core/quotas.rb +215 -0
- data/lib/megam/core/quotas_collection.rb +121 -0
- data/lib/megam/core/rawimages.rb +194 -0
- data/lib/megam/core/rawimages_collection.rb +121 -0
- data/lib/megam/core/reports.rb +176 -0
- data/lib/megam/core/reports_collection.rb +121 -0
- data/lib/megam/core/request.rb +197 -0
- data/lib/megam/core/request_collection.rb +121 -0
- data/lib/megam/core/rest_adapter.rb +44 -0
- data/lib/megam/core/sensors.rb +141 -0
- data/lib/megam/core/sensors_collection.rb +121 -0
- data/lib/megam/core/snapshots.rb +268 -0
- data/lib/megam/core/snapshots_collection.rb +122 -0
- data/lib/megam/core/sshkey.rb +173 -0
- data/lib/megam/core/sshkey_collection.rb +122 -0
- data/lib/megam/core/stuff.rb +22 -0
- data/lib/megam/core/subscriptions.rb +167 -0
- data/lib/megam/core/subscriptions_collection.rb +121 -0
- data/lib/megam/core/text.rb +87 -0
- data/lib/megam/core/text_formatter.rb +64 -0
- data/lib/megam/mixins/assemblies.rb +16 -0
- data/lib/megam/mixins/assembly.rb +59 -0
- data/lib/megam/mixins/common_deployable.rb +78 -0
- data/lib/megam/mixins/components.rb +182 -0
- data/lib/megam/mixins/megam_attributes.rb +30 -0
- data/lib/megam/mixins/outputs.rb +23 -0
- data/lib/megam/mixins/policies.rb +27 -0
- data/lib/megam_api.rb +1 -0
- data/megam_api.gemspec +26 -0
- data/test/mixins/test_assemblies.rb +113 -0
- data/test/mixins/test_assembly.rb +74 -0
- data/test/mixins/test_component.rb +19 -0
- data/test/test_accounts.rb +127 -0
- data/test/test_addons.rb +26 -0
- data/test/test_assemblies.rb +88 -0
- data/test/test_assembly.rb +37 -0
- data/test/test_backups.rb +29 -0
- data/test/test_balances.rb +38 -0
- data/test/test_billedhistories.rb +30 -0
- data/test/test_billingtranscations.rb +35 -0
- data/test/test_components.rb +42 -0
- data/test/test_credits.rb +28 -0
- data/test/test_disks.rb +25 -0
- data/test/test_domains.rb +29 -0
- data/test/test_eventsbilling.rb +30 -0
- data/test/test_eventscontainer.rb +26 -0
- data/test/test_eventsstorage.rb +12 -0
- data/test/test_eventsvm.rb +26 -0
- data/test/test_helper.rb +77 -0
- data/test/test_marketplaces.rb +38 -0
- data/test/test_organizations.rb +45 -0
- data/test/test_promos.rb +11 -0
- data/test/test_quotas.rb +33 -0
- data/test/test_reports.rb +32 -0
- data/test/test_requests.rb +95 -0
- data/test/test_sensors.rb +50 -0
- data/test/test_snapshots.rb +30 -0
- data/test/test_sshkeys.rb +50 -0
- data/test/test_subscriptions.rb +22 -0
- metadata +325 -0
@@ -0,0 +1,123 @@
|
|
1
|
+
module Megam
|
2
|
+
class MarketPlaceCollection
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
attr_reader :iterator
|
6
|
+
def initialize
|
7
|
+
@apps = Array.new
|
8
|
+
@apps_by_name = Hash.new
|
9
|
+
@insert_after_idx = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def all_apps
|
13
|
+
@apps
|
14
|
+
end
|
15
|
+
|
16
|
+
def [](index)
|
17
|
+
@apps[index]
|
18
|
+
end
|
19
|
+
|
20
|
+
def []=(index, arg)
|
21
|
+
is_megam_app(arg)
|
22
|
+
@apps[index] = arg
|
23
|
+
@apps_by_name[arg.flavor] = index
|
24
|
+
end
|
25
|
+
|
26
|
+
def <<(*args)
|
27
|
+
args.flatten.each do |a|
|
28
|
+
is_megam_app(a)
|
29
|
+
@apps << a
|
30
|
+
@apps_by_name[a.flavor] = @apps.length - 1
|
31
|
+
end
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
# 'push' is an alias method to <<
|
36
|
+
alias_method :push, :<<
|
37
|
+
|
38
|
+
def insert(app)
|
39
|
+
is_megam_app(app)
|
40
|
+
if @insert_after_idx
|
41
|
+
# in the middle of executing a run, so any nodes inserted now should
|
42
|
+
# be placed after the most recent addition done by the currently executing
|
43
|
+
# node
|
44
|
+
@apps.insert(@insert_after_idx + 1, app)
|
45
|
+
# update name -> location mappings and register new node
|
46
|
+
@apps_by_name.each_key do |key|
|
47
|
+
@apps_by_name[key] += 1 if @apps_by_name[key] > @insert_after_idx
|
48
|
+
end
|
49
|
+
@apps_by_name[app.flavor] = @insert_after_idx + 1
|
50
|
+
@insert_after_idx += 1
|
51
|
+
else
|
52
|
+
@apps << app
|
53
|
+
@apps_by_name[app.flavor] = @apps.length - 1
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def each
|
58
|
+
@apps.each do |app|
|
59
|
+
yield app
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def each_index
|
64
|
+
@apps.each_index do |i|
|
65
|
+
yield i
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def empty?
|
70
|
+
@apps.empty?
|
71
|
+
end
|
72
|
+
|
73
|
+
def lookup(app)
|
74
|
+
lookup_by = nil
|
75
|
+
if app.kind_of?(Megam::MarketPlace)
|
76
|
+
lookup_by = app.flavor
|
77
|
+
elsif app.kind_of?(String)
|
78
|
+
lookup_by = app
|
79
|
+
else
|
80
|
+
raise ArgumentError, "Must pass a Megam::MarketPlace or String to lookup"
|
81
|
+
end
|
82
|
+
res = @apps_by_name[lookup_by]
|
83
|
+
unless res
|
84
|
+
raise ArgumentError, "Cannot find a app matching #{lookup_by} (did you define it first?)"
|
85
|
+
end
|
86
|
+
@apps[res]
|
87
|
+
end
|
88
|
+
|
89
|
+
def to_s
|
90
|
+
@apps.join(", ")
|
91
|
+
end
|
92
|
+
|
93
|
+
def for_json
|
94
|
+
to_a.map { |item| item.to_s }
|
95
|
+
end
|
96
|
+
|
97
|
+
def to_json(*a)
|
98
|
+
Megam::JSONCompat.to_json(for_json, *a)
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.json_create(o)
|
102
|
+
collection = self.new()
|
103
|
+
o["results"].each do |apps_list|
|
104
|
+
apps_array = apps_list.kind_of?(Array) ? apps_list : [ apps_list ]
|
105
|
+
apps_array.each do |app|
|
106
|
+
collection.insert(app)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
collection
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
def is_megam_app(arg)
|
117
|
+
unless arg.kind_of?(Megam::MarketPlace)
|
118
|
+
raise ArgumentError, "Members must be Megam::MarketPlace's"
|
119
|
+
end
|
120
|
+
true
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
module Megam
|
5
|
+
#== MonoLogger
|
6
|
+
# A subclass of Ruby's stdlib Logger with all the mutex and logrotation stuff
|
7
|
+
# ripped out.
|
8
|
+
class MonoLogger < Logger
|
9
|
+
#
|
10
|
+
# === Synopsis
|
11
|
+
#
|
12
|
+
# Logger.new(name, shift_age = 7, shift_size = 1048576)
|
13
|
+
# Logger.new(name, shift_age = 'weekly')
|
14
|
+
#
|
15
|
+
# === Args
|
16
|
+
#
|
17
|
+
# +logdev+::
|
18
|
+
# The log device. This is a filename (String) or IO object (typically
|
19
|
+
# +STDOUT+, +STDERR+, or an open file).
|
20
|
+
# +shift_age+::
|
21
|
+
# Number of old log files to keep, *or* frequency of rotation (+daily+,
|
22
|
+
# +weekly+ or +monthly+).
|
23
|
+
# +shift_size+::
|
24
|
+
# Maximum logfile size (only applies when +shift_age+ is a number).
|
25
|
+
#
|
26
|
+
# === Description
|
27
|
+
#
|
28
|
+
# Create an instance.
|
29
|
+
#
|
30
|
+
def initialize(logdev)
|
31
|
+
@progname = nil
|
32
|
+
@level = DEBUG
|
33
|
+
@default_formatter = Formatter.new
|
34
|
+
@formatter = nil
|
35
|
+
@logdev = nil
|
36
|
+
if logdev
|
37
|
+
@logdev = LocklessLogDevice.new(logdev)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class LocklessLogDevice < LogDevice
|
42
|
+
def initialize(log = nil)
|
43
|
+
@dev = @filename = @shift_age = @shift_size = nil
|
44
|
+
if log.respond_to?(:write) and log.respond_to?(:close)
|
45
|
+
@dev = log
|
46
|
+
else
|
47
|
+
@dev = open_logfile(log)
|
48
|
+
@dev.sync = true
|
49
|
+
@filename = log
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def write(message)
|
54
|
+
@dev.write(message)
|
55
|
+
rescue Exception => ignored
|
56
|
+
warn("log writing failed. #{ignored}")
|
57
|
+
end
|
58
|
+
|
59
|
+
def close
|
60
|
+
@dev.close rescue nil
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def open_logfile(filename)
|
66
|
+
if (FileTest.exist?(filename))
|
67
|
+
open(filename, (File::WRONLY | File::APPEND))
|
68
|
+
else
|
69
|
+
create_logfile(filename)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def create_logfile(filename)
|
74
|
+
logdev = open(filename, (File::WRONLY | File::APPEND | File::CREAT))
|
75
|
+
logdev.sync = true
|
76
|
+
add_log_header(logdev)
|
77
|
+
logdev
|
78
|
+
end
|
79
|
+
|
80
|
+
def add_log_header(file)
|
81
|
+
file.write(
|
82
|
+
"# Logfile created on %s by %s\n" % [Time.now.to_s, Logger::ProgName]
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
module Megam
|
2
|
+
class Organizations < Megam::RestAdapter
|
3
|
+
def initialize(o)
|
4
|
+
@id = nil
|
5
|
+
@name = nil
|
6
|
+
@accounts_id = nil
|
7
|
+
@related_orgs = []
|
8
|
+
@created_at = nil
|
9
|
+
super(o)
|
10
|
+
end
|
11
|
+
|
12
|
+
def organization
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def id(arg=nil)
|
17
|
+
if arg != nil
|
18
|
+
@id = arg
|
19
|
+
else
|
20
|
+
@id
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def accounts_id(arg=nil)
|
25
|
+
if arg != nil
|
26
|
+
@accounts_id = arg
|
27
|
+
else
|
28
|
+
@accounts_id
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def name(arg=nil)
|
33
|
+
if arg != nil
|
34
|
+
@name = arg
|
35
|
+
else
|
36
|
+
@name
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def related_orgs(arg=[])
|
41
|
+
if arg != []
|
42
|
+
@related_orgs = arg
|
43
|
+
else
|
44
|
+
@related_orgs
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def created_at(arg=nil)
|
49
|
+
if arg != nil
|
50
|
+
@created_at = arg
|
51
|
+
else
|
52
|
+
@created_at
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Transform the ruby obj -> to a Hash
|
57
|
+
def to_hash
|
58
|
+
index_hash = Hash.new
|
59
|
+
index_hash["json_claz"] = self.class.name
|
60
|
+
index_hash["id"] = id
|
61
|
+
index_hash["name"] = name
|
62
|
+
index_hash["accounts_id"] = accounts_id
|
63
|
+
index_hash["related_orgs"] = related_orgs
|
64
|
+
index_hash["created_at"] = created_at
|
65
|
+
index_hash
|
66
|
+
end
|
67
|
+
|
68
|
+
def to_json(*a)
|
69
|
+
for_json.to_json(*a)
|
70
|
+
end
|
71
|
+
|
72
|
+
def for_json
|
73
|
+
result = {
|
74
|
+
"id" => id,
|
75
|
+
"name" => name,
|
76
|
+
"accounts_id" => accounts_id,
|
77
|
+
"related_orgs" => related_orgs,
|
78
|
+
"created_at" => created_at
|
79
|
+
}
|
80
|
+
result
|
81
|
+
end
|
82
|
+
|
83
|
+
# Create a Megam::Organization from JSON (used by the backgroud job workers)
|
84
|
+
def self.json_create(o)
|
85
|
+
org = new({})
|
86
|
+
org.id(o["id"]) if o.has_key?("id")
|
87
|
+
org.name(o["name"]) if o.has_key?("name")
|
88
|
+
org.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id")
|
89
|
+
org.related_orgs(o["related_orgs"]) if o.has_key?("related_orgs")
|
90
|
+
org.created_at(o["created_at"]) if o.has_key?("created_at")
|
91
|
+
org
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.from_hash(o)
|
95
|
+
org = self.new(o)
|
96
|
+
org.from_hash(o)
|
97
|
+
org
|
98
|
+
end
|
99
|
+
|
100
|
+
def from_hash(o)
|
101
|
+
@id = o[:id] if o.has_key?(:id)
|
102
|
+
@name = o[:name] if o.has_key?(:name)
|
103
|
+
@accounts_id = o[:accounts_id] if o.has_key?(:accounts_id)
|
104
|
+
@related_orgs = o[:related_orgs] if o.has_key?(:related_orgs)
|
105
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
106
|
+
self
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.create(o)
|
110
|
+
org = from_hash(o)
|
111
|
+
org.create
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.show(o)
|
115
|
+
org = from_hash(o)
|
116
|
+
org.megam_rest.get_organizations(email)
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.update(o)
|
120
|
+
org = from_hash(o)
|
121
|
+
org.update
|
122
|
+
end
|
123
|
+
|
124
|
+
def update
|
125
|
+
megam_rest.update_organization(to_hash)
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.list(o)
|
129
|
+
org = from_hash(o)
|
130
|
+
org.megam_rest.get_organizations
|
131
|
+
end
|
132
|
+
|
133
|
+
def create
|
134
|
+
megam_rest.post_organization(to_hash)
|
135
|
+
end
|
136
|
+
|
137
|
+
def to_s
|
138
|
+
Megam::Stuff.styled_hash(to_hash)
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
module Megam
|
2
|
+
class OrganizationsCollection
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
attr_reader :iterator
|
6
|
+
def initialize
|
7
|
+
@organizations = Array.new
|
8
|
+
@organizations_by_name = Hash.new
|
9
|
+
@insert_after_idx = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def all_organizations
|
13
|
+
@organizations
|
14
|
+
end
|
15
|
+
|
16
|
+
def [](index)
|
17
|
+
@organizations[index]
|
18
|
+
end
|
19
|
+
|
20
|
+
def []=(index, arg)
|
21
|
+
is_megam_organizations(arg)
|
22
|
+
@organizations[index] = arg
|
23
|
+
@organizations_by_name[arg.name] = index
|
24
|
+
end
|
25
|
+
|
26
|
+
def <<(*args)
|
27
|
+
args.flatten.each do |a|
|
28
|
+
is_megam_organizations(a)
|
29
|
+
@organizations << a
|
30
|
+
@organizations_by_name[a.name] =@organizations.length - 1
|
31
|
+
end
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
# 'push' is an alias method to <<
|
36
|
+
alias_method :push, :<<
|
37
|
+
|
38
|
+
def insert(organizations)
|
39
|
+
is_megam_organizations(organizations)
|
40
|
+
if @insert_after_idx
|
41
|
+
# in the middle of executing a run, so any predefs inserted now should
|
42
|
+
# be placed after the most recent addition done by the currently executing
|
43
|
+
# predefclouds
|
44
|
+
@organizations.insert(@insert_after_idx + 1, organizations)
|
45
|
+
# update name -> location mappings and register new predefclouds
|
46
|
+
@organizations_by_name.each_key do |key|
|
47
|
+
@organizations_by_name[key] += 1 if@organizations_by_name[key] > @insert_after_idx
|
48
|
+
end
|
49
|
+
@organizations_by_name[organizations.name] = @insert_after_idx + 1
|
50
|
+
@insert_after_idx += 1
|
51
|
+
else
|
52
|
+
@organizations << organizations
|
53
|
+
@organizations_by_name[organizations.name] =@organizations.length - 1
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def each
|
58
|
+
@organizations.each do |organizations|
|
59
|
+
yield organizations
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def each_index
|
64
|
+
@organizations.each_index do |i|
|
65
|
+
yield i
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def empty?
|
70
|
+
@organizations.empty?
|
71
|
+
end
|
72
|
+
|
73
|
+
def lookup(organizations)
|
74
|
+
lookup_by = nil
|
75
|
+
if organizations.kind_of?(Megam::Organizations)
|
76
|
+
lookup_by = organizations.name
|
77
|
+
elsif organizations.kind_of?(String)
|
78
|
+
lookup_by = organizations
|
79
|
+
else
|
80
|
+
raise ArgumentError, "Must pass a Megam::PredefClouds or String to lookup"
|
81
|
+
end
|
82
|
+
res =@organizations_by_name[lookup_by]
|
83
|
+
unless res
|
84
|
+
raise ArgumentError, "Cannot find a predefclouds matching #{lookup_by} (did you define it first?)"
|
85
|
+
end
|
86
|
+
@organizations[res]
|
87
|
+
end
|
88
|
+
|
89
|
+
def to_s
|
90
|
+
@organizations.join(", ")
|
91
|
+
end
|
92
|
+
|
93
|
+
def for_json
|
94
|
+
to_a.map { |item| item.to_s }
|
95
|
+
end
|
96
|
+
|
97
|
+
def to_json(*a)
|
98
|
+
Megam::JSONCompat.to_json(for_json, *a)
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.json_create(o)
|
102
|
+
collection = self.new()
|
103
|
+
o["results"].each do |organizations_list|
|
104
|
+
organizations_array = organizations_list.kind_of?(Array) ? organizations_list : [ organizations_list ]
|
105
|
+
organizations_array.each do |organizations|
|
106
|
+
collection.insert(organizations)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
collection
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def is_megam_organizations(arg)
|
115
|
+
unless arg.kind_of?(Megam::Organizations)
|
116
|
+
raise ArgumentError, "Members must be Megam::Organizations's"
|
117
|
+
end
|
118
|
+
true
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|