Sha256: a85c1b66c9dacad0e5e5cd47999224b54f31a1c7a3fa54b06a109a14d97f3c66

Contents?: true

Size: 879 Bytes

Versions: 9

Compression:

Stored size: 879 Bytes

Contents

module Virtus
  class Attribute
    class DefaultValue

      # Represents default value evaluated via a symbol
      #
      # @api private
      class FromSymbol < DefaultValue

        # Return if the class can handle the value
        #
        # @param [Object] value
        #
        # @return [Boolean]
        #
        # @api private
        def self.handle?(value)
          value.is_a?(::Symbol)
        end

        # Evaluates the value via instance#public_send(value)
        #
        # Symbol value is returned if the instance doesn't respond to value
        #
        # @return [Object] evaluated value
        #
        # @api private
        def call(instance, *)
          instance.respond_to?(@value) ? instance.public_send(@value) : @value
        end

      end # class FromSymbol
    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_symbol.rb
virtus-0.5.4 lib/virtus/attribute/default_value/from_symbol.rb
virtus-0.5.3 lib/virtus/attribute/default_value/from_symbol.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/virtus-0.5.2/lib/virtus/attribute/default_value/from_symbol.rb
virtus-0.5.2 lib/virtus/attribute/default_value/from_symbol.rb
virtus-0.5.1 lib/virtus/attribute/default_value/from_symbol.rb
virtus-0.5.0 lib/virtus/attribute/default_value/from_symbol.rb
virtus-0.4.2 lib/virtus/attribute/default_value/from_symbol.rb
virtus-0.4.1 lib/virtus/attribute/default_value/from_symbol.rb