Class: Rabl::Configuration

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

Overview

Rabl.host

Constant Summary collapse

DEFAULT_XML_OPTIONS =
{ :dasherize  => true, :skip_types => false }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



22
23
24
25
26
27
28
29
30
# File 'lib/rabl/configuration.rb', line 22

def initialize
  @include_json_root     = true
  @include_msgpack_root  = true
  @include_xml_root      = false
  @enable_json_callbacks = false
  @json_engine           = nil
  @msgpack_engine        = nil
  @xml_options           = {}
end

Instance Attribute Details

#enable_json_callbacksObject

Returns the value of attribute enable_json_callbacks.



16
17
18
# File 'lib/rabl/configuration.rb', line 16

def enable_json_callbacks
  @enable_json_callbacks
end

#include_json_rootObject

Returns the value of attribute include_json_root.



13
14
15
# File 'lib/rabl/configuration.rb', line 13

def include_json_root
  @include_json_root
end

#include_msgpack_rootObject

Returns the value of attribute include_msgpack_root.



14
15
16
# File 'lib/rabl/configuration.rb', line 14

def include_msgpack_root
  @include_msgpack_root
end

#include_xml_rootObject

Returns the value of attribute include_xml_root.



15
16
17
# File 'lib/rabl/configuration.rb', line 15

def include_xml_root
  @include_xml_root
end

#msgpack_engineObject

Returns the MessagePack encoder/engine to use.

Returns:

  • the MessagePack encoder/engine to use.



46
47
48
# File 'lib/rabl/configuration.rb', line 46

def msgpack_engine
  @msgpack_engine || ::MessagePack
end

#xml_options=(value) ⇒ Object (writeonly)

Sets the attribute xml_options

Parameters:

  • value

    the value to set the attribute xml_options to.



18
19
20
# File 'lib/rabl/configuration.rb', line 18

def xml_options=(value)
  @xml_options = value
end

Instance Method Details

#[](option) ⇒ Object

Allows config options to be read like a hash

Parameters:

  • option (Symbol)

    Key for a given attribute



53
54
55
# File 'lib/rabl/configuration.rb', line 53

def [](option)
  send(option)
end

#default_xml_optionsObject

Returns merged default and inputted xml options



58
59
60
# File 'lib/rabl/configuration.rb', line 58

def default_xml_options
  @_default_xml_options ||= @xml_options.reverse_merge(DEFAULT_XML_OPTIONS)
end

#json_engineObject

Returns The JSON engine used to encode Rabl templates into JSON.

Returns:

  • The JSON engine used to encode Rabl templates into JSON



40
41
42
# File 'lib/rabl/configuration.rb', line 40

def json_engine
  get_json_engine
end

#json_engine=(engine_name_or_class) ⇒ Object

Parameters:

  • engine_name (Symbol, String, #encode)

    The name of a JSON engine, or class that responds to ‘encode`, to use to encode Rabl templates into JSON. For more details, see the MultiJson gem.



35
36
37
# File 'lib/rabl/configuration.rb', line 35

def json_engine=(engine_name_or_class)
  MultiJson.engine = @engine_name = engine_name_or_class
end