aws-sdk 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. data/ca-bundle.crt +2 -348
  2. data/lib/aws.rb +24 -49
  3. data/lib/aws/{common.rb → core.rb} +120 -9
  4. data/lib/aws/{api_config.rb → core/api_config.rb} +19 -20
  5. data/lib/aws/core/api_config_transform.rb +36 -0
  6. data/lib/aws/core/async_handle.rb +91 -0
  7. data/lib/aws/core/authorize_v2.rb +39 -0
  8. data/lib/aws/{authorize_v3.rb → core/authorize_v3.rb} +16 -15
  9. data/lib/aws/{api_config_transform.rb → core/authorize_with_session_token.rb} +9 -12
  10. data/lib/aws/core/autoloader.rb +64 -0
  11. data/lib/aws/core/cacheable.rb +78 -0
  12. data/lib/aws/core/client.rb +471 -0
  13. data/lib/aws/core/client_logging.rb +125 -0
  14. data/lib/aws/core/collections.rb +229 -0
  15. data/lib/aws/core/configuration.rb +358 -0
  16. data/lib/aws/core/configured_client_methods.rb +76 -0
  17. data/lib/aws/core/configured_grammars.rb +63 -0
  18. data/lib/aws/{configured_option_grammars.rb → core/configured_option_grammars.rb} +18 -20
  19. data/lib/aws/{configured_xml_grammars.rb → core/configured_xml_grammars.rb} +19 -21
  20. data/lib/aws/core/default_signer.rb +67 -0
  21. data/lib/aws/core/http/curb_handler.rb +129 -0
  22. data/lib/aws/core/http/handler.rb +77 -0
  23. data/lib/aws/core/http/httparty_handler.rb +113 -0
  24. data/lib/aws/core/http/net_http_handler.rb +124 -0
  25. data/lib/aws/core/http/request.rb +207 -0
  26. data/lib/aws/core/http/response.rb +73 -0
  27. data/lib/aws/{ignore_result_element.rb → core/ignore_result_element.rb} +14 -18
  28. data/lib/aws/core/indifferent_hash.rb +88 -0
  29. data/lib/aws/core/inflection.rb +47 -0
  30. data/lib/aws/core/lazy_error_classes.rb +62 -0
  31. data/lib/aws/{uri_escape.rb → core/meta_utils.rb} +24 -23
  32. data/lib/aws/core/model.rb +57 -0
  33. data/lib/aws/{authorize_with_session_token.rb → core/naming.rb} +9 -8
  34. data/lib/aws/core/option_grammar.rb +562 -0
  35. data/lib/aws/core/policy.rb +914 -0
  36. data/lib/aws/core/resource.rb +380 -0
  37. data/lib/aws/core/resource_cache.rb +40 -0
  38. data/lib/aws/core/response.rb +125 -0
  39. data/lib/aws/core/response_cache.rb +50 -0
  40. data/lib/aws/core/service_interface.rb +60 -0
  41. data/lib/aws/core/uri_escape.rb +46 -0
  42. data/lib/aws/core/xml_grammar.rb +926 -0
  43. data/lib/aws/ec2.rb +47 -16
  44. data/lib/aws/ec2/attachment.rb +0 -2
  45. data/lib/aws/ec2/attachment_collection.rb +1 -6
  46. data/lib/aws/ec2/availability_zone.rb +0 -2
  47. data/lib/aws/ec2/availability_zone_collection.rb +0 -3
  48. data/lib/aws/ec2/client.rb +6 -9
  49. data/lib/aws/ec2/client/xml.rb +3 -6
  50. data/lib/aws/ec2/collection.rb +1 -4
  51. data/lib/aws/ec2/config.rb +18 -0
  52. data/lib/aws/ec2/elastic_ip.rb +0 -2
  53. data/lib/aws/ec2/elastic_ip_collection.rb +0 -4
  54. data/lib/aws/ec2/errors.rb +1 -4
  55. data/lib/aws/ec2/has_permissions.rb +0 -2
  56. data/lib/aws/ec2/image.rb +0 -5
  57. data/lib/aws/ec2/image_collection.rb +0 -6
  58. data/lib/aws/ec2/instance.rb +23 -9
  59. data/lib/aws/ec2/instance_collection.rb +85 -22
  60. data/lib/aws/ec2/key_pair.rb +0 -2
  61. data/lib/aws/ec2/key_pair_collection.rb +1 -4
  62. data/lib/aws/ec2/permission_collection.rb +2 -5
  63. data/lib/aws/ec2/region.rb +0 -2
  64. data/lib/aws/ec2/region_collection.rb +0 -4
  65. data/lib/aws/ec2/request.rb +4 -9
  66. data/lib/aws/ec2/reserved_instances.rb +0 -3
  67. data/lib/aws/ec2/reserved_instances_collection.rb +0 -4
  68. data/lib/aws/ec2/reserved_instances_offering.rb +0 -3
  69. data/lib/aws/ec2/reserved_instances_offering_collection.rb +0 -4
  70. data/lib/aws/ec2/resource.rb +3 -5
  71. data/lib/aws/ec2/resource_tag_collection.rb +1 -6
  72. data/lib/aws/ec2/security_group.rb +204 -72
  73. data/lib/aws/ec2/security_group/egress_ip_permission_collection.rb +53 -0
  74. data/lib/aws/ec2/security_group/ip_permission.rb +92 -10
  75. data/lib/aws/ec2/security_group/ip_permission_collection.rb +14 -15
  76. data/lib/aws/ec2/security_group_collection.rb +11 -8
  77. data/lib/aws/ec2/snapshot.rb +0 -4
  78. data/lib/aws/ec2/snapshot_collection.rb +0 -4
  79. data/lib/aws/ec2/tag.rb +0 -3
  80. data/lib/aws/ec2/tag_collection.rb +1 -8
  81. data/lib/aws/ec2/tagged_item.rb +1 -3
  82. data/lib/aws/ec2/volume.rb +0 -6
  83. data/lib/aws/ec2/volume_collection.rb +0 -4
  84. data/lib/aws/errors.rb +0 -3
  85. data/lib/aws/iam.rb +33 -12
  86. data/lib/aws/iam/access_key.rb +0 -3
  87. data/lib/aws/iam/access_key_collection.rb +0 -3
  88. data/lib/aws/iam/account_alias_collection.rb +0 -2
  89. data/lib/aws/iam/client.rb +6 -8
  90. data/lib/aws/iam/client/xml.rb +4 -8
  91. data/lib/aws/iam/collection.rb +2 -5
  92. data/lib/aws/iam/config.rb +18 -0
  93. data/lib/aws/iam/errors.rb +2 -4
  94. data/lib/aws/iam/group.rb +0 -5
  95. data/lib/aws/iam/group_collection.rb +0 -3
  96. data/lib/aws/iam/group_policy_collection.rb +0 -2
  97. data/lib/aws/iam/group_user_collection.rb +1 -4
  98. data/lib/aws/iam/login_profile.rb +0 -2
  99. data/lib/aws/iam/mfa_device.rb +1 -3
  100. data/lib/aws/iam/mfa_device_collection.rb +0 -3
  101. data/lib/aws/iam/policy.rb +2 -4
  102. data/lib/aws/iam/policy_collection.rb +0 -3
  103. data/lib/aws/iam/request.rb +3 -7
  104. data/lib/aws/iam/resource.rb +1 -4
  105. data/lib/aws/iam/server_certificate.rb +0 -2
  106. data/lib/aws/iam/server_certificate_collection.rb +0 -3
  107. data/lib/aws/iam/signing_certificate.rb +0 -2
  108. data/lib/aws/iam/signing_certificate_collection.rb +0 -3
  109. data/lib/aws/iam/user.rb +0 -7
  110. data/lib/aws/iam/user_collection.rb +0 -3
  111. data/lib/aws/iam/user_group_collection.rb +0 -3
  112. data/lib/aws/iam/user_policy.rb +0 -2
  113. data/lib/aws/iam/user_policy_collection.rb +0 -3
  114. data/lib/aws/rails.rb +5 -4
  115. data/lib/aws/record.rb +4 -1
  116. data/lib/aws/record/base.rb +3 -2
  117. data/lib/aws/record/errors.rb +1 -3
  118. data/lib/aws/s3.rb +31 -6
  119. data/lib/aws/s3/access_control_list.rb +0 -2
  120. data/lib/aws/s3/acl_object.rb +10 -12
  121. data/lib/aws/s3/bucket.rb +1 -9
  122. data/lib/aws/s3/bucket_collection.rb +2 -5
  123. data/lib/aws/s3/bucket_version_collection.rb +1 -5
  124. data/lib/aws/s3/client.rb +34 -37
  125. data/lib/aws/s3/client/xml.rb +11 -14
  126. data/lib/aws/{resource_cache.rb → s3/config.rb} +6 -20
  127. data/lib/aws/s3/errors.rb +6 -7
  128. data/lib/aws/s3/multipart_upload.rb +1 -4
  129. data/lib/aws/s3/multipart_upload_collection.rb +1 -6
  130. data/lib/aws/s3/object_collection.rb +1 -5
  131. data/lib/aws/s3/object_metadata.rb +1 -3
  132. data/lib/aws/s3/object_upload_collection.rb +1 -7
  133. data/lib/aws/s3/object_version.rb +1 -4
  134. data/lib/aws/s3/object_version_collection.rb +1 -4
  135. data/lib/aws/s3/policy.rb +3 -5
  136. data/lib/aws/s3/prefix_and_delimiter_collection.rb +0 -2
  137. data/lib/aws/s3/prefixed_collection.rb +0 -2
  138. data/lib/aws/s3/presigned_post.rb +1 -3
  139. data/lib/aws/s3/request.rb +2 -5
  140. data/lib/aws/s3/s3_object.rb +1 -8
  141. data/lib/aws/s3/tree.rb +8 -6
  142. data/lib/aws/s3/tree/branch_node.rb +0 -3
  143. data/lib/aws/s3/tree/child_collection.rb +1 -5
  144. data/lib/aws/s3/tree/leaf_node.rb +0 -5
  145. data/lib/aws/s3/tree/parent.rb +1 -4
  146. data/lib/aws/s3/uploaded_part.rb +1 -3
  147. data/lib/aws/s3/uploaded_part_collection.rb +1 -5
  148. data/lib/aws/simple_db.rb +21 -6
  149. data/lib/aws/simple_db/attribute.rb +1 -6
  150. data/lib/aws/simple_db/attribute_collection.rb +1 -7
  151. data/lib/aws/simple_db/client.rb +7 -9
  152. data/lib/aws/simple_db/client/options.rb +2 -4
  153. data/lib/aws/simple_db/client/xml.rb +5 -10
  154. data/lib/aws/{naming.rb → simple_db/config.rb} +3 -14
  155. data/lib/aws/simple_db/delete_attributes.rb +0 -2
  156. data/lib/aws/simple_db/domain.rb +1 -6
  157. data/lib/aws/simple_db/domain_collection.rb +1 -4
  158. data/lib/aws/simple_db/domain_metadata.rb +1 -3
  159. data/lib/aws/simple_db/errors.rb +1 -4
  160. data/lib/aws/simple_db/item.rb +1 -7
  161. data/lib/aws/simple_db/item_collection.rb +22 -23
  162. data/lib/aws/simple_db/put_attributes.rb +0 -2
  163. data/lib/aws/simple_db/request.rb +3 -7
  164. data/lib/aws/simple_email_service.rb +11 -6
  165. data/lib/aws/simple_email_service/client.rb +7 -9
  166. data/lib/aws/simple_email_service/client/options.rb +3 -6
  167. data/lib/aws/simple_email_service/client/xml.rb +4 -8
  168. data/lib/aws/simple_email_service/config.rb +19 -0
  169. data/lib/aws/simple_email_service/email_address_collection.rb +1 -3
  170. data/lib/aws/simple_email_service/errors.rb +1 -4
  171. data/lib/aws/simple_email_service/quotas.rb +1 -3
  172. data/lib/aws/simple_email_service/request.rb +3 -7
  173. data/lib/aws/sns.rb +15 -8
  174. data/lib/aws/sns/client.rb +7 -8
  175. data/lib/aws/sns/client/options.rb +3 -6
  176. data/lib/aws/sns/client/xml.rb +4 -8
  177. data/lib/aws/sns/config.rb +18 -0
  178. data/lib/aws/sns/errors.rb +1 -4
  179. data/lib/aws/sns/policy.rb +3 -5
  180. data/lib/aws/sns/request.rb +4 -9
  181. data/lib/aws/sns/subscription.rb +1 -5
  182. data/lib/aws/sns/subscription_collection.rb +1 -5
  183. data/lib/aws/sns/topic.rb +1 -6
  184. data/lib/aws/sns/topic_collection.rb +1 -4
  185. data/lib/aws/sns/topic_subscription_collection.rb +1 -4
  186. data/lib/aws/sqs.rb +14 -5
  187. data/lib/aws/sqs/client.rb +6 -9
  188. data/lib/aws/sqs/client/xml.rb +4 -7
  189. data/lib/aws/sqs/config.rb +18 -0
  190. data/lib/aws/sqs/errors.rb +1 -4
  191. data/lib/aws/sqs/policy.rb +3 -5
  192. data/lib/aws/sqs/queue.rb +2 -7
  193. data/lib/aws/sqs/queue_collection.rb +4 -5
  194. data/lib/aws/sqs/received_message.rb +1 -3
  195. data/lib/aws/sqs/received_sns_message.rb +2 -2
  196. data/lib/aws/sqs/request.rb +4 -7
  197. data/lib/aws/sts.rb +12 -6
  198. data/lib/aws/sts/client.rb +6 -8
  199. data/lib/aws/sts/client/xml.rb +4 -8
  200. data/lib/aws/sts/config.rb +18 -0
  201. data/lib/aws/sts/errors.rb +1 -4
  202. data/lib/aws/sts/federated_session.rb +0 -2
  203. data/lib/aws/sts/policy.rb +3 -5
  204. data/lib/aws/sts/request.rb +3 -7
  205. metadata +60 -50
  206. data/lib/aws/async_handle.rb +0 -90
  207. data/lib/aws/authorize_v2.rb +0 -37
  208. data/lib/aws/base_client.rb +0 -488
  209. data/lib/aws/cacheable.rb +0 -79
  210. data/lib/aws/client_logging.rb +0 -122
  211. data/lib/aws/collections.rb +0 -230
  212. data/lib/aws/configuration.rb +0 -357
  213. data/lib/aws/configured_client_methods.rb +0 -81
  214. data/lib/aws/configured_grammars.rb +0 -65
  215. data/lib/aws/default_signer.rb +0 -65
  216. data/lib/aws/http/curb_handler.rb +0 -127
  217. data/lib/aws/http/handler.rb +0 -77
  218. data/lib/aws/http/httparty_handler.rb +0 -103
  219. data/lib/aws/http/request.rb +0 -165
  220. data/lib/aws/http/request_param.rb +0 -64
  221. data/lib/aws/http/response.rb +0 -72
  222. data/lib/aws/indifferent_hash.rb +0 -86
  223. data/lib/aws/inflection.rb +0 -46
  224. data/lib/aws/lazy_error_classes.rb +0 -64
  225. data/lib/aws/meta_utils.rb +0 -43
  226. data/lib/aws/model.rb +0 -57
  227. data/lib/aws/option_grammar.rb +0 -565
  228. data/lib/aws/policy.rb +0 -914
  229. data/lib/aws/resource.rb +0 -381
  230. data/lib/aws/response.rb +0 -125
  231. data/lib/aws/response_cache.rb +0 -50
  232. data/lib/aws/service_interface.rb +0 -60
  233. data/lib/aws/xml_grammar.rb +0 -925
@@ -1,43 +0,0 @@
1
- # Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License"). You
4
- # may not use this file except in compliance with the License. A copy of
5
- # the License is located at
6
- #
7
- # http://aws.amazon.com/apache2.0/
8
- #
9
- # or in the "license" file accompanying this file. This file is
10
- # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
- # ANY KIND, either express or implied. See the License for the specific
12
- # language governing permissions and limitations under the License.
13
-
14
- module AWS
15
-
16
- # @private
17
- module MetaUtils
18
-
19
- def extend_method(object, name, &block)
20
- object.extend(
21
- Module.new do
22
- define_method(name, &block)
23
- end
24
- )
25
- end
26
- module_function :extend_method
27
-
28
- def class_extend_method(klass, name, &block)
29
- klass.send(:include,
30
- Module.new do
31
- define_method(name, &block)
32
- end
33
- )
34
- end
35
- module_function :class_extend_method
36
-
37
- def extend(object, &block)
38
- object.extend(Module.new(&block))
39
- end
40
- module_function :extend
41
-
42
- end
43
- end
@@ -1,57 +0,0 @@
1
- # Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License"). You
4
- # may not use this file except in compliance with the License. A copy of
5
- # the License is located at
6
- #
7
- # http://aws.amazon.com/apache2.0/
8
- #
9
- # or in the "license" file accompanying this file. This file is
10
- # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
- # ANY KIND, either express or implied. See the License for the specific
12
- # language governing permissions and limitations under the License.
13
-
14
- require 'aws/inflection'
15
-
16
- module AWS
17
-
18
- # @private
19
- module Model
20
-
21
- # @private
22
- def initialize(*args)
23
- options = args.last.kind_of?(Hash) ? args.last : {}
24
- @config = case
25
- when options[:config] then options[:config]
26
- when args.first.respond_to?(:config) then args.first.config
27
- else AWS.config
28
- end
29
- end
30
-
31
- # @return [Configuration] Returns the configuration for this object.
32
- attr_reader :config
33
-
34
- # Each class including this module has its own client class.
35
- # Generally it is the service namespace suffixed by client:
36
- #
37
- # * s3_client
38
- # * simple_db_client
39
- #
40
- # @return Retruns the proper client class for the given model.
41
- def client
42
- @config.send("#{config_prefix}_client")
43
- end
44
-
45
- # @return [String] The short name of the service as used in coniguration.
46
- # (e.g. SimpleDB::Client.config_prefix #=> 'simple_db')
47
- def config_prefix
48
- Inflection.ruby_name(self.class.to_s.split(/::/)[1])
49
- end
50
-
51
- # @return [String] A sensible default inspect string.
52
- def inspect
53
- "<#{self.class}>"
54
- end
55
-
56
- end
57
- end
@@ -1,565 +0,0 @@
1
- # Copyright 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License"). You
4
- # may not use this file except in compliance with the License. A copy of
5
- # the License is located at
6
- #
7
- # http://aws.amazon.com/apache2.0/
8
- #
9
- # or in the "license" file accompanying this file. This file is
10
- # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
- # ANY KIND, either express or implied. See the License for the specific
12
- # language governing permissions and limitations under the License.
13
-
14
- require 'aws/inflection'
15
- require 'aws/meta_utils'
16
- require 'aws/http/request_param'
17
- require 'base64'
18
- require 'set'
19
-
20
- module AWS
21
-
22
- # @private
23
- class OptionGrammar
24
-
25
- # @private
26
- class DefaultOption; end
27
-
28
- # @private
29
- class FormatError < ArgumentError
30
- attr_accessor :expectation
31
- attr_accessor :context_description
32
-
33
- def initialize(expectation, context)
34
- @expectation = expectation
35
- @context_description = context
36
- end
37
-
38
- def to_s
39
- "expected #{expectation} for #{context_description}"
40
- end
41
- end
42
-
43
- # @private
44
- module Descriptors
45
-
46
- # @private
47
- module NoArgs
48
- def apply(option)
49
- option.extend self
50
- end
51
- end
52
-
53
- module Timestamp
54
-
55
- extend NoArgs
56
-
57
- def validate(value, context = nil)
58
- true
59
- # raise format_error("timestamp value", context) unless
60
- # case value
61
- # when String
62
- # value =~ /^\d+$/ or value =~ /^\d{4}-\d{2}-d{2}T\d{2}:\d{2}:\d{2}Z$/
63
- # when String then value =~ /^2009-12-04T20:56:05.000Z\d+$/
64
- # when Integer then true
65
- # when DateTime then true
66
- # when Timestamp then true
67
- # when Date then true
68
- # else false
69
- # end
70
- # end
71
- # value.respond_to? :to_str
72
- end
73
-
74
- def encode_value(value)
75
- value.to_s
76
- # value.to_s
77
- # case value
78
- # when Integer
79
- # when
80
- # case value
81
- # when nil, '' then nil
82
- # when DateTime then raw
83
- # when Integer then DateTime.parse(Time.at(raw).to_s) # timestamp
84
- # else DateTime.parse(raw.to_s) # work with Time, Date and String objects
85
- # end
86
- end
87
- end
88
-
89
- # @private
90
- module String
91
-
92
- extend NoArgs
93
-
94
- def validate(value, context = nil)
95
- raise format_error("string value", context) unless
96
- value.respond_to? :to_str
97
- end
98
-
99
- def encode_value(value)
100
- value.to_s
101
- end
102
-
103
- end
104
-
105
- # @private
106
- module Blob
107
-
108
- extend NoArgs
109
-
110
- def validate(value, context = nil)
111
- raise format_error("string value", context) unless
112
- value.respond_to? :to_str
113
- end
114
-
115
- def encode_value(value)
116
- Base64.encode64(value.to_s)
117
- end
118
-
119
- end
120
-
121
- # @private
122
- module Integer
123
-
124
- extend NoArgs
125
-
126
- def validate(value, context = nil)
127
- raise format_error("integer value", context) unless
128
- value.respond_to? :to_int
129
- end
130
-
131
- def encode_value(value)
132
- value.to_s
133
- end
134
-
135
- end
136
-
137
- # @private
138
- module Boolean
139
-
140
- extend NoArgs
141
-
142
- def validate(value, context = nil)
143
- raise format_error("boolean value", context) unless
144
- value == true || value == false
145
- end
146
-
147
- def encode_value(value)
148
- value.to_s
149
- end
150
-
151
- end
152
-
153
- # @private
154
- module Required
155
- extend NoArgs
156
- def required?; true; end
157
- end
158
-
159
- # @private
160
- module Rename
161
- def self.apply(option, new_name)
162
- new_name = Inflection.ruby_name(new_name)
163
- MetaUtils.extend_method(option, :ruby_name) { new_name }
164
- end
165
- end
166
-
167
- # @private
168
- module Pattern
169
-
170
- # def validate value, context = nil
171
- # unless value =~ regex
172
- # raise format_error("value to match #{regex}", context)
173
- # end
174
- # end
175
- #
176
- # def self.apply option, regex
177
- # option.extend(self)
178
- # MetaUtils.extend_method(option, :regex) { regex }
179
- # end
180
-
181
- def self.apply *args
182
- end
183
-
184
- end
185
-
186
- # @private
187
- module ListMethods
188
-
189
- module ClassMethods
190
-
191
- def apply(option, member_descriptors)
192
- super(option)
193
- member_option = option.member_option if option.respond_to?(:member_option)
194
- member_option ||= ListMember.new
195
- member_option = member_option.extend_with_config(*member_descriptors)
196
- MetaUtils.extend_method(option, :member_option) { member_option }
197
- end
198
-
199
- end
200
-
201
- module InstanceMethods
202
-
203
- def validate(value, context = nil)
204
- raise format_error("enumerable value", context) unless
205
- value.respond_to? :each
206
- i = 0
207
- value.each do |member|
208
- i += 1
209
- member_option.validate(member,
210
- "member #{i} of #{context_description(context)}")
211
- end
212
- end
213
-
214
- def request_params(value, prefix = nil)
215
- params = []
216
- value.each do |v|
217
- name = prefixed_name(prefix) + join + (params.size + 1).to_s
218
- params << member_option.request_params(v, name)
219
- end
220
- return [Http::Request::Param.new(prefixed_name(prefix), "")] if params.empty?
221
- params
222
- end
223
-
224
- def join
225
- '.'
226
- end
227
-
228
- end
229
-
230
- end
231
-
232
- module List
233
-
234
- extend NoArgs
235
- extend ListMethods::ClassMethods
236
- include ListMethods::InstanceMethods
237
-
238
- end
239
-
240
- module MemberedList
241
-
242
- extend NoArgs
243
- extend ListMethods::ClassMethods
244
- include ListMethods::InstanceMethods
245
-
246
- def join
247
- '.member.'
248
- end
249
-
250
- end
251
-
252
- class ListMember < DefaultOption
253
-
254
- def initialize options = {}
255
- super("##list-member##")
256
- @prefix = options[:prefix] || ''
257
- end
258
-
259
- def prefixed_name(prefix)
260
- "#{prefix}#{@prefix}"
261
- end
262
-
263
- end
264
-
265
- # @private
266
- module Structure
267
-
268
- extend NoArgs
269
-
270
- def self.apply(option, members)
271
- options = {}
272
- options = option.member_options.inject({}) do |memo, member_option|
273
- memo[member_option.name] = member_option
274
- memo
275
- end if option.respond_to?(:member_options)
276
-
277
- super(option)
278
-
279
- members.each do |(name, descriptors)|
280
- member_option = options[name] || DefaultOption.new(name)
281
- member_option = member_option.extend_with_config(*descriptors)
282
- options[name] = member_option
283
- end
284
-
285
- MetaUtils.extend_method(option, :member_options) { options.values }
286
- by_ruby_name = options.values.inject({}) do |memo, member_option|
287
- memo[member_option.ruby_name] = member_option
288
- memo
289
- end
290
- MetaUtils.extend_method(option, :member_option) { |n| by_ruby_name[n] }
291
- end
292
-
293
- def validate(value, context = nil)
294
- raise format_error("hash value", context) unless
295
- value.respond_to?(:to_hash)
296
-
297
- context = context_description(context)
298
-
299
- value.each do |name, v|
300
- name = name.to_s
301
- raise ArgumentError.new("unexpected key #{name} for #{context}") unless
302
- member_option(name)
303
- member_option(name).validate(v, "key #{name} of #{context}")
304
- end
305
-
306
- member_options.each do |option|
307
- raise ArgumentError.new("missing required key #{option.ruby_name} for #{context}") if
308
- option.required? and
309
- !value.has_key?(option.ruby_name) and
310
- !value.has_key?(option.ruby_name.to_sym)
311
- end
312
- end
313
-
314
- def request_params(values, prefix = nil)
315
- values.map do |name, value|
316
- name = name.to_s
317
- member_option(name).request_params(value, prefixed_name(prefix))
318
- end.flatten
319
- end
320
-
321
- end
322
-
323
- # @private
324
- module Boolean
325
- extend NoArgs
326
- end
327
-
328
- end
329
-
330
- class DefaultOption
331
-
332
- attr_reader :name
333
-
334
- def initialize(name)
335
- @name = name
336
- end
337
-
338
- def ruby_name
339
- Inflection.ruby_name(name)
340
- end
341
-
342
- def request_params(value, prefix = nil)
343
- [Http::Request::Param.new(prefixed_name(prefix), encode_value(value))]
344
- end
345
-
346
- def prefixed_name(prefix)
347
- return "#{prefix}.#{name}" if prefix
348
- name
349
- end
350
-
351
- def encode_value(value)
352
- value
353
- end
354
-
355
- def required?
356
- false
357
- end
358
-
359
- def format_error(expected, context = nil)
360
- context = context_description(context)
361
- FormatError.new(expected, context)
362
- end
363
-
364
- def context_description(context)
365
- context or "option #{ruby_name}"
366
- end
367
-
368
- def extend_with_config(*descriptors)
369
- option = clone
370
- descriptors.each do |desc|
371
- if desc.kind_of?(Hash)
372
- (name, arg) = desc.to_a.first
373
- else
374
- name = desc
375
- arg = nil
376
- end
377
- class_name = Inflection.class_name(name.to_s)
378
- mod = Descriptors::const_get(class_name)
379
- if arg
380
- mod.apply(option, arg)
381
- else
382
- mod.apply(option)
383
- end
384
- end
385
- option
386
- end
387
-
388
- include Descriptors::String
389
-
390
- end
391
-
392
- # @private
393
- module ModuleMethods
394
-
395
- include Inflection
396
-
397
- def customize(config = [])
398
- m = Class.new(self)
399
- supported_options = m.supported_options.inject({}) do |memo, opt|
400
- memo[opt.name] = opt
401
- memo
402
- end
403
- config.each do |option_config|
404
- if config.kind_of?(Hash)
405
- (name, value_desc) = option_config
406
- else
407
- (name, value_desc) = parse_option(option_config)
408
- end
409
- option = supported_options[name] || DefaultOption.new(name)
410
- option = option.extend_with_config(*value_desc)
411
- supported_options[option.name] = option
412
- end
413
-
414
- supported_ary = supported_options.values
415
- MetaUtils.extend_method(m, :supported_options) { supported_ary }
416
- supported_ruby_names = supported_ary.inject({}) do |memo, opt|
417
- memo[opt.ruby_name] = opt
418
- memo
419
- end
420
- MetaUtils.extend_method(m, :option) { |n| supported_ruby_names[n] }
421
- supported_ary.each do |opt|
422
- MetaUtils.extend_method(m, "validate_#{opt.ruby_name}") do |value|
423
- opt.validate(value)
424
- end
425
- end
426
-
427
- m
428
- end
429
-
430
- def option(name)
431
- nil
432
- end
433
-
434
- def supported_options
435
- []
436
- end
437
-
438
- def validate(options)
439
- options.each do |name, value|
440
- name = name.to_s
441
- raise ArgumentError.new("unexpected option #{name}") unless
442
- option(name)
443
- option(name).validate(value)
444
- end
445
- supported_options.each do |option|
446
- raise ArgumentError.new("missing required option #{option.ruby_name}") unless
447
- !option.required? ||
448
- options.has_key?(option.ruby_name) || options.has_key?(option.ruby_name.to_sym)
449
- end
450
- end
451
-
452
- def request_params(options)
453
- validate(options)
454
- options.map do |(name, value)|
455
- name = name.to_s
456
- option(name).request_params(value)
457
- end.flatten
458
- end
459
-
460
- def included(m)
461
- m.extend(self::ModuleMethods)
462
- end
463
-
464
- protected
465
- def parse_option(option)
466
- value_desc = nil
467
- if option.kind_of? Hash
468
- raise ArgumentError.new("passed empty hash where an option was expected") if
469
- option.empty?
470
-
471
- raise ArgumentError.new("too many entries in option description") if
472
- option.size > 1
473
-
474
- (name, value_desc) = option.to_a.first
475
- name = name.to_s
476
-
477
- raise ArgumentError.new("expected an array for "+
478
- "value description of option #{name},"+
479
- "got #{value_desc.inspect}") unless
480
- value_desc.nil? or value_desc.kind_of?(Array)
481
- else
482
- name = option
483
- end
484
-
485
- value_desc ||= []
486
-
487
- [name, value_desc]
488
- end
489
-
490
- protected
491
- def apply_required_descriptor(m, name)
492
- name = ruby_name(name)
493
- MetaUtils.extend_method(m, :validate) do |opts|
494
- raise ArgumentError.new("missing required option #{name}") unless
495
- opts.key? name or opts.key? name.to_sym
496
- end
497
- end
498
-
499
- protected
500
- def apply_integer_descriptor(m, name)
501
- MetaUtils.extend_method(m, "validate_#{ruby_name(name)}") do |value|
502
- raise ArgumentError.new("expected integer value for option #{ruby_name(name)}") unless
503
- value.respond_to? :to_int
504
- end
505
- end
506
-
507
- protected
508
- def apply_string_descriptor(m, name)
509
- MetaUtils.extend_method(m, "validate_#{ruby_name(name)}") do |value|
510
- raise ArgumentError.new("expected string value for option #{ruby_name(name)}") unless
511
- value.respond_to? :to_str
512
- end
513
- end
514
-
515
- protected
516
- def apply_list_descriptor(m, name, arg)
517
- MetaUtils.extend_method(m, "validate_#{ruby_name(name)}") do |value|
518
- raise ArgumentError.new("expected value for option #{ruby_name(name)} "+
519
- "to respond to #each") unless
520
- value.respond_to? :each
521
- end
522
- MetaUtils.extend_method(m, "params_for_#{ruby_name(name)}") do |value|
523
- i = 0
524
- values = []
525
- value.each do |member|
526
- i += 1
527
- values << Http::Request::Param.new(name+"."+i.to_s, member.to_s)
528
- end
529
- if i > 0
530
- values
531
- else
532
- Http::Request::Param.new(name, "")
533
- end
534
- end
535
- end
536
-
537
- protected
538
- def apply_rename_descriptor(m, name, new_name)
539
- name = ruby_name(name)
540
- MetaUtils.extend_method(m, :validate) do |opts|
541
- raise ArgumentError.new("unexpected option foo") if
542
- opts.key?(name) or opts.key?(name.to_sym)
543
-
544
- opts = opts.dup
545
- opts[name] = opts[new_name] if opts.key?(new_name)
546
- opts[name.to_sym] = opts[new_name.to_sym] if opts.key?(new_name.to_sym)
547
- opts.delete(new_name)
548
- opts.delete(new_name.to_sym)
549
- super(opts)
550
- end
551
-
552
- # couldn't find a better way to alias a class method
553
- method = m.method("params_for_#{name}")
554
- MetaUtils.extend_method(m, "params_for_#{new_name}") do |value|
555
- method.call(value)
556
- end
557
- end
558
-
559
- end
560
-
561
- extend ModuleMethods
562
-
563
- end
564
-
565
- end