Sha256: ccd039d6827064ecc55b5feb06ec77bd246fa85fd756e3844f1744198569015e

Contents?: true

Size: 701 Bytes

Versions: 2

Compression:

Stored size: 701 Bytes

Contents

module Id::Field
  class Summary
    def initialize(definition)
      @definition = definition
    end

    def to_s
      [name, type, key, optional, default].compact.join("\n")
    end

    private
    attr_reader :definition

    def name
      "Name: #{definition.name}"
    end

    def type
      "Type: #{definition.type}" unless definition.type == Object
    end

    def key
      "Key in hash: #{definition.key}" unless definition.key == definition.name.to_s
    end

    def optional
      "Optional: true" if definition.optional?
    end

    def default
      default = definition.default
      "Default: #{default.is_a?(Proc) ? 'Lambda' : default}" unless default.nil?
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
id-0.1.1 lib/id/field/summary.rb
id-0.1 lib/id/field/summary.rb