Class: Lurker::Json::Parser::TypedStrategy
- Inherits:
-
Object
- Object
- Lurker::Json::Parser::TypedStrategy
- Includes:
- Expertise
- Defined in:
- lib/lurker/json/parser/typed_strategy.rb
Instance Attribute Summary collapse
-
#schema_options ⇒ Object
readonly
Returns the value of attribute schema_options.
Instance Method Summary collapse
-
#initialize(options) ⇒ TypedStrategy
constructor
A new instance of TypedStrategy.
- #parse(payload) ⇒ Object
Methods included from Expertise
type_defined?, type_polymorph?, type_supposed?
Constructor Details
#initialize(options) ⇒ TypedStrategy
Returns a new instance of TypedStrategy.
9 10 11 12 13 14 |
# File 'lib/lurker/json/parser/typed_strategy.rb', line 9 def initialize() = .dup @polymorph_if_empty = .delete(:polymorph_if_empty) = end |
Instance Attribute Details
#schema_options ⇒ Object (readonly)
Returns the value of attribute schema_options.
7 8 9 |
# File 'lib/lurker/json/parser/typed_strategy.rb', line 7 def end |
Instance Method Details
#parse(payload) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/lurker/json/parser/typed_strategy.rb', line 16 def parse(payload) case payload when Lurker::Json::Schema payload when Hash return create_by_type(payload) if type_defined?(payload) return create_by_supposition(payload) if type_supposed?(payload) return create_polymorph(payload) if polymorph_if_empty? && type_polymorph?(payload) Lurker::Json::Object.new(payload, ) when Array return create_polymorph(payload) if polymorph_if_empty? && type_polymorph?(payload) Lurker::Json::List.new(payload, ) else Lurker::Json::Attribute.new(payload, ) end end |