Class: Moxml::Config

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

Constant Summary collapse

VALID_ADAPTERS =
i[nokogiri oga rexml ox headed_ox libxml].freeze
DEFAULT_ADAPTER =
VALID_ADAPTERS.first

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter_name = nil, strict_parsing = nil, default_encoding = nil) ⇒ Config

Returns a new instance of Config.



26
27
28
29
30
31
32
33
34
# File 'lib/moxml/config.rb', line 26

def initialize(adapter_name = nil, strict_parsing = nil,
               default_encoding = nil)
  self.adapter = adapter_name || Config.default.adapter_name
  @strict_parsing = strict_parsing || Config.default.strict_parsing
  @default_encoding = default_encoding || Config.default.default_encoding
  # reserved for future use
  @default_indent = 2
  @entity_encoding = :basic
end

Class Attribute Details

.default_adapterObject



15
16
17
# File 'lib/moxml/config.rb', line 15

def default_adapter
  @default_adapter ||= DEFAULT_ADAPTER
end

Instance Attribute Details

#adapter_nameObject (readonly)

Returns the value of attribute adapter_name.



20
21
22
# File 'lib/moxml/config.rb', line 20

def adapter_name
  @adapter_name
end

#default_encodingObject

Returns the value of attribute default_encoding.



21
22
23
# File 'lib/moxml/config.rb', line 21

def default_encoding
  @default_encoding
end

#default_indentObject

Returns the value of attribute default_indent.



21
22
23
# File 'lib/moxml/config.rb', line 21

def default_indent
  @default_indent
end

#entity_encodingObject

Returns the value of attribute entity_encoding.



21
22
23
# File 'lib/moxml/config.rb', line 21

def entity_encoding
  @entity_encoding
end

#strict_parsingObject

Returns the value of attribute strict_parsing.



21
22
23
# File 'lib/moxml/config.rb', line 21

def strict_parsing
  @strict_parsing
end

Class Method Details

.defaultObject



11
12
13
# File 'lib/moxml/config.rb', line 11

def default
  @default ||= new(default_adapter, true, "UTF-8")
end

Instance Method Details

#adapterObject



57
58
59
# File 'lib/moxml/config.rb', line 57

def adapter
  @adapter ||= Adapter.load(@adapter_name)
end

#adapter=(name) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/moxml/config.rb', line 36

def adapter=(name)
  name = name.to_sym
  @adapter = nil

  unless VALID_ADAPTERS.include?(name)
    raise Moxml::AdapterError.new(
      "Invalid adapter: #{name}",
      adapter: name,
      operation: "set_adapter",
    )
  end

  @adapter_name = name
  adapter
end

#default_adapter=(name) ⇒ Object



52
53
54
55
# File 'lib/moxml/config.rb', line 52

def default_adapter=(name)
  self.adapter = name
  self.class.default_adapter = name
end