method

deserialize

Importance_0
v7.1.3.2 - Show latest stable - 0 notes - Class: Hstore
deserialize(value) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rb, line 18
          def deserialize(value)
            return value unless value.is_a?(::String)

            scanner = StringScanner.new(value)
            hash = {}

            until scanner.eos?
              unless scanner.skip(/"/)
                raise(ArgumentError, ERROR % scanner.string.inspect)
              end

              unless key = scanner.scan(/^(\\[\\"]|[^\\"])*?(?=")/)
                raise(ArgumentError, ERROR % scanner.string.inspect)
              end

              unless scanner.skip(/"=>?/)
                raise(ArgumentError, ERROR % scanner.string.inspect)
              end

              if scanner.scan(/NULL/)
                value = nil
              else
                unless scanner.skip(/"/)
                  raise(ArgumentError, ERROR % scanner.string.inspect)
                end

                unless value = scanner.scan(/^(\\[\\"]|[^\\"])*?(?=")/)
                  raise(ArgumentError, ERROR % scanner.string.inspect)
                end

                unless scanner.skip(/"/)
                  raise(ArgumentError, ERROR % scanner.string.inspect)
                end
              end

              key.gsub!('\"', '"')
              key.gsub!("\\\\", "\\")

              if value
                value.gsub!('\"', '"')
                value.gsub!("\\\\", "\\")
              end

              hash[key] = value

              unless scanner.skip(/, /) || scanner.eos?
                raise(ArgumentError, ERROR % scanner.string.inspect)
              end
            end

            hash
          end
Register or log in to add new notes.