Sha256: 10281c175b17694c2a1c4921bf7da11adf15828d7b7927fd4768784f2b7879d9

Contents?: true

Size: 592 Bytes

Versions: 4

Compression:

Stored size: 592 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 = {}, &block)
      @all ||= Relation.new(model: self)
      instance = super(opts, &block)
      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

4 entries across 4 versions & 1 rubygems

Version Path
lazy_record-0.1.8 lib/lazy_record/callbacks.rb
lazy_record-0.1.7 lib/lazy_record/callbacks.rb
lazy_record-0.1.6 lib/lazy_record/callbacks.rb
lazy_record-0.1.4 lib/lazy_record/callbacks.rb