Class: Saphyr::Config Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This class is used to encapsulate global settings (field types, schema).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Config.



81
82
83
84
85
86
87
# File 'lib/saphyr.rb', line 81

def initialize()
  @schemas = {}
  @field_types = {
    array: Saphyr::Fields::ArrayField,
    schema: Saphyr::Fields::SchemaField,
  }
end

Instance Attribute Details

#field_typesObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



79
80
81
# File 'lib/saphyr.rb', line 79

def field_types
  @field_types
end

#schemasObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



79
80
81
# File 'lib/saphyr.rb', line 79

def schemas
  @schemas
end

Instance Method Details

#field_type(name, klass) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method is part of the DSL and used to register global field type and global schemas.

Parameters:

  • name (String, Symbol)

    The field type name

  • klass (Class)

    The class used to handle the field type



96
97
98
99
100
# File 'lib/saphyr.rb', line 96

def field_type(name, klass)
  raise Saphyr::Error.new "Cannot overwrite ':array' field" if name == :array
  raise Saphyr::Error.new "Cannot overwrite ':schema' field" if name == :schema
  @field_types[name] = klass
end

#get_schema(name) ⇒ Saphyr::Schema

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get a specific global schema given his name.

Parameters:

  • name (Symbol)

    The schema name

Returns:

Raises:



133
134
135
136
# File 'lib/saphyr.rb', line 133

def get_schema(name)
  raise Saphyr::Error.new "Unknown schema : #{name}" unless @schemas.key? name
  @schemas[name]
end

#instanciate_field_type(type, opts = {}) ⇒ Field Type Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Instanciate a registered field type.

Parameters:

  • type (Symbol)

    The type name use to register the field type

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

    A hash of options to pass to the field type instance.

Returns:

  • (Field Type Object)

    An instance of the field type.



123
124
125
126
127
# File 'lib/saphyr.rb', line 123

def instanciate_field_type(type, opts={})
  klass = @field_types[type]
  raise Saphyr::Error.new "Unknown field : #{type}" if klass.nil?
  Object.const_get(klass.name).new opts
end

#schema(name, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method is part of the DSL used to configure global settings. Register a new global schema.

Parameters:

name

The name of the schema can be ‘Symbol` or `String`.

&block

The block evaluated by the DSL.



111
112
113
114
115
# File 'lib/saphyr.rb', line 111

def schema(name, &block)
  schema = Saphyr::Schema.new
  schema.instance_eval &block
  @schemas[name] = schema
end