Module: ElasticRecord::JSON

Defined in:
lib/elastic_record/json.rb

Class Method Summary collapse

Class Method Details

.decode(json) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/elastic_record/json.rb', line 12

def decode(json)
  if ElasticRecord::JSON.parser == :oj
    Oj.compat_load(json)
  else
    ActiveSupport::JSON.decode(json)
  end
end

.encode(data) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/elastic_record/json.rb', line 20

def encode(data)
  if ElasticRecord::JSON.parser == :oj
    Oj.dump(data, mode: :compat)
  else
    ActiveSupport::JSON.encode(data)
  end
end

.parserObject



4
5
6
# File 'lib/elastic_record/json.rb', line 4

def parser
  @@parser ||= :active_support
end

.parser=(value) ⇒ Object



8
9
10
# File 'lib/elastic_record/json.rb', line 8

def parser=(value)
  @@parser = value
end