Sha256: b5ffe210a0a2070cb871f7ad93ad8b73924865dc033f790adedde2c76b94e43b

Contents?: true

Size: 807 Bytes

Versions: 3

Compression:

Stored size: 807 Bytes

Contents

module Dataset
  module Record # :nodoc:
    
    class Model # :nodoc:
      attr_reader :attributes, :model, :meta, :symbolic_name
      
      def initialize(meta, attributes, symbolic_name = nil)
        @meta          = meta
        @attributes    = attributes.stringify_keys
        @symbolic_name = symbolic_name || object_id
      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 {|k,v| m.send "#{k}=", v}
          m
        end
      end
    end
    
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
radiant-0.7.2 vendor/plugins/dataset/lib/dataset/record/model.rb
radiant-0.7.0 vendor/plugins/dataset/lib/dataset/record/model.rb
radiant-0.7.1 vendor/plugins/dataset/lib/dataset/record/model.rb