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.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rabl/configuration.rb', line 42

def initialize
  @include_json_root     = true
  @include_msgpack_root  = true
  @include_plist_root    = true
  @include_xml_root      = false
  @include_bson_root     = true
  @enable_json_callbacks = false
  @bson_check_keys       = false
  @bson_move_id          = false
  @json_engine           = nil
  @msgpack_engine        = nil
  @bson_engine           = nil
  @plist_engine          = nil
  @xml_options           = {}
  @cache_sources         = false
  @cache_all_output      = false
end

Instance Attribute Details

#bson_check_keysObject

Returns the value of attribute bson_check_keys.



31
32
33
# File 'lib/rabl/configuration.rb', line 31

def bson_check_keys
  @bson_check_keys
end

#bson_engineObject

Returns the Bson encoder/engine to use.

Returns:

  • the Bson encoder/engine to use.



80
81
82
# File 'lib/rabl/configuration.rb', line 80

def bson_engine
  @bson_engine || ::BSON
end

#bson_move_idObject

Returns the value of attribute bson_move_id.



32
33
34
# File 'lib/rabl/configuration.rb', line 32

def bson_move_id
  @bson_move_id
end

#cache_all_outputObject

Returns the value of attribute cache_all_output.



38
39
40
# File 'lib/rabl/configuration.rb', line 38

def cache_all_output
  @cache_all_output
end

#cache_sourcesObject

Returns the value of attribute cache_sources.



37
38
39
# File 'lib/rabl/configuration.rb', line 37

def cache_sources
  @cache_sources
end

#enable_json_callbacksObject

Returns the value of attribute enable_json_callbacks.



30
31
32
# File 'lib/rabl/configuration.rb', line 30

def enable_json_callbacks
  @enable_json_callbacks
end

#include_bson_rootObject

Returns the value of attribute include_bson_root.



29
30
31
# File 'lib/rabl/configuration.rb', line 29

def include_bson_root
  @include_bson_root
end

#include_json_rootObject

Returns the value of attribute include_json_root.



25
26
27
# File 'lib/rabl/configuration.rb', line 25

def include_json_root
  @include_json_root
end

#include_msgpack_rootObject

Returns the value of attribute include_msgpack_root.



26
27
28
# File 'lib/rabl/configuration.rb', line 26

def include_msgpack_root
  @include_msgpack_root
end

#include_plist_rootObject

Returns the value of attribute include_plist_root.



27
28
29
# File 'lib/rabl/configuration.rb', line 27

def include_plist_root
  @include_plist_root
end

#include_xml_rootObject

Returns the value of attribute include_xml_root.



28
29
30
# File 'lib/rabl/configuration.rb', line 28

def include_xml_root
  @include_xml_root
end

#msgpack_engineObject

Returns the MessagePack encoder/engine to use.

Returns:

  • the MessagePack encoder/engine to use.



74
75
76
# File 'lib/rabl/configuration.rb', line 74

def msgpack_engine
  @msgpack_engine || ::MessagePack
end

#plist_engineObject

Returns the Plist encoder/engine to use.

Returns:

  • the Plist encoder/engine to use.



86
87
88
# File 'lib/rabl/configuration.rb', line 86

def plist_engine
  @plist_engine || ::Plist::Emit
end

#xml_options=(value) ⇒ Object (writeonly)

Sets the attribute xml_options

Parameters:

  • value

    the value to set the attribute xml_options to.



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

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



93
94
95
# File 'lib/rabl/configuration.rb', line 93

def [](option)
  send(option)
end

#default_xml_optionsObject

Returns merged default and inputted xml options



98
99
100
# File 'lib/rabl/configuration.rb', line 98

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



68
69
70
# File 'lib/rabl/configuration.rb', line 68

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.



63
64
65
# File 'lib/rabl/configuration.rb', line 63

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