Sha256: 098fce583fd0120605e4ff09658b6f357467b4d1828f6d9102ff1ffa533b0536

Contents?: true

Size: 583 Bytes

Versions: 4

Compression:

Stored size: 583 Bytes

Contents

require 'active_support/concern'
require 'active_support/inflector'

module Ripple
  module EmbeddedDocument
    # @private
    module Finders
      extend ActiveSupport::Concern

      module ClassMethods
        def instantiate(attrs)
          begin
            klass = attrs['_type'].present? ? attrs.delete('_type').constantize : self
          rescue NameError
            klass = self
          end
          klass.new.tap do |object|
            object.raw_attributes = attrs
            object.changed_attributes.clear
          end
        end
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
wyngle-ripple-0.1.0 lib/ripple/embedded_document/finders.rb
better-ripple-1.0.0 lib/ripple/embedded_document/finders.rb
ripple-1.0.0.beta2 lib/ripple/embedded_document/finders.rb
ripple-1.0.0.beta lib/ripple/embedded_document/finders.rb