class Seahorse::Model::Shapes::Shape
Attributes
type[RW]
@return [String]
definition[R]
@return [Hash]
documentation[R]
location[R]
@return [String] Returns one of 'body', 'uri', 'headers', 'status_code'
location_name[R]
@return [String, nil] Typically only set for shapes that are
structure members. Serialized names are typically set on the shape references, not on the shape definition.
name[R]
@return [String]
shape_map[R]
@return [ShapeMap]
type[R]
@return [String] The type name for this shape.
Public Class Methods
new(definition, options = {})
click to toggle source
@param [Hash] definition @option options [ShapeMap] :shape_map (nil)
# File lib/seahorse/model/shapes.rb, line 64 def initialize(definition, options = {}) definition['type'] ||= self.class.type @name = definition['shape'] @definition = definition @type = definition['type'] @location = definition['location'] || 'body' @location_name = definition['locationName'] @shape_map = options[:shape_map] || ShapeMap.new end
Public Instance Methods
inspect()
click to toggle source
@api private @return [String]
# File lib/seahorse/model/shapes.rb, line 109 def inspect "#<#{self.class.name}>" end
metadata(key)
click to toggle source
@param [String] key @return [Object, nil]
# File lib/seahorse/model/shapes.rb, line 103 def metadata(key) @definition[key.to_s] end
with(options)
click to toggle source
@api private
# File lib/seahorse/model/shapes.rb, line 114 def with(options) self.class.new(@definition.merge(options), shape_map: shape_map) end
Private Instance Methods
apply_type(definition)
click to toggle source
# File lib/seahorse/model/shapes.rb, line 180 def apply_type(definition) case definition['type'] when type then definition when nil then { 'type' => type }.merge(definition) else raise ArgumentError, "expected 'type' to be `#{type}'" end end
from_type(definition, options)
click to toggle source
# File lib/seahorse/model/shapes.rb, line 188 def from_type(definition, options) if type = definition['type'] Shapes.shape_class(type).new(definition, options) else raise ArgumentError, 'must specify "type" in the definition' end end
new(definition = {}, options = {})
click to toggle source
Constructs and returns a new shape object. You must specify the shape type using the “type” option or you must construct the shape using the appropriate subclass of `Shape`.
@example Constructing a new shape
shape = Seahorse::Model::Shapes::Shape.new("type" => "structure") shape.class #=> Seahorse::Model::Shapes::Structure shape.definition #=> { "type" => "structure" }
@example Constructing a new shape using the shape class
shape = Seahorse::Model::Shapes::String.new shape.definition #=> { "type" => "string" }
@param [Hash] definition @option options [ShapeMap] :shape_map @return [Shape]
Calls superclass method
# File lib/seahorse/model/shapes.rb, line 170 def new(definition = {}, options = {}) if self == Shape from_type(definition, options) else super(apply_type(definition), options) end end
shape_at(key)
click to toggle source
# File lib/seahorse/model/shapes.rb, line 124 def shape_at(key) if @definition[key] shape_for(@definition[key]) else raise ArgumentError, "expected shape definition at #{key.inspect}" end end
shape_for(reference)
click to toggle source
# File lib/seahorse/model/shapes.rb, line 132 def shape_for(reference) if reference.key?('shape') # shape ref given, e.g. { "shape" => "ShapeName" }, # use the shape map to resolve this reference @shape_map.shape(reference) else Shape.new(reference, shape_map: @shape_map) end end
underscore(string)
click to toggle source
# File lib/seahorse/model/shapes.rb, line 120 def underscore(string) Util.underscore(string) end