ocs 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/docs/resources.md +278 -0
- data/lib/ocs.rb +1 -1
- data/lib/ocs/client.rb +1 -1
- data/lib/ocs/document/generator.rb +111 -0
- data/lib/ocs/document/patches/ocs/resources/base.rb +18 -0
- data/lib/ocs/document/templates/_resource.md.erb +8 -0
- data/lib/ocs/document/templates/resources.md.erb +4 -0
- data/lib/ocs/errors.rb +6 -0
- data/lib/ocs/resources.rb +3 -1
- data/lib/ocs/resources/base.rb +5 -94
- data/lib/ocs/resources/dynamic_definers.rb +94 -0
- data/lib/ocs/version.rb +1 -1
- data/ocs.gemspec +1 -0
- metadata +24 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8c215e6924e10df79b386df078dc3d8a29b4674
|
4
|
+
data.tar.gz: afef6522a19430d1311ef964dd5abb24fbb6268a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bd0b3b9d4bc4ce58a8fba98faa8f15fbad18caa8a22f302b290c49b4f6ab05bae9aa948262130b02b30f917b2abcb380b984739acd035a45f8014caf1a972a6
|
7
|
+
data.tar.gz: dfda45f337a17f60d9011c155023f4ebffbb5cf2ce2e2786ee60074f84f4d0869551c8ddd9b8cfd50d064b13d2786bff3e20af82d0ba495d61db049eb9919861
|
data/docs/resources.md
ADDED
@@ -0,0 +1,278 @@
|
|
1
|
+
Resouces
|
2
|
+
========
|
3
|
+
|
4
|
+
## Account
|
5
|
+
### Attributes
|
6
|
+
|
7
|
+
Attribute | Type
|
8
|
+
---|---
|
9
|
+
name | String
|
10
|
+
|
11
|
+
## Address
|
12
|
+
### Attributes
|
13
|
+
|
14
|
+
Attribute | Type
|
15
|
+
---|---
|
16
|
+
|
17
|
+
## AffinityGroup
|
18
|
+
### Attributes
|
19
|
+
|
20
|
+
Attribute | Type
|
21
|
+
---|---
|
22
|
+
|
23
|
+
## AsyncJob
|
24
|
+
### Attributes
|
25
|
+
|
26
|
+
Attribute | Type
|
27
|
+
---|---
|
28
|
+
jobid | String
|
29
|
+
jobstatus | Integer
|
30
|
+
|
31
|
+
## Base
|
32
|
+
### Attributes
|
33
|
+
|
34
|
+
Attribute | Type
|
35
|
+
---|---
|
36
|
+
|
37
|
+
## DiskOffering
|
38
|
+
### Attributes
|
39
|
+
|
40
|
+
Attribute | Type
|
41
|
+
---|---
|
42
|
+
name | String
|
43
|
+
|
44
|
+
## Domain
|
45
|
+
### Attributes
|
46
|
+
|
47
|
+
Attribute | Type
|
48
|
+
---|---
|
49
|
+
haschild | [TrueClass, FalseClass]
|
50
|
+
level | Integer
|
51
|
+
name | String
|
52
|
+
path | String
|
53
|
+
|
54
|
+
## Group
|
55
|
+
### Attributes
|
56
|
+
|
57
|
+
Attribute | Type
|
58
|
+
---|---
|
59
|
+
name | String
|
60
|
+
|
61
|
+
## Host
|
62
|
+
### Attributes
|
63
|
+
|
64
|
+
Attribute | Type
|
65
|
+
---|---
|
66
|
+
name | String
|
67
|
+
|
68
|
+
## Iso
|
69
|
+
### Attributes
|
70
|
+
|
71
|
+
Attribute | Type
|
72
|
+
---|---
|
73
|
+
displaytext | String
|
74
|
+
name | String
|
75
|
+
|
76
|
+
## Network
|
77
|
+
### Attributes
|
78
|
+
|
79
|
+
Attribute | Type
|
80
|
+
---|---
|
81
|
+
account | String
|
82
|
+
aclid | String
|
83
|
+
acltype | String
|
84
|
+
broadcastdomaintype | String
|
85
|
+
broadcasturi | String
|
86
|
+
canusefordeploy | [TrueClass, FalseClass]
|
87
|
+
cidr | String
|
88
|
+
displaynetwork | [TrueClass, FalseClass]
|
89
|
+
displaytext | String
|
90
|
+
dns1 | String
|
91
|
+
dns2 | String
|
92
|
+
gateway | String
|
93
|
+
ip6cidr | String
|
94
|
+
ip6gateway | String
|
95
|
+
isdefault | [TrueClass, FalseClass]
|
96
|
+
ispersistent | [TrueClass, FalseClass]
|
97
|
+
issystem | [TrueClass, FalseClass]
|
98
|
+
name | String
|
99
|
+
netmask | String
|
100
|
+
networkcidr | String
|
101
|
+
networkdomain | String
|
102
|
+
networkofferingavailability | String
|
103
|
+
networkofferingconservemode | [TrueClass, FalseClass]
|
104
|
+
networkofferingdisplaytext | String
|
105
|
+
networkofferingid | String
|
106
|
+
networkofferingname | String
|
107
|
+
physicalnetworkid | String
|
108
|
+
related | String
|
109
|
+
reservediprange | String
|
110
|
+
restartrequired | [TrueClass, FalseClass]
|
111
|
+
service | Array
|
112
|
+
specifyipranges | [TrueClass, FalseClass]
|
113
|
+
state | String
|
114
|
+
subdomainaccess | [TrueClass, FalseClass]
|
115
|
+
traffictype | String
|
116
|
+
type | String
|
117
|
+
vlan | String
|
118
|
+
vpcid | String
|
119
|
+
|
120
|
+
## Nic
|
121
|
+
### Attributes
|
122
|
+
|
123
|
+
Attribute | Type
|
124
|
+
---|---
|
125
|
+
broadcasturi | String
|
126
|
+
gateway | String
|
127
|
+
ipaddress | String
|
128
|
+
isdefault | [TrueClass, FalseClass]
|
129
|
+
isolationuri | String
|
130
|
+
macaddress | String
|
131
|
+
netmask | String
|
132
|
+
networkid | String
|
133
|
+
networkname | String
|
134
|
+
traffictype | String
|
135
|
+
type | String
|
136
|
+
|
137
|
+
## OsType
|
138
|
+
### Attributes
|
139
|
+
|
140
|
+
Attribute | Type
|
141
|
+
---|---
|
142
|
+
description | String
|
143
|
+
|
144
|
+
## ResourceDetail
|
145
|
+
### Attributes
|
146
|
+
|
147
|
+
Attribute | Type
|
148
|
+
---|---
|
149
|
+
type | String
|
150
|
+
|
151
|
+
## SecurityGroup
|
152
|
+
### Attributes
|
153
|
+
|
154
|
+
Attribute | Type
|
155
|
+
---|---
|
156
|
+
|
157
|
+
## ServiceOffering
|
158
|
+
### Attributes
|
159
|
+
|
160
|
+
Attribute | Type
|
161
|
+
---|---
|
162
|
+
cpunumber | Integer
|
163
|
+
cpuspeed | Integer
|
164
|
+
created | String
|
165
|
+
defaultuse | [TrueClass, FalseClass]
|
166
|
+
deploymentplanner | String
|
167
|
+
diskBytesReadRate | Integer
|
168
|
+
diskBytesWriteRate | Integer
|
169
|
+
diskIopsReadRate | Integer
|
170
|
+
diskIopsWriteRate | Integer
|
171
|
+
displaytext | String
|
172
|
+
hosttags | String
|
173
|
+
iscustomized | [TrueClass, FalseClass]
|
174
|
+
issystem | [TrueClass, FalseClass]
|
175
|
+
isvolatile | [TrueClass, FalseClass]
|
176
|
+
limitcpuuse | [TrueClass, FalseClass]
|
177
|
+
memory | Integer
|
178
|
+
name | String
|
179
|
+
networkrate | Integer
|
180
|
+
offerha | [TrueClass, FalseClass]
|
181
|
+
serviceofferingdetails | Hash
|
182
|
+
storagetype | String
|
183
|
+
systemvmtype | String
|
184
|
+
tags | String
|
185
|
+
|
186
|
+
## SshKeyPair
|
187
|
+
### Attributes
|
188
|
+
|
189
|
+
Attribute | Type
|
190
|
+
---|---
|
191
|
+
fingerprint | String
|
192
|
+
name | String
|
193
|
+
|
194
|
+
## Tag
|
195
|
+
### Attributes
|
196
|
+
|
197
|
+
Attribute | Type
|
198
|
+
---|---
|
199
|
+
key | String
|
200
|
+
value | String
|
201
|
+
resourcetype | String
|
202
|
+
|
203
|
+
## Template
|
204
|
+
### Attributes
|
205
|
+
|
206
|
+
Attribute | Type
|
207
|
+
---|---
|
208
|
+
bootable | [TrueClass, FalseClass]
|
209
|
+
checksum | String
|
210
|
+
created | String
|
211
|
+
crossZones | [TrueClass, FalseClass]
|
212
|
+
details | Hash
|
213
|
+
displaytext | String
|
214
|
+
format | String
|
215
|
+
hypervisor | String
|
216
|
+
isdynamicallyscalable | [TrueClass, FalseClass]
|
217
|
+
isextractable | [TrueClass, FalseClass]
|
218
|
+
isfeatured | [TrueClass, FalseClass]
|
219
|
+
ispublic | [TrueClass, FalseClass]
|
220
|
+
isready | [TrueClass, FalseClass]
|
221
|
+
name | String
|
222
|
+
passwordenabled | [TrueClass, FalseClass]
|
223
|
+
removed | [TrueClass, FalseClass]
|
224
|
+
size | Integer
|
225
|
+
sshkeyenabled | [TrueClass, FalseClass]
|
226
|
+
status | String
|
227
|
+
templatetag | String
|
228
|
+
templatetype | String
|
229
|
+
|
230
|
+
## VirtualMachine
|
231
|
+
### Attributes
|
232
|
+
|
233
|
+
Attribute | Type
|
234
|
+
---|---
|
235
|
+
cpunumber | Integer
|
236
|
+
cpuspeed | Integer
|
237
|
+
cpuused | String
|
238
|
+
created | String
|
239
|
+
displayname | String
|
240
|
+
displayvm | [TrueClass, FalseClass]
|
241
|
+
haenable | [TrueClass, FalseClass]
|
242
|
+
hypervisor | String
|
243
|
+
instancename | String
|
244
|
+
isdynamicallyscalable | [TrueClass, FalseClass]
|
245
|
+
memory | Integer
|
246
|
+
name | String
|
247
|
+
networkkbsread | Integer
|
248
|
+
networkkbswrite | Integer
|
249
|
+
passwordenabled | [TrueClass, FalseClass]
|
250
|
+
rootdeviceid | Integer
|
251
|
+
rootdevicetype | String
|
252
|
+
state | String
|
253
|
+
|
254
|
+
## Zone
|
255
|
+
### Attributes
|
256
|
+
|
257
|
+
Attribute | Type
|
258
|
+
---|---
|
259
|
+
allocationstate | String
|
260
|
+
capacity | Hash
|
261
|
+
description | String
|
262
|
+
dhcpprovider | String
|
263
|
+
displaytext | String
|
264
|
+
dns1 | String
|
265
|
+
dns2 | String
|
266
|
+
guestcidraddress | String
|
267
|
+
internaldns1 | String
|
268
|
+
internaldns2 | String
|
269
|
+
ip6dns1 | String
|
270
|
+
ip6dns2 | String
|
271
|
+
localstorageenabled | [TrueClass, FalseClass]
|
272
|
+
name | String
|
273
|
+
networktype | String
|
274
|
+
resourcedetails | Hash
|
275
|
+
securitygroupsenabled | [TrueClass, FalseClass]
|
276
|
+
vlan | String
|
277
|
+
zonetoken | String
|
278
|
+
|
data/lib/ocs.rb
CHANGED
data/lib/ocs/client.rb
CHANGED
@@ -54,7 +54,7 @@ module Ocs
|
|
54
54
|
|
55
55
|
raw_resource_name, *arguments = args
|
56
56
|
resource_name = raw_resource_name.to_s.singularize
|
57
|
-
if Resources.const_defined?(resource_name.camelize)
|
57
|
+
if Ocs::Resources.const_defined?(resource_name.camelize)
|
58
58
|
return resource_class(resource_name).public_send(method, self, *arguments)
|
59
59
|
end
|
60
60
|
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require "active_support/core_ext/class/attribute"
|
2
|
+
require "active_support/core_ext/string/inflections"
|
3
|
+
require "erubis"
|
4
|
+
|
5
|
+
module Ocs
|
6
|
+
module Document
|
7
|
+
class Generator
|
8
|
+
class_attribute :resources
|
9
|
+
self.resources = {}
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def documents_path
|
13
|
+
File.expand_path("../../../../docs", __FILE__)
|
14
|
+
end
|
15
|
+
|
16
|
+
def library_path
|
17
|
+
File.expand_path("../../../", __FILE__)
|
18
|
+
end
|
19
|
+
|
20
|
+
def ocs_path
|
21
|
+
File.join(library_path, "ocs")
|
22
|
+
end
|
23
|
+
|
24
|
+
def patches_path
|
25
|
+
File.join(ocs_path, "document/patches")
|
26
|
+
end
|
27
|
+
|
28
|
+
def resources_path
|
29
|
+
File.join(ocs_path, "resources")
|
30
|
+
end
|
31
|
+
|
32
|
+
def resource_paths
|
33
|
+
Dir[File.join(resources_path, "*.rb")]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def initialize
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def generate
|
42
|
+
require "ocs/errors"
|
43
|
+
Patches.patch("ocs/resources/base")
|
44
|
+
self.class.resource_paths.each do |resource|
|
45
|
+
name = resource.sub(/^.+\//, "").sub(/\.rb$/, "").camelize
|
46
|
+
self.class.resources[name] = {}
|
47
|
+
require resource
|
48
|
+
end
|
49
|
+
output
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def output
|
55
|
+
output_resources
|
56
|
+
end
|
57
|
+
|
58
|
+
def output_resources
|
59
|
+
File.write(File.join(self.class.documents_path, "resources.md"), resources_markdown)
|
60
|
+
end
|
61
|
+
|
62
|
+
def render_resource_markdown(name, attributes)
|
63
|
+
p name
|
64
|
+
p attributes
|
65
|
+
::Erubis::Eruby.new(resource_template).evaluate(name: name, attributes: attributes)
|
66
|
+
end
|
67
|
+
|
68
|
+
def resource_template
|
69
|
+
File.read(File.expand_path("../templates/_resource.md.erb", __FILE__))
|
70
|
+
end
|
71
|
+
|
72
|
+
def resources_contents
|
73
|
+
self.class.resources.map { |name, attributes| render_resource_markdown(name, attributes) }
|
74
|
+
end
|
75
|
+
|
76
|
+
def resources_markdown
|
77
|
+
::Erubis::Eruby.new(resources_template).evaluate { resources_contents.join("\n") }
|
78
|
+
end
|
79
|
+
|
80
|
+
def resources_template
|
81
|
+
File.read(File.expand_path("../templates/resources.md.erb", __FILE__))
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
module Patches
|
86
|
+
class << self
|
87
|
+
def patch(target_class_path)
|
88
|
+
patch_class_path = "ocs/document/patches/#{target_class_path}"
|
89
|
+
require target_class_path
|
90
|
+
require patch_class_path
|
91
|
+
target_class = target_class_path.camelize.constantize
|
92
|
+
patch_class = patch_class_path.camelize.constantize
|
93
|
+
target_class.prepend(patch_class)
|
94
|
+
if patch_class.const_defined?(:ClassMethods)
|
95
|
+
target_class.singleton_class.instance_eval { self.prepend(patch_class::ClassMethods) }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
module Ocs
|
101
|
+
module Resources
|
102
|
+
module Base
|
103
|
+
module ClassMethods
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Ocs
|
2
|
+
module Document
|
3
|
+
module Patches
|
4
|
+
module Ocs
|
5
|
+
module Resources
|
6
|
+
module Base
|
7
|
+
module ClassMethods
|
8
|
+
def define_attribute(attribute_name, type:)
|
9
|
+
::Ocs::Document::Generator.resources[to_s.split(/::/).last][attribute_name] = {type: type}
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/ocs/errors.rb
ADDED
data/lib/ocs/resources.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
require "ocs/resources/dynamic_definers"
|
2
|
+
require "ocs/resources/base"
|
3
|
+
|
1
4
|
module Ocs
|
2
5
|
module Resources
|
3
6
|
autoload :Account, "ocs/resources/account"
|
4
7
|
autoload :Address, "ocs/resources/address"
|
5
8
|
autoload :AffinityGroup, "ocs/resources/affinity_group"
|
6
9
|
autoload :AsyncJob, "ocs/resources/async_job"
|
7
|
-
autoload :Base, "ocs/resources/base"
|
8
10
|
autoload :DiskOffering, "ocs/resources/disk_offering"
|
9
11
|
autoload :Domain, "ocs/resources/domain"
|
10
12
|
autoload :Group, "ocs/resources/group"
|
data/lib/ocs/resources/base.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
module Ocs
|
2
2
|
module Resources
|
3
|
-
class AttributeTypeError < OcsError; end
|
4
|
-
class AttributeClassError < OcsError; end
|
5
|
-
class MissingKeyError < OcsError; end
|
6
|
-
|
7
3
|
class Base
|
8
4
|
BOOLEAN = [TrueClass, FalseClass].freeze
|
9
5
|
|
@@ -11,6 +7,8 @@ module Ocs
|
|
11
7
|
self.delegations = {}
|
12
8
|
|
13
9
|
class << self
|
10
|
+
include DynamicDefiners
|
11
|
+
|
14
12
|
def all(client)
|
15
13
|
list(client)
|
16
14
|
end
|
@@ -65,99 +63,12 @@ module Ocs
|
|
65
63
|
end
|
66
64
|
end
|
67
65
|
end
|
68
|
-
|
69
|
-
# Dynamic Definitions
|
70
|
-
|
71
|
-
def alias_attribute(new_name, original_name)
|
72
|
-
alias_method new_name, original_name
|
73
|
-
alias_method :"#{new_name}=", :"#{original_name}="
|
74
|
-
end
|
75
|
-
|
76
|
-
def define_action(action_name, required: [], optional: [], api_name: nil)
|
77
|
-
define_method(action_name) do |special_parameters = {}|
|
78
|
-
api = api_name || "#{action_name}#{self.class.name}"
|
79
|
-
parameters = action_parameters(required, optional).merge(special_parameters)
|
80
|
-
send_and_update(api, parameters)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def define_attribute(attribute_name, type:)
|
85
|
-
define_method(:"#{attribute_name}=") do |value|
|
86
|
-
unless [*type].any? { |type| value.is_a?(type) }
|
87
|
-
raise AttributeTypeError.new(
|
88
|
-
"#{attribute_name} needs to be a #{[*type].join(" or ")}"
|
89
|
-
)
|
90
|
-
end
|
91
|
-
instance_variable_set(:"@#{attribute_name}", value)
|
92
|
-
end
|
93
|
-
|
94
|
-
attr_reader attribute_name
|
95
|
-
end
|
96
|
-
|
97
|
-
def delegate_attribute(attribute_name, to:, as:)
|
98
|
-
writer_method_name = :"#{to}_#{as}="
|
99
|
-
define_method(writer_method_name) do |value|
|
100
|
-
instance =
|
101
|
-
public_send(to) ||
|
102
|
-
public_send(:"#{to}=", resource_class(to).new(client))
|
103
|
-
instance.public_send(:"#{as}=", value)
|
104
|
-
end
|
105
|
-
delegations[attribute_name] = writer_method_name
|
106
|
-
|
107
|
-
define_method(:"#{to}_#{as}") do
|
108
|
-
instance = public_send(to)
|
109
|
-
instance && instance.public_send(as)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def delegate_attributes(attribute_name, to:)
|
114
|
-
delegations[attribute_name] = :"#{to}="
|
115
|
-
end
|
116
|
-
|
117
|
-
def has_one(attribute_name)
|
118
|
-
define_method(:"#{attribute_name}=") do |value|
|
119
|
-
klass = resource_class(attribute_name)
|
120
|
-
unless value.instance_of?(klass)
|
121
|
-
raise AttributeClassError.new(
|
122
|
-
"#{attribute_name} needs to be an instance of #{klass}"
|
123
|
-
)
|
124
|
-
end
|
125
|
-
instance_variable_set(:"@#{attribute_name}", value)
|
126
|
-
end
|
127
|
-
|
128
|
-
attr_reader attribute_name
|
129
|
-
end
|
130
|
-
|
131
|
-
def has_many(attribute_name)
|
132
|
-
define_method(:"#{attribute_name}=") do |values|
|
133
|
-
unless values.is_a?(Array)
|
134
|
-
raise AttributeTypeError.new("#{attribute_name} needs to be a Array")
|
135
|
-
end
|
136
|
-
|
137
|
-
klass = resource_class(attribute_name.to_s.singularize)
|
138
|
-
instances = values.map do |value|
|
139
|
-
case value
|
140
|
-
when klass
|
141
|
-
value
|
142
|
-
when Hash
|
143
|
-
klass.new(client, value)
|
144
|
-
else
|
145
|
-
raise AttributeClassError.new(
|
146
|
-
"elements of #{attribute_name} need to be instances of #{klass}"
|
147
|
-
)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
instance_variable_set(:"@#{attribute_name}", instances)
|
151
|
-
end
|
152
|
-
|
153
|
-
attr_reader attribute_name
|
154
|
-
end
|
155
66
|
end
|
156
67
|
|
157
|
-
define_attribute :id, type: String
|
158
|
-
|
159
68
|
attr_reader :client, :error
|
160
69
|
|
70
|
+
define_attribute :id, type: String
|
71
|
+
|
161
72
|
def initialize(client, raw_hash = {})
|
162
73
|
@client = client
|
163
74
|
@raw_hash = raw_hash
|
@@ -205,7 +116,7 @@ module Ocs
|
|
205
116
|
if response.success?
|
206
117
|
@error = nil
|
207
118
|
update_attributes!(response.content)
|
208
|
-
|
119
|
+
self
|
209
120
|
else
|
210
121
|
@error = ApiError.new(api, parameters, response)
|
211
122
|
false
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Ocs
|
2
|
+
module Resources
|
3
|
+
module DynamicDefiners
|
4
|
+
def alias_attribute(alias_name, original_name)
|
5
|
+
alias_method alias_name, original_name
|
6
|
+
alias_method :"#{alias_name}=", :"#{original_name}="
|
7
|
+
end
|
8
|
+
|
9
|
+
def define_action(action_name, required: [], optional: [], api_name: nil)
|
10
|
+
define_method(action_name) do |special_parameters = {}|
|
11
|
+
api = api_name || "#{action_name}#{self.class.name}"
|
12
|
+
parameters = action_parameters(required, optional).merge(special_parameters)
|
13
|
+
send_and_update(api, parameters)
|
14
|
+
end
|
15
|
+
|
16
|
+
define_method(:"#{action_name}!") do |special_parameters = {}|
|
17
|
+
send(action_name) || fail(@error)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def define_attribute(attribute_name, type:)
|
22
|
+
define_method(:"#{attribute_name}=") do |value|
|
23
|
+
unless [*type].any? { |t| value.is_a?(t) }
|
24
|
+
fail AttributeTypeMismatch.new(
|
25
|
+
"#{attribute_name} needs to be a #{[*type].join(" or ")}"
|
26
|
+
)
|
27
|
+
end
|
28
|
+
instance_variable_set(:"@#{attribute_name}", value)
|
29
|
+
end
|
30
|
+
|
31
|
+
attr_reader attribute_name
|
32
|
+
end
|
33
|
+
|
34
|
+
def delegate_attribute(attribute_name, to:, as:)
|
35
|
+
writer_method_name = :"#{to}_#{as}="
|
36
|
+
define_method(writer_method_name) do |value|
|
37
|
+
instance =
|
38
|
+
public_send(to) ||
|
39
|
+
public_send(:"#{to}=", resource_class(to).new(client))
|
40
|
+
instance.public_send(:"#{as}=", value)
|
41
|
+
end
|
42
|
+
delegations[attribute_name] = writer_method_name
|
43
|
+
|
44
|
+
define_method(:"#{to}_#{as}") do
|
45
|
+
instance = public_send(to)
|
46
|
+
instance && instance.public_send(as)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def delegate_attributes(attribute_name, to:)
|
51
|
+
delegations[attribute_name] = :"#{to}="
|
52
|
+
end
|
53
|
+
|
54
|
+
def has_one(attribute_name)
|
55
|
+
define_method(:"#{attribute_name}=") do |value|
|
56
|
+
klass = resource_class(attribute_name)
|
57
|
+
unless value.instance_of?(klass)
|
58
|
+
fail AttributeClassMismatch.new(
|
59
|
+
"#{attribute_name} needs to be an instance of #{klass}"
|
60
|
+
)
|
61
|
+
end
|
62
|
+
instance_variable_set(:"@#{attribute_name}", value)
|
63
|
+
end
|
64
|
+
|
65
|
+
attr_reader attribute_name
|
66
|
+
end
|
67
|
+
|
68
|
+
def has_many(attribute_name)
|
69
|
+
define_method(:"#{attribute_name}=") do |values|
|
70
|
+
unless values.is_a?(Array)
|
71
|
+
fail AttributeTypeMismatch.new("#{attribute_name} needs to be an Array")
|
72
|
+
end
|
73
|
+
|
74
|
+
klass = resource_class(attribute_name.to_s.singularize)
|
75
|
+
instances = values.map do |value|
|
76
|
+
case value
|
77
|
+
when klass
|
78
|
+
value
|
79
|
+
when Hash
|
80
|
+
klass.new(client, value)
|
81
|
+
else
|
82
|
+
fail AttributeClassMismatch.new(
|
83
|
+
"Elements of #{attribute_name} need to be instances of #{klass} or Hash"
|
84
|
+
)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
instance_variable_set(:"@#{attribute_name}", instances)
|
88
|
+
end
|
89
|
+
|
90
|
+
attr_reader attribute_name
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/lib/ocs/version.rb
CHANGED
data/ocs.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency "faraday_middleware"
|
24
24
|
spec.add_dependency "memoist"
|
25
25
|
|
26
|
+
spec.add_development_dependency "erubis"
|
26
27
|
spec.add_development_dependency "bundler", "~> 1.9"
|
27
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
28
29
|
spec.add_development_dependency "pry"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ocs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nownabe
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: erubis
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: bundler
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,9 +138,15 @@ files:
|
|
124
138
|
- Rakefile
|
125
139
|
- bin/console
|
126
140
|
- bin/setup
|
141
|
+
- docs/resources.md
|
127
142
|
- lib/ocs.rb
|
128
143
|
- lib/ocs/api_error.rb
|
129
144
|
- lib/ocs/client.rb
|
145
|
+
- lib/ocs/document/generator.rb
|
146
|
+
- lib/ocs/document/patches/ocs/resources/base.rb
|
147
|
+
- lib/ocs/document/templates/_resource.md.erb
|
148
|
+
- lib/ocs/document/templates/resources.md.erb
|
149
|
+
- lib/ocs/errors.rb
|
130
150
|
- lib/ocs/request.rb
|
131
151
|
- lib/ocs/resources.rb
|
132
152
|
- lib/ocs/resources/account.rb
|
@@ -136,6 +156,7 @@ files:
|
|
136
156
|
- lib/ocs/resources/base.rb
|
137
157
|
- lib/ocs/resources/disk_offering.rb
|
138
158
|
- lib/ocs/resources/domain.rb
|
159
|
+
- lib/ocs/resources/dynamic_definers.rb
|
139
160
|
- lib/ocs/resources/group.rb
|
140
161
|
- lib/ocs/resources/host.rb
|
141
162
|
- lib/ocs/resources/iso.rb
|
@@ -178,3 +199,4 @@ signing_key:
|
|
178
199
|
specification_version: 4
|
179
200
|
summary: Ocs is an objective CloudStack API client.
|
180
201
|
test_files: []
|
202
|
+
has_rdoc:
|