Sha256: fd1ee2be1b032fa71610693abfdad96adbd9d4dafb17cffd6194ec3b8f314bca

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

require 'parameters/param'

module Parameters
  class ClassParam < Param

    # Default value of the class parameter
    attr_reader :value

    #
    # Creates a new ClassParam object.
    #
    # @param [Symbol, String] name
    #   The name of the class parameter.
    #
    # @param [Class, Array[Class]] type
    #   The enforced type of the class parameter.
    #
    # @param [String, nil] description
    #   The description of the class parameter.
    #
    # @param [Object, nil] value
    #   The default value of the class parameter.
    #
    def initialize(name,type=nil,description=nil,value=nil)
      super(name,type,description)

      @value = value
    end

    #
    # Sets the value of the class param.
    #
    # @param [Object] value
    #   The new value of the class param.
    #
    # @return [Object]
    #   The new value of the class param.
    #
    # @since 0.2.0
    #
    def value=(new_value)
      @value = coerce(new_value)
    end

    #
    # @return [String]
    #   The representation of the class param.
    #
    def to_s
      text = @name.to_s

      text << " [#{@value.inspect}]" if @value
      text << "\t#{@description}" if @description

      return text
    end

    #
    # Inspects the class parameter.
    #
    # @return [String]
    #   Inspection of the class params value.
    #
    def inspect
      "#<#{self.class}: #{@value.inspect}>"
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
parameters-0.2.3 lib/parameters/class_param.rb
parameters-0.2.2 lib/parameters/class_param.rb