Class: Lurker::Json::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/lurker/json/parser.rb,
lib/lurker/json/parser/expertise.rb,
lib/lurker/json/parser/plain_strategy.rb,
lib/lurker/json/parser/typed_strategy.rb

Defined Under Namespace

Modules: Expertise Classes: PlainStrategy, TypedStrategy

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Parser

Returns a new instance of Parser.



14
15
16
17
18
19
20
21
# File 'lib/lurker/json/parser.rb', line 14

def initialize(options = {})
  @root_schema = options[:root_schema]
  @parent_schema = options[:parent_schema]
  @parent_property = options[:parent_property]
  @polymorph_if_empty = options.fetch(:polymorph_if_empty, false)
  @uri = options[:uri] || @parent_schema.try(:uri)
  @strategy = nil
end

Class Method Details

.plain(options = {}) ⇒ Object



5
6
7
# File 'lib/lurker/json/parser.rb', line 5

def plain(options = {})
  new(options).plain
end

.typed(options = {}) ⇒ Object



9
10
11
# File 'lib/lurker/json/parser.rb', line 9

def typed(options = {})
  new(options).typed
end

Instance Method Details

#parse(payload) ⇒ Object



23
24
25
# File 'lib/lurker/json/parser.rb', line 23

def parse(payload)
  parse_once { @strategy.new(schema_options_once).parse(payload) }
end

#parse_property(property, payload) ⇒ Object



27
28
29
30
# File 'lib/lurker/json/parser.rb', line 27

def parse_property(property, payload)
  options = schema_options_once.merge!(parent_property: property)
  parse_once { @strategy.new(options).parse(payload) }
end

#plain(options = {}) ⇒ Object



32
33
34
35
36
# File 'lib/lurker/json/parser.rb', line 32

def plain(options = {})
  @options = schema_options.merge!(options)
  @strategy = strategy_klass(:plain)
  self
end

#typed(options = {}) ⇒ Object



38
39
40
41
42
# File 'lib/lurker/json/parser.rb', line 38

def typed(options = {})
  @options = schema_options.merge!(options)
  @strategy = strategy_klass(:typed)
  self
end