Module: JsonApiClient::Helpers::Schemable::ClassMethods

Defined in:
lib/json_api_client/helpers/schemable.rb

Instance Method Summary collapse

Instance Method Details

#properties(*names) ⇒ Object

Declare multiple properties with the same optional options

Parameters:

  • names (Array<Symbol>)
  • options (Hash)

    property options



36
37
38
39
40
41
# File 'lib/json_api_client/helpers/schemable.rb', line 36

def properties(*names)
  options = names.last.is_a?(Hash) ? names.pop : {}
  names.each do |name|
    property name, options
  end
end

#property(name, options = {}) ⇒ Object

Declares a new property by name

Parameters:

  • name (Symbol)

    the name of the property

  • options (Hash) (defaults to: {})

    property options

Options Hash (options):

  • :type (Symbol)

    The property type

  • :default (Symbol)

    The default value for the property



26
27
28
# File 'lib/json_api_client/helpers/schemable.rb', line 26

def property(name, options = {})
  schema.add(name, options)
end

#schemaSchema

Returns the schema for this resource class

Returns:

  • (Schema)

    the schema for this resource class



16
17
18
# File 'lib/json_api_client/helpers/schemable.rb', line 16

def schema
  @schema ||= Schema.new
end