Class: Sequel::Postgres::PGArray::JSONCreator
- Defined in:
- lib/sequel/extensions/pg_array.rb
Overview
Callable object that takes the input string and parses it using. a JSON parser. This should be faster than the standard Creator, but only handles integer types correctly.
Constant Summary collapse
- SUBST =
Character conversion map mapping input strings to JSON replacements
{'{'.freeze=>'['.freeze, '}'.freeze=>']'.freeze, 'NULL'.freeze=>'null'.freeze}
- SUBST_RE =
Regular expression matching input strings to convert
%r[\{|\}|NULL].freeze
Instance Attribute Summary
Attributes inherited from Creator
Instance Method Summary collapse
-
#call(string) ⇒ Object
Parse the input string by using a gsub to convert non-JSON characters to JSON, running it through a regular JSON parser.
Methods inherited from Creator
Constructor Details
This class inherits a constructor from Sequel::Postgres::PGArray::Creator
Instance Method Details
#call(string) ⇒ Object
Parse the input string by using a gsub to convert non-JSON characters to JSON, running it through a regular JSON parser. If a converter is used, a recursive map of the output is done to make sure that the entires in the correct type.
477 478 479 480 481 |
# File 'lib/sequel/extensions/pg_array.rb', line 477 def call(string) array = Sequel.parse_json(string.gsub(SUBST_RE){|m| SUBST[m]}) array = Sequel.recursive_map(array, @converter) if @converter PGArray.new(array, @type) end |