Sha256: b19b4298f12ca6c9e3ab34c7566758360bdd4295eee98d0e359b99d133a7fc50

Contents?: true

Size: 1.02 KB

Versions: 7

Compression:

Stored size: 1.02 KB

Contents

module Virtus
  class Attribute

    # Class representing the default value option
    #
    # @api private
    class DefaultValue
      extend DescendantsTracker

      include Equalizer.new(inspect) << :value

      # Builds a default value instance
      #
      # @return [Virtus::Attribute::DefaultValue]
      #
      # @api private
      def self.build(*args)
        klass = descendants.detect { |descendant| descendant.handle?(*args) } || self
        klass.new(*args)
      end

      # Returns the value instance
      #
      # @return [Object]
      #
      # @api private
      attr_reader :value

      # Initializes an default value instance
      #
      # @param [Object] value
      #
      # @return [undefined]
      #
      # @api private
      def initialize(value)
        @value = value
      end

      # Evaluates the value
      #
      # @return [Object] evaluated value
      #
      # @api private
      def call(*)
        value
      end

    end # class DefaultValue
  end # class Attribute
end # module Virtus

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/lib/virtus/attribute/default_value.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/lib/virtus/attribute/default_value.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/lib/virtus/attribute/default_value.rb
virtus2-2.1.0 lib/virtus/attribute/default_value.rb
virtus2-2.0.2 lib/virtus/attribute/default_value.rb
virtus2-2.0.1 lib/virtus/attribute/default_value.rb
virtus-2.0.0 lib/virtus/attribute/default_value.rb