Class: JsonApiClient::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/json_api_client/schema.rb

Defined Under Namespace

Modules: Types Classes: Property, TypeFactory

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSchema

Returns a new instance of Schema.



108
109
110
# File 'lib/json_api_client/schema.rb', line 108

def initialize
  @properties = {}
end

Class Method Details

.register(type_hash) ⇒ Object



149
150
151
# File 'lib/json_api_client/schema.rb', line 149

def register(type_hash)
  TypeFactory.register(type_hash)
end

Instance Method Details

#add(name, options) ⇒ void

This method returns an undefined value.

Add a property to the schema

Parameters:

  • name (Symbol)

    the name of the property

  • options (Hash)

    property options

Options Hash (options):

  • :type (Symbol)

    The property type

  • :default (Symbol)

    The default value for the property



119
120
121
# File 'lib/json_api_client/schema.rb', line 119

def add(name, options)
  @properties[name.to_sym] = Property.new(name.to_sym, options[:type], options[:default])
end

#each_property(&block) ⇒ Object Also known as: each



132
133
134
# File 'lib/json_api_client/schema.rb', line 132

def each_property(&block)
  @properties.values.each(&block)
end

#find(property_name) ⇒ Property? Also known as: []

Look up a property by name

Parameters:

  • property_name (String)

    the name of the property

Returns:

  • (Property, nil)

    the property definition for property_name or nil



142
143
144
# File 'lib/json_api_client/schema.rb', line 142

def find(property_name)
  @properties[property_name.to_sym]
end

#sizeFixnum Also known as: length

How many properties are defined

Returns:

  • (Fixnum)

    the number of defined properties



126
127
128
# File 'lib/json_api_client/schema.rb', line 126

def size
  @properties.size
end