Sha256: a221dc46c0e310d6667e4a27fc4812d5ad974e5d1b6e1a685bf4586504ccbaf3

Contents?: true

Size: 693 Bytes

Versions: 31

Compression:

Stored size: 693 Bytes

Contents

require 'active_record/attribute'

module ActiveRecord
  class Attribute # :nodoc:
    class UserProvidedDefault < FromUser # :nodoc:
      def initialize(name, value, type, database_default)
        @user_provided_value = value
        super(name, value, type, database_default)
      end

      def value_before_type_cast
        if user_provided_value.is_a?(Proc)
          @memoized_value_before_type_cast ||= user_provided_value.call
        else
          @user_provided_value
        end
      end

      def with_type(type)
        self.class.new(name, user_provided_value, type, original_attribute)
      end

      protected

      attr_reader :user_provided_value
    end
  end
end

Version data entries

31 entries across 31 versions & 4 rubygems

Version Path
activerecord-5.0.7.2 lib/active_record/attribute/user_provided_default.rb
activerecord-5.0.7.1 lib/active_record/attribute/user_provided_default.rb
activerecord-5.0.7 lib/active_record/attribute/user_provided_default.rb
activerecord-5.0.6 lib/active_record/attribute/user_provided_default.rb
activerecord-5.0.6.rc1 lib/active_record/attribute/user_provided_default.rb
activerecord-5.0.5 lib/active_record/attribute/user_provided_default.rb
activerecord-5.0.5.rc2 lib/active_record/attribute/user_provided_default.rb
activerecord-5.0.5.rc1 lib/active_record/attribute/user_provided_default.rb
activerecord-5.0.4 lib/active_record/attribute/user_provided_default.rb
activerecord-5.0.4.rc1 lib/active_record/attribute/user_provided_default.rb
activerecord-5.0.3 lib/active_record/attribute/user_provided_default.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activerecord-5.0.2/lib/active_record/attribute/user_provided_default.rb
activerecord-5.0.2 lib/active_record/attribute/user_provided_default.rb
activerecord-5.0.2.rc1 lib/active_record/attribute/user_provided_default.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/attribute/user_provided_default.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/attribute/user_provided_default.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/attribute/user_provided_default.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/attribute/user_provided_default.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/attribute/user_provided_default.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/attribute/user_provided_default.rb