Class: Atum::Core::Schema::ApiSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/atum/core/schema/api_schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ ApiSchema

Returns a new instance of ApiSchema.



7
8
9
# File 'lib/atum/core/schema/api_schema.rb', line 7

def initialize(schema)
  @schema = schema
end

Instance Attribute Details

#schemaObject (readonly)

Returns the value of attribute schema.



5
6
7
# File 'lib/atum/core/schema/api_schema.rb', line 5

def schema
  @schema
end

Instance Method Details

#descriptionObject

Description of the API



12
13
14
# File 'lib/atum/core/schema/api_schema.rb', line 12

def description
  @schema['description']
end

#inspectObject Also known as: to_s

Get a simple human-readable representation of this client instance.



35
36
37
# File 'lib/atum/core/schema/api_schema.rb', line 35

def inspect
  "#<Atum::ApiSchema description=\"#{description}\">"
end

#lookup_path(*path) ⇒ Object

Lookup a path in this schema.

Parameters:

  • path (Array<String>)

    Array of keys, one for each to look up in the schema

Returns:

  • (Object)

    Value at the specifed path in this schema.



46
47
48
# File 'lib/atum/core/schema/api_schema.rb', line 46

def lookup_path(*path)
  path.reduce(@schema) { |a, e| a[e] }
end

#resource_schema_for(name) ⇒ Object

Get the schema for a resource.

Parameters:

  • name (String)

    The name of the resource.

Returns:

  • ResourceSchema The resource schema for resource called name

Raises:

  • (SchemaError)

    Raised if an unknown resource name is provided.



21
22
23
24
25
26
27
# File 'lib/atum/core/schema/api_schema.rb', line 21

def resource_schema_for(name)
  unless resource_schema_hash.key?(name)
    raise SchemaError, "Unknown resource '#{name}'."
  end

  resource_schema_hash[name]
end

#resource_schemasArray<ResourceSchema>

Returns The resource schemata in this API.

Returns:



30
31
32
# File 'lib/atum/core/schema/api_schema.rb', line 30

def resource_schemas
  resource_schema_hash.values
end