Sha256: 8cb2dce7d4e4585a2fe33849e8621735ec5c1dd3ee7e479f04697f34e1db9ed4

Contents?: true

Size: 1.36 KB

Versions: 28

Compression:

Stored size: 1.36 KB

Contents

require 'puppet/parameter/value_collection'

# An individual Value class.
class Puppet::Parameter::Value
  attr_reader :name, :options, :event
  attr_accessor :block, :call, :method, :required_features

  # Add an alias for this value.
  def alias(name)
    @aliases << convert(name)
  end

  # Return all aliases.
  def aliases
    @aliases.dup
  end

  # Store the event that our value generates, if it does so.
  def event=(value)
    @event = convert(value)
  end

  def initialize(name)
    if name.is_a?(Regexp)
      @name = name
    else
      # Convert to a string and then a symbol, so things like true/false
      # still show up as symbols.
      @name = convert(name)
    end

    @aliases = []

    @call = :instead
  end

  # Does a provided value match our value?
  def match?(value)
    if regex?
      return true if name =~ value.to_s
    else
      return(name == convert(value) ? true : @aliases.include?(convert(value)))
    end
  end

  # Is our value a regex?
  def regex?
    @name.is_a?(Regexp)
  end

  private

  # A standard way of converting all of our values, so we're always
  # comparing apples to apples.
  def convert(value)
    case value
    when Symbol, ''             # can't intern an empty string
      value
    when String
      value.intern
    when true
      :true
    when false
      :false
    else
      value.to_s.intern
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
puppet-parse-0.1.4 lib/vendor/puppet/parameter/value.rb
puppet-parse-0.1.3 lib/vendor/puppet/parameter/value.rb
puppet-parse-0.1.2 lib/vendor/puppet/parameter/value.rb
puppet-parse-0.1.1 lib/vendor/puppet/parameter/value.rb
puppet-2.7.26 lib/puppet/parameter/value.rb
puppet-2.7.25 lib/puppet/parameter/value.rb
puppet-2.7.24 lib/puppet/parameter/value.rb
puppet-2.7.23 lib/puppet/parameter/value.rb
puppet-2.7.22 lib/puppet/parameter/value.rb
puppet-parse-0.1.0 lib/vendor/puppet/parameter/value.rb
puppet-parse-0.0.6 lib/vendor/puppet/parameter/value.rb
puppet-2.7.21 lib/puppet/parameter/value.rb
puppet-parse-0.0.5 lib/vendor/puppet/parameter/value.rb
puppet-parse-0.0.4 lib/vendor/puppet/parameter/value.rb
puppet-3.0.2 lib/puppet/parameter/value.rb
puppet-3.0.2.rc3 lib/puppet/parameter/value.rb
puppet-3.0.2.rc2 lib/puppet/parameter/value.rb
puppet-3.0.2.rc1 lib/puppet/parameter/value.rb
puppet-parse-0.0.2 lib/vendor/puppet/parameter/value.rb
puppet-2.7.20 lib/puppet/parameter/value.rb