Sha256: f6969cf16afc7be31f8a19881b55591fa7e77ad09fe826d05269328a37c0599c

Contents?: true

Size: 576 Bytes

Versions: 10

Compression:

Stored size: 576 Bytes

Contents

# frozen_string_literal: true

require 'lazy_record/dynamic_modules'

module LazyRecord
  # After #initialize callbacks for validations and setting object id.
  module Callbacks
    def new(opts = {})
      @all ||= Relation.new(model: self)
      instance = super(opts)
      if instance.respond_to?(:validation)
        instance = instance.validation(*@validations)
      end
      add_id(instance)
    end

    def add_id(instance)
      if instance
        all << instance
        instance.send(:id=, count)
      end
      instance
    end

    private :add_id
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
lazy_record-0.4.4 lib/lazy_record/callbacks.rb
lazy_record-0.4.3 lib/lazy_record/callbacks.rb
lazy_record-0.4.2 lib/lazy_record/callbacks.rb
lazy_record-0.4.1 lib/lazy_record/callbacks.rb
lazy_record-0.4.0 lib/lazy_record/callbacks.rb
lazy_record-0.3.0 lib/lazy_record/callbacks.rb
lazy_record-0.2.2 lib/lazy_record/callbacks.rb
lazy_record-0.2.1 lib/lazy_record/callbacks.rb
lazy_record-0.2.0 lib/lazy_record/callbacks.rb
lazy_record-0.1.9 lib/lazy_record/callbacks.rb