Sha256: f4641a11ff3a72dd1ffc8c788a75a720ea6bda1de5c63e16d0a97a3fbc3ef28c

Contents?: true

Size: 920 Bytes

Versions: 9

Compression:

Stored size: 920 Bytes

Contents

module Virtus
  class Attribute
    class DefaultValue

      # Represents default value evaluated via a clonable object
      #
      # @api private
      class FromClonable < DefaultValue
        SINGLETON_CLASSES = [
          ::NilClass, ::TrueClass, ::FalseClass, ::Numeric,  ::Symbol ].freeze

        # Return if the class can handle the value
        #
        # @param [Object] value
        #
        # @return [Boolean]
        #
        # @api private
        def self.handle?(value)
          case value
          when *SINGLETON_CLASSES
            false
          else
            true
          end
        end

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

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

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
virtus-0.5.5 lib/virtus/attribute/default_value/from_clonable.rb
virtus-0.5.4 lib/virtus/attribute/default_value/from_clonable.rb
virtus-0.5.3 lib/virtus/attribute/default_value/from_clonable.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/virtus-0.5.2/lib/virtus/attribute/default_value/from_clonable.rb
virtus-0.5.2 lib/virtus/attribute/default_value/from_clonable.rb
virtus-0.5.1 lib/virtus/attribute/default_value/from_clonable.rb
virtus-0.5.0 lib/virtus/attribute/default_value/from_clonable.rb
virtus-0.4.2 lib/virtus/attribute/default_value/from_clonable.rb
virtus-0.4.1 lib/virtus/attribute/default_value/from_clonable.rb