Module: AWS::Core::OptionGrammar::Descriptors::Map
- Defined in:
- lib/aws/core/option_grammar.rb
Class Method Summary collapse
Instance Method Summary collapse
- #hash_format(value) ⇒ Object
- #key_option ⇒ Object
- #request_params(values, prefix = nil) ⇒ Object
- #validate(value, context = nil) ⇒ Object
- #value_option ⇒ Object
Class Method Details
.apply(option, members = {}) ⇒ Object
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'lib/aws/core/option_grammar.rb', line 342 def self.apply option, members = {} option.extend self key_option = option.key_option if key_descriptors = members[:key] key_option = key_option.extend_with_config(*key_descriptors) MetaUtils.extend_method(option, :key_option) { key_option } end value_option = option.value_option if value_descriptors = members[:value] value_option = value_option.extend_with_config(*value_descriptors) MetaUtils.extend_method(option, :value_option) { value_option } end key_option.param_name = members[:key_param] if members[:key_param] value_option.param_name = members[:value_param] if members[:value_param] end |
Instance Method Details
#hash_format(value) ⇒ Object
393 394 395 396 397 398 399 |
# File 'lib/aws/core/option_grammar.rb', line 393 def hash_format(value) value.inject({}) do |hash, (key, value)| hash[key_option.hash_format(key)] = value_option.hash_format(value) hash end end |
#key_option ⇒ Object
401 402 403 |
# File 'lib/aws/core/option_grammar.rb', line 401 def key_option @_key_option ||= MapOption.new("key") end |
#request_params(values, prefix = nil) ⇒ Object
377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/aws/core/option_grammar.rb', line 377 def request_params values, prefix = nil values.inject([]) do |params, (key,value)| index = params.size / 2 + 1 common_prefix = "#{prefixed_name(prefix)}.#{index}." key_name = common_prefix + key_option.param_name value_name = common_prefix + value_option.param_name params << Http::Request::Param.new(key_name, key) params << Http::Request::Param.new(value_name, value) end end |
#validate(value, context = nil) ⇒ Object
363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/aws/core/option_grammar.rb', line 363 def validate(value, context = nil) raise format_error("hash value", context) unless value.respond_to?(:to_hash) context = context_description(context) value.each do |key, value| key_option.validate(key, "key of #{context}") value_option.validate(value, "value at key #{key} of #{context}") end end |