class Seahorse::Model::ShapeMap

@api private

Attributes

definitions[R]

@return [Hash]

Public Class Methods

new(shape_defs = {}) click to toggle source

@param [Hash<String,Hash>] shape_defs ({}) A hash of shape definitions.

Hash keys should be shape names.  Hash values should be shape
definitions.
# File lib/seahorse/model/shape_map.rb, line 9
def initialize(shape_defs = {})
  @definitions = shape_defs
  @shapes = {}
end

Public Instance Methods

shape(shape_ref) click to toggle source

@param [Hash] shape_ref @option shape_ref [required, String] 'shape' @return [Shapes::Shape] @raise [ArgumentError] Raised when the given shape ref can not be

resolved.
# File lib/seahorse/model/shape_map.rb, line 22
def shape(shape_ref)
  @shapes[shape_ref] ||= build_shape(shape_ref)
end
shape_names() click to toggle source

@return [Array<String>]

# File lib/seahorse/model/shape_map.rb, line 27
def shape_names
  @definitions.keys
end

Private Instance Methods

build_shape(shape_ref) click to toggle source
# File lib/seahorse/model/shape_map.rb, line 33
def build_shape(shape_ref)
  Shapes::Shape.new(resolve(shape_ref), shape_map: self)
end
resolve(shape_ref) click to toggle source
# File lib/seahorse/model/shape_map.rb, line 37
def resolve(shape_ref)
  if definition = @definitions[shape_ref['shape']]
    definition.merge(shape_ref)
  else
    raise ArgumentError, "shape not found for #{shape_ref.inspect}"
  end
end