Class: Saphyr::Config Private
- Inherits:
-
Object
- Object
- Saphyr::Config
- 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
- #field_types ⇒ Object readonly private
- #schemas ⇒ Object readonly private
Instance Method Summary collapse
-
#field_type(name, klass) ⇒ Object
private
This method is part of the DSL and used to register global field type and global schemas.
-
#get_schema(name) ⇒ Saphyr::Schema
private
Get a specific global schema given his name.
-
#initialize ⇒ Config
constructor
private
A new instance of Config.
-
#instanciate_field_type(type, opts = {}) ⇒ Field Type Object
private
Instanciate a registered field type.
-
#schema(name, &block) ⇒ Object
private
This method is part of the DSL used to configure global settings.
Constructor Details
#initialize ⇒ Config
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_types ⇒ Object (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 |
#schemas ⇒ Object (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.
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.
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.
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 |