Sha256: baa0cc4174554af5aef0017ac059a167ed9c7af136d91c5d2f8940ab0071eb32

Contents?: true

Size: 1.11 KB

Versions: 72

Compression:

Stored size: 1.11 KB

Contents

require 'clamp/attribute/definition'

module Clamp
  module Parameter

    class Definition < Attribute::Definition

      def initialize(name, description, options = {})
        @name = name
        @description = description
        super(options)
        @multivalued = (@name =~ ELLIPSIS_SUFFIX)
        @required = options.fetch(:required) do
          (@name !~ OPTIONAL)
        end
      end

      attr_reader :name

      def help_lhs
        name
      end

      def consume(arguments)
        raise ArgumentError, "no value provided" if required? && arguments.empty?
        arguments.shift(multivalued? ? arguments.length : 1)
      end

      private

      ELLIPSIS_SUFFIX = / \.\.\.$/
      OPTIONAL = /^\[(.*)\]/

      VALID_ATTRIBUTE_NAME = /^[a-z0-9_]+$/

      def infer_attribute_name
        inferred_name = name.downcase.tr('-', '_').sub(ELLIPSIS_SUFFIX, '').sub(OPTIONAL) { $1 }
        unless inferred_name =~ VALID_ATTRIBUTE_NAME
          raise "cannot infer attribute_name from #{name.inspect}"
        end
        inferred_name += "_list" if multivalued?
        inferred_name
      end

    end

  end
end

Version data entries

72 entries across 68 versions & 18 rubygems

Version Path
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/clamp-0.6.5/lib/clamp/parameter/definition.rb
logstash-filter-csharp-0.1.0 vendor/bundle/jruby/2.3.0/gems/clamp-0.6.5/lib/clamp/parameter/definition.rb
logstash-filter-htmlentities-0.1.0 vendor/bundle/jruby/1.9/gems/clamp-0.6.5/lib/clamp/parameter/definition.rb
logstash-output-icinga-1.0.0 vendor/jruby/1.9/gems/clamp-0.6.5/lib/clamp/parameter/definition.rb
logstash-filter-zabbix-0.1.2 vendor/bundle/jruby/1.9/gems/clamp-0.6.5/lib/clamp/parameter/definition.rb
logstash-filter-zabbix-0.1.1 vendor/bundle/jruby/1.9/gems/clamp-0.6.5/lib/clamp/parameter/definition.rb
logstash-input-fifo-0.9.1 vendor/bundle/jruby/1.9/gems/clamp-0.6.5/lib/clamp/parameter/definition.rb
logstash-input-fifo-0.9.0 vendor/bundle/jruby/1.9/gems/clamp-0.6.5/lib/clamp/parameter/definition.rb
logstash-input-salesforce-3.0.0 vendor/jruby/1.9/gems/clamp-0.6.5/lib/clamp/parameter/definition.rb
ivanvc-logstash-input-s3-3.1.1.4 vendor/local/gems/clamp-0.6.5/lib/clamp/parameter/definition.rb
ivanvc-logstash-input-s3-3.1.1.3 vendor/local/gems/clamp-0.6.5/lib/clamp/parameter/definition.rb
ivanvc-logstash-input-s3-3.1.1.2 vendor/local/gems/clamp-0.6.5/lib/clamp/parameter/definition.rb
logstash-filter-delta-1.1.0 vendor/bundle/jruby/2.2.0/gems/clamp-0.6.5/lib/clamp/parameter/definition.rb
logstash-filter-delta-1.0.1 vendor/bundle/jruby/2.2.0/gems/clamp-0.6.5/lib/clamp/parameter/definition.rb
logstash-filter-base64-1.0.4 vendor/bundle/jruby/2.2.0/gems/clamp-0.6.5/lib/clamp/parameter/definition.rb
logstash-filter-base64-1.0.3 vendor/bundle/jruby/2.2.0/gems/clamp-0.6.5/lib/clamp/parameter/definition.rb
logstash-filter-delta-1.0.0 vendor/bundle/jruby/2.2.0/gems/clamp-0.6.5/lib/clamp/parameter/definition.rb
logstash-filter-base64-1.0.2 vendor/bundle/jruby/2.3.0/gems/clamp-0.6.5/lib/clamp/parameter/definition.rb
logstash-filter-base64-1.0.1 vendor/bundle/jruby/2.3.0/gems/clamp-0.6.5/lib/clamp/parameter/definition.rb
logstash-filter-base64-1.0.0 vendor/bundle/jruby/2.3.0/gems/clamp-0.6.5/lib/clamp/parameter/definition.rb