Copy the current model object's default json options into the subclass.
# File lib/sequel/plugins/json_serializer.rb, line 126 def inherited(subclass) super opts = {} json_serializer_opts.each{|k, v| opts[k] = (v.is_a?(Array) || v.is_a?(Hash)) ? v.dup : v} subclass.instance_variable_set(:@json_serializer_opts, opts) end
Create a new model object from the hash provided by parsing JSON. Handles column values (stored in values), associations (stored in associations), and other values (by calling a setter method). If an entry in the hash is not a column or an association, and no setter method exists, raises an Error.
# File lib/sequel/plugins/json_serializer.rb, line 100 def json_create(hash) obj = new cols = columns.map{|x| x.to_s} assocs = associations.map{|x| x.to_s} meths = obj.send(:setter_methods, nil, nil) hash.delete(JSON.create_id) hash.each do |k, v| if assocs.include?(k) obj.associations[k.to_sym] = v elsif meths.include?("#{k}=") obj.send("#{k}=", v) elsif cols.include?(k) obj.values[k.to_sym] = v else raise Error, "Entry in JSON hash not an association or column and no setter method exists: #{k}" end end obj end
Generated with the Darkfish Rdoc Generator 2.