module AWS::Core::OptionGrammar::Descriptors::Structure

@private

Public Class Methods

apply(option, members) click to toggle source
# File lib/aws/core/option_grammar.rb, line 276
def self.apply(option, members)
  options = {}
  options = option.member_options.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 = options[name] || DefaultOption.new(name)
    member_option = member_option.extend_with_config(*descriptors)
    options[name] = member_option
  end
  
  MetaUtils.extend_method(option, :member_options) { options.values }
  by_ruby_name = options.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

Public Instance Methods

hash_format(hash) click to toggle source
# File lib/aws/core/option_grammar.rb, line 329
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) click to toggle source
# File lib/aws/core/option_grammar.rb, line 322
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) click to toggle source
# File lib/aws/core/option_grammar.rb, line 300
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
  
  member_options.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