Method: Sequel::Plugins::JsonSerializer::ClassMethods#array_from_json
- Defined in:
- lib/sequel/plugins/json_serializer.rb
permalink #array_from_json(json, opts = OPTS) ⇒ Object
Attempt to parse an array of instances from the given JSON string, with options passed to InstanceMethods#from_json_node.
199 200 201 202 203 204 205 206 207 |
# File 'lib/sequel/plugins/json_serializer.rb', line 199 def array_from_json(json, opts=OPTS) v = Sequel.parse_json(json) if v.is_a?(Array) raise(Error, 'parsed json returned an array containing non-hashes') unless v.all?{|ve| ve.is_a?(Hash) || ve.is_a?(self)} v.map{|ve| ve.is_a?(self) ? ve : new.from_json_node(ve, opts)} else raise(Error, 'parsed json did not return an array') end end |