Sha256: bb02126f6e244b42722fd6b36888cee03469317b043dda2d0c99ca2e754dd036
Contents?: true
Size: 1.11 KB
Versions: 43
Compression:
Stored size: 1.11 KB
Contents
module Dataset module Record # :nodoc: class Model # :nodoc: attr_reader :attributes, :model, :meta, :symbolic_name, :session_binding def initialize(meta, attributes, symbolic_name, session_binding) @meta = meta @attributes = attributes.stringify_keys @symbolic_name = symbolic_name || object_id @session_binding = session_binding end def record_class meta.record_class end def id model.id end def create model = to_model model.save! model end def to_hash to_model.attributes end def to_model @model ||= begin m = meta.record_class.new attributes.each do |k,v| if reflection = record_class.reflect_on_association(k.to_sym) case v when Symbol v = session_binding.find_model(reflection.klass, v) end end m.send "#{k}=", v end m end end end end end
Version data entries
43 entries across 43 versions & 8 rubygems