Module: Mustache::JSON

Defined in:
lib/mustache_json.rb,
lib/mustache/json/backends/yajl.rb,
lib/mustache/json/backends/json_gem.rb,
lib/mustache/json/backends/json_pure.rb,
lib/mustache/json/backends/active_support.rb

Defined Under Namespace

Modules: Backends

Class Method Summary collapse

Class Method Details

.backendObject

:nodoc:



32
33
34
35
# File 'lib/mustache_json.rb', line 32

def self.backend #:nodoc:
  self.backend = :json_gem unless defined?(@backend)
  @backend
end

.backend=(backend) ⇒ Object

Set the back-end for the JSON encoder in a swappable fashion. Currently supported backends:

  • :json_gem

  • :json_pure

  • :active_support

  • :yajl

The default backend is the JSON gem.



46
47
48
49
# File 'lib/mustache_json.rb', line 46

def self.backend=(backend)
  require "mustache/json/backends/#{backend.to_s.downcase}.rb"
  @backend = class_for(backend)
end

.class_for(backend) ⇒ Object

:nodoc:



56
57
58
59
# File 'lib/mustache_json.rb', line 56

def self.class_for(backend)#:nodoc:
  class_name = backend.to_s.split('_').map(&:capitalize).join('')
  eval "Mustache::JSON::Backends::#{class_name}"
end

.encode(object) ⇒ Object

Generic JSON encoder that will use the specified back-end.



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

def self.encode(object)
  self.backend.encode(object)
end