Module: Shale

Defined in:
lib/shale.rb,
lib/shale/type.rb,
lib/shale/error.rb,
lib/shale/utils.rb,
lib/shale/mapper.rb,
lib/shale/schema.rb,
lib/shale/version.rb,
lib/shale/attribute.rb,
lib/shale/type/date.rb,
lib/shale/type/time.rb,
lib/shale/adapter/ox.rb,
lib/shale/type/float.rb,
lib/shale/type/value.rb,
lib/shale/adapter/csv.rb,
lib/shale/mapping/xml.rb,
lib/shale/type/string.rb,
lib/shale/adapter/json.rb,
lib/shale/mapping/dict.rb,
lib/shale/type/boolean.rb,
lib/shale/type/complex.rb,
lib/shale/type/integer.rb,
lib/shale/adapter/rexml.rb,
lib/shale/adapter/tomlib.rb,
lib/shale/adapter/ox/node.rb,
lib/shale/adapter/toml_rb.rb,
lib/shale/adapter/nokogiri.rb,
lib/shale/mapping/xml_base.rb,
lib/shale/mapping/delegates.rb,
lib/shale/mapping/dict_base.rb,
lib/shale/mapping/group/xml.rb,
lib/shale/mapping/validator.rb,
lib/shale/mapping/xml_group.rb,
lib/shale/adapter/rexml/node.rb,
lib/shale/mapping/dict_group.rb,
lib/shale/mapping/group/dict.rb,
lib/shale/adapter/ox/document.rb,
lib/shale/schema/xml_compiler.rb,
lib/shale/schema/compiler/date.rb,
lib/shale/schema/compiler/time.rb,
lib/shale/schema/json_compiler.rb,
lib/shale/schema/xml_generator.rb,
lib/shale/adapter/nokogiri/node.rb,
lib/shale/schema/compiler/float.rb,
lib/shale/schema/compiler/value.rb,
lib/shale/schema/json_generator.rb,
lib/shale/adapter/rexml/document.rb,
lib/shale/mapping/descriptor/xml.rb,
lib/shale/schema/compiler/string.rb,
lib/shale/mapping/descriptor/dict.rb,
lib/shale/schema/compiler/boolean.rb,
lib/shale/schema/compiler/complex.rb,
lib/shale/schema/compiler/integer.rb,
lib/shale/schema/compiler/property.rb,
lib/shale/adapter/nokogiri/document.rb,
lib/shale/schema/json_generator/ref.rb,
lib/shale/mapping/group/xml_grouping.rb,
lib/shale/schema/json_generator/base.rb,
lib/shale/schema/json_generator/date.rb,
lib/shale/schema/json_generator/time.rb,
lib/shale/mapping/group/dict_grouping.rb,
lib/shale/schema/compiler/xml_complex.rb,
lib/shale/schema/json_generator/float.rb,
lib/shale/schema/json_generator/value.rb,
lib/shale/schema/xml_generator/import.rb,
lib/shale/schema/xml_generator/schema.rb,
lib/shale/schema/compiler/xml_property.rb,
lib/shale/schema/json_generator/object.rb,
lib/shale/schema/json_generator/schema.rb,
lib/shale/schema/json_generator/string.rb,
lib/shale/schema/xml_generator/element.rb,
lib/shale/schema/json_generator/boolean.rb,
lib/shale/schema/json_generator/integer.rb,
lib/shale/schema/xml_generator/attribute.rb,
lib/shale/mapping/descriptor/xml_namespace.rb,
lib/shale/schema/json_generator/collection.rb,
lib/shale/schema/xml_generator/ref_element.rb,
lib/shale/schema/xml_generator/complex_type.rb,
lib/shale/schema/xml_generator/ref_attribute.rb,
lib/shale/schema/xml_generator/typed_element.rb,
lib/shale/schema/xml_generator/typed_attribute.rb

Overview

Main library namespace

Shale uses adapters for parsing and serializing documents. For handling JSON, YAML, TOML and CSV, adapter must implement .load and .dump methods, so e.g for handling JSON, MultiJson works out of the box.

Adapters for XML handling are more complicated and must conform to [@see shale/adapter/rexml] Shale provides adaters for most popular XML parsing libraries: Shale::Adapter::REXML, Shale::Adapter::Nokogiri and Shale::Adapter::Ox

By default Shale::Adapter::REXML is used so no external dependencies are needed, but it’s not as performant as Nokogiri or Ox, so you may want to change it.

Examples:

setting MultiJSON for handling JSON documents

Shale.json_adapter = MultiJson
Shale.json_adapter # => MultiJson

setting TOML adapter for handling TOML documents

require 'shale/adapter/toml_rb'

Shale.toml_adapter = Shale::Adapter::TomlRB
Shale.toml_adapter # => Shale::Adapter::TomlRB

setting REXML adapter for handling XML documents

Shale.xml_adapter = Shale::Adapter::REXML
Shale.xml_adapter # => Shale::Adapter::REXML

setting Nokogiri adapter for handling XML documents

require 'shale/adapter/nokogiri'

Shale.xml_adapter = Shale::Adapter::Nokogir
Shale.xml_adapter # => Shale::Adapter::Nokogir

setting Ox adapter for handling XML documents

require 'shale/adapter/ox'

Shale.xml_adapter = Shale::Adapter::Ox
Shale.xml_adapter # => Shale::Adapter::Ox

setting CSV adapter for handling CSV documents

require 'shale/adapter/csv'

Shale.csv_adapter = Shale::Adapter::CSV
Shale.csv_adapter # => Shale::Adapter::CSV

Defined Under Namespace

Modules: Adapter, Mapping, Schema, Type, Utils Classes: AdapterError, Attribute, AttributeNotDefinedError, DefaultNotCallableError, IncorrectMappingArgumentsError, IncorrectModelError, Mapper, NotAShaleMapperError, NotATypeValueError, ParseError, SchemaError, ShaleError, UnknownAttributeError, UnknownTypeError

Constant Summary collapse

TOML_ADAPTER_NOT_SET_MESSAGE =

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

Error message displayed when TOML adapter is not set

<<~MSG
  TOML Adapter is not set.
  To use Shale with TOML documents you have to install parser and set adapter.

  # To use Tomlib:
  # Make sure tomlib is installed eg. execute: gem install tomlib
  require 'shale/adapter/tomlib'
  Shale.toml_adapter = Shale::Adapter::Tomlib

  # To use toml-rb:
  # Make sure toml-rb is installed eg. execute: gem install toml-rb
  require 'shale/adapter/toml_rb'
  Shale.toml_adapter = Shale::Adapter::TomlRB
MSG
XML_ADAPTER_NOT_SET_MESSAGE =

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

Error message displayed when XML adapter is not set

<<~MSG
  XML Adapter is not set.
  To use Shale with XML documents you have to install parser and set adapter.

  # To use REXML:
  require 'shale/adapter/rexml'
  Shale.xml_adapter = Shale::Adapter::REXML

  # To use Nokogiri:
  # Make sure Nokogiri is installed eg. execute: gem install nokogiri
  require 'shale/adapter/nokogiri'
  Shale.xml_adapter = Shale::Adapter::Nokogiri

  # To use OX:
  # Make sure Ox is installed eg. execute: gem install ox
  require 'shale/adapter/ox'
  Shale.xml_adapter = Shale::Adapter::Ox
MSG
CSV_ADAPTER_NOT_SET_MESSAGE =

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

Error message displayed when CSV adapter is not set

<<~MSG
  CSV Adapter is not set.
  To use Shale with CSV documents you have to install parser and set adapter.

  # To use csv gem:
  # Make sure csv is installed eg. execute: gem install csv
  require 'shale/adapter/csv'
  Shale.csv_adapter = Shale::Adapter::CSV
MSG
VERSION =

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

'1.2.0'

Class Attribute Summary collapse

Class Attribute Details

.csv_adapterObject

Set CSV adapter

Examples:

setting adapter

Shale.csv_adapter = Shale::Adapter::CSV

getting adapter

Shale.csv_adapter
# => Shale::Adapter::CSV

Parameters:

  • adapter (.load, .dump)


111
112
113
# File 'lib/shale.rb', line 111

def csv_adapter
  @csv_adapter
end

.json_adapter.load, .dump

Return JSON adapter. By default Shale::Adapter::JSON is used

Examples:

Shale.json_adapter
# => Shale::Adapter::JSON

Returns:

  • (.load, .dump)


137
138
139
# File 'lib/shale.rb', line 137

def json_adapter
  @json_adapter || Adapter::JSON
end

.toml_adapterObject

TOML adapter accessor. Available adapters are Shale::Adapter::Tomlib and Shale::Adapter::TomRB

Examples:

setting adapter

Shale.toml_adapter = Shale::Adapter::Tomlib

getting adapter

Shale.toml_adapter
# => Shale::Adapter::Tomlib

Parameters:



97
98
99
# File 'lib/shale.rb', line 97

def toml_adapter
  @toml_adapter
end

.xml_adapterObject

XML adapter accessor. Available adapters are Shale::Adapter::REXML, Shale::Adapter::Nokogiri and Shale::Adapter::Ox

Examples:

setting adapter

Shale.xml_adapter = Shale::Adapter::REXML

getting adapter

Shale.xml_adapter
# => Shale::Adapter::REXML

Parameters:



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

def xml_adapter
  @xml_adapter
end

.yaml_adapter.load, .dump

Return YAML adapter. By default YAML is used

Examples:

Shale.yaml_adapter
# => YAML

Returns:

  • (.load, .dump)


150
151
152
# File 'lib/shale.rb', line 150

def yaml_adapter
  @yaml_adapter || YAML
end