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

#initialize ⇒ Configuration

Returns a new instance of Configuration.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/rabl/configuration.rb', line 59

def initialize
  @include_json_root                            = true
  @include_child_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
  @escape_all_output                            = false
  @view_paths                                   = []
  @cache_engine                                 = Rabl::CacheEngine.new
  @perform_caching                              = false
  @use_read_multi                               = true
  @replace_nil_values_with_empty_strings        = false
  @replace_empty_string_values_with_nil_values  = false
  @exclude_nil_values                           = false
  @exclude_empty_values_in_collections          = false
  @camelize_keys                                = false
end

Instance Attribute Details

#bson_check_keys ⇒ Object

Returns the value of attribute bson_check_keys.



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

def bson_check_keys
  @bson_check_keys
end

#bson_engine ⇒ Object

Returns the Bson encoder/engine to use.

Returns:

  • the Bson encoder/engine to use.



101
102
103
# File 'lib/rabl/configuration.rb', line 101

def bson_engine
  @bson_engine || ::BSON
end

#bson_move_id ⇒ Object

Returns the value of attribute bson_move_id.



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

def bson_move_id
  @bson_move_id
end

#cache_all_output ⇒ Object

Returns the value of attribute cache_all_output.



44
45
46
# File 'lib/rabl/configuration.rb', line 44

def cache_all_output
  @cache_all_output
end

#cache_engine ⇒ Object

Returns the value of attribute cache_engine.



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

def cache_engine
  @cache_engine
end

#cache_sources ⇒ Object

Returns the value of attribute cache_sources.



43
44
45
# File 'lib/rabl/configuration.rb', line 43

def cache_sources
  @cache_sources
end

#camelize_keys ⇒ Object

Returns the value of attribute camelize_keys.



55
56
57
# File 'lib/rabl/configuration.rb', line 55

def camelize_keys
  @camelize_keys
end

#enable_json_callbacks ⇒ Object

Returns the value of attribute enable_json_callbacks.



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

def enable_json_callbacks
  @enable_json_callbacks
end

#escape_all_output ⇒ Object

Returns the value of attribute escape_all_output.



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

def escape_all_output
  @escape_all_output
end

#exclude_empty_values_in_collections ⇒ Object

Returns the value of attribute exclude_empty_values_in_collections.



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

def exclude_empty_values_in_collections
  @exclude_empty_values_in_collections
end

#exclude_nil_values ⇒ Object

Returns the value of attribute exclude_nil_values.



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

def exclude_nil_values
  @exclude_nil_values
end

#include_bson_root ⇒ Object

Returns the value of attribute include_bson_root.



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

def include_bson_root
  @include_bson_root
end

#include_child_root ⇒ Object

Returns the value of attribute include_child_root.



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

def include_child_root
  @include_child_root
end

#include_json_root ⇒ Object

Returns the value of attribute include_json_root.



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

def include_json_root
  @include_json_root
end

#include_msgpack_root ⇒ Object

Returns the value of attribute include_msgpack_root.



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

def include_msgpack_root
  @include_msgpack_root
end

#include_plist_root ⇒ Object

Returns the value of attribute include_plist_root.



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

def include_plist_root
  @include_plist_root
end

#include_xml_root ⇒ Object

Returns the value of attribute include_xml_root.



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

def include_xml_root
  @include_xml_root
end

#json_engine ⇒ Object

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

Returns:

  • The JSON engine used to encode Rabl templates into JSON



89
90
91
# File 'lib/rabl/configuration.rb', line 89

def json_engine
  @json_engine || (defined?(::Oj) ? ::Oj : ::JSON)
end

#msgpack_engine ⇒ Object

Returns the MessagePack encoder/engine to use.

Returns:

  • the MessagePack encoder/engine to use.



95
96
97
# File 'lib/rabl/configuration.rb', line 95

def msgpack_engine
  @msgpack_engine || ::MessagePack
end

#perform_caching ⇒ Object

Returns the value of attribute perform_caching.



49
50
51
# File 'lib/rabl/configuration.rb', line 49

def perform_caching
  @perform_caching
end

#plist_engine ⇒ Object

Returns the Plist encoder/engine to use.

Returns:

  • the Plist encoder/engine to use.



107
108
109
# File 'lib/rabl/configuration.rb', line 107

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

#raise_on_missing_attribute ⇒ Object

Returns the value of attribute raise_on_missing_attribute.



48
49
50
# File 'lib/rabl/configuration.rb', line 48

def raise_on_missing_attribute
  @raise_on_missing_attribute
end

#replace_empty_string_values_with_nil_values ⇒ Object

Returns the value of attribute replace_empty_string_values_with_nil_values.



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

def replace_empty_string_values_with_nil_values
  @replace_empty_string_values_with_nil_values
end

#replace_nil_values_with_empty_strings ⇒ Object

Returns the value of attribute replace_nil_values_with_empty_strings.



51
52
53
# File 'lib/rabl/configuration.rb', line 51

def replace_nil_values_with_empty_strings
  @replace_nil_values_with_empty_strings
end

#use_read_multi ⇒ Object

Returns the value of attribute use_read_multi.



50
51
52
# File 'lib/rabl/configuration.rb', line 50

def use_read_multi
  @use_read_multi
end

#view_paths ⇒ Object

Returns the value of attribute view_paths.



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

def view_paths
  @view_paths
end

#xml_options=(value) ⇒ Object (writeonly)

Sets the attribute xml_options

Parameters:

  • value —

    the value to set the attribute xml_options to.



42
43
44
# File 'lib/rabl/configuration.rb', line 42

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



114
115
116
# File 'lib/rabl/configuration.rb', line 114

def [](option)
  __send__(option)
end

#default_xml_options ⇒ Object

Returns merged default and inputted xml options



119
120
121
# File 'lib/rabl/configuration.rb', line 119

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