Module: AWS::Core::OptionGrammar::Descriptors::Structure
- Extended by:
- NoArgs
- Defined in:
- lib/aws/core/option_grammar.rb
Class Method Summary collapse
Instance Method Summary collapse
- #hash_format(hash) ⇒ Object
- #request_params(values, prefix = nil) ⇒ Object
- #validate(value, context = nil) ⇒ Object
Methods included from NoArgs
Class Method Details
.apply(option, members) ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/aws/core/option_grammar.rb', line 277 def self.apply(option, members) = {} = option..inject({}) do |memo, member_option| memo[member_option.name] = member_option memo end if option.respond_to?(:member_options) super(option) members.each do |(name, descriptors)| member_option = [name] || DefaultOption.new(name) member_option = member_option.extend_with_config(*descriptors) [name] = member_option end MetaUtils.extend_method(option, :member_options) { .values } by_ruby_name = .values.inject({}) do |memo, member_option| memo[member_option.ruby_name] = member_option memo[member_option.name] = member_option memo end MetaUtils.extend_method(option, :member_option) { |n| by_ruby_name[n] } end |
Instance Method Details
#hash_format(hash) ⇒ Object
330 331 332 333 334 335 336 |
# File 'lib/aws/core/option_grammar.rb', line 330 def hash_format(hash) hash.inject({}) do |hash, (name, value)| option = member_option(name.to_s) hash[option.name] = option.hash_format(value) hash end end |
#request_params(values, prefix = nil) ⇒ Object
323 324 325 326 327 328 |
# File 'lib/aws/core/option_grammar.rb', line 323 def request_params(values, prefix = nil) values.map do |name, value| name = name.to_s member_option(name).request_params(value, prefixed_name(prefix)) end.flatten end |
#validate(value, context = nil) ⇒ Object
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/aws/core/option_grammar.rb', line 301 def validate(value, context = nil) raise format_error("hash value", context) unless value.respond_to?(:to_hash) context = context_description(context) value.each do |name, v| name = name.to_s raise ArgumentError.new("unexpected key #{name} for #{context}") unless member_option(name) member_option(name).validate(v, "key #{name} of #{context}") end .each do |option| raise ArgumentError.new("missing required key #{option.ruby_name} for #{context}") if option.required? and !value.has_key?(option.ruby_name) and !value.has_key?(option.ruby_name.to_sym) and !value.has_key?(option.name) end end |