Class: Puppet::Pops::Types::PURIType Private

Inherits:
PAnyType show all
Includes:
TypeWithMembers
Defined in:
lib/puppet/pops/types/p_uri_type.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

SCHEME =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'scheme'
USERINFO =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'userinfo'
HOST =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'host'
PORT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'port'
PATH =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'path'
QUERY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'query'
FRAGMENT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'fragment'
OPAQUE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'opaque'
URI_MEMBERS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  SCHEME => AttrReader.new(SCHEME),
  USERINFO => AttrReader.new(USERINFO),
  HOST => AttrReader.new(HOST),
  PORT => AttrReader.new(PORT),
  PATH => AttrReader.new(PATH),
  QUERY => AttrReader.new(QUERY),
  FRAGMENT => AttrReader.new(FRAGMENT),
  OPAQUE => AttrReader.new(OPAQUE),
}
TYPE_URI_INIT_HASH =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

TypeFactory.struct(
  TypeFactory.optional(SCHEME) => PStringType::NON_EMPTY,
  TypeFactory.optional(USERINFO) => PStringType::NON_EMPTY,
  TypeFactory.optional(HOST) => PStringType::NON_EMPTY,
  TypeFactory.optional(PORT) => PIntegerType.new(0),
  TypeFactory.optional(PATH) => PStringType::NON_EMPTY,
  TypeFactory.optional(QUERY) => PStringType::NON_EMPTY,
  TypeFactory.optional(FRAGMENT) => PStringType::NON_EMPTY,
  TypeFactory.optional(OPAQUE) => PStringType::NON_EMPTY,
)
TYPE_STRING_PARAM =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

TypeFactory
    .optional(PVariantType
        .new([
  PStringType::NON_EMPTY,
  PRegexpType::DEFAULT,
  TypeFactory.type_type(PPatternType::DEFAULT),
  TypeFactory.type_type(PEnumType::DEFAULT),
  TypeFactory.type_type(PNotUndefType::DEFAULT),
  TypeFactory.type_type(PUndefType::DEFAULT),
]))
TYPE_INTEGER_PARAM =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

TypeFactory
    .optional(PVariantType
        .new([
  PIntegerType.new(0),
  TypeFactory.type_type(PNotUndefType::DEFAULT),
  TypeFactory.type_type(PUndefType::DEFAULT),
]))
TYPE_URI_PARAM_HASH_TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

TypeFactory.struct(
  TypeFactory.optional(SCHEME) => TYPE_STRING_PARAM,
  TypeFactory.optional(USERINFO) => TYPE_STRING_PARAM,
  TypeFactory.optional(HOST) => TYPE_STRING_PARAM,
  TypeFactory.optional(PORT) => TYPE_INTEGER_PARAM,
  TypeFactory.optional(PATH) => TYPE_STRING_PARAM,
  TypeFactory.optional(QUERY) => TYPE_STRING_PARAM,
  TypeFactory.optional(FRAGMENT) => TYPE_STRING_PARAM,
  TypeFactory.optional(OPAQUE) => TYPE_STRING_PARAM,
)
TYPE_URI_PARAM_TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

PVariantType.new([PStringType::NON_EMPTY, TYPE_URI_PARAM_HASH_TYPE])

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PAnyType

#accept, #assignable?, #callable?, #callable_args?, #callable_with?, #check_self_recursion, create, #create, #iterable?, #iterable_type, #kind_of_callable?, #loader, #name, #new_function, #normalize, #really_instance?, #resolve, #simple_name, simple_name, #to_alias_expanded_s, #to_s

Methods inherited from TypedModelObject

_pcore_type, create_ptype, register_ptypes

Methods included from Visitable

#accept

Methods included from PuppetObject

#_pcore_all_contents, #_pcore_contents, #_pcore_type, #to_s

Constructor Details

#initialize(parameters = nil) ⇒ PURIType

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of PURIType.



107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/puppet/pops/types/p_uri_type.rb', line 107

def initialize(parameters = nil)
  case parameters
  when String
    parameters = TypeAsserter.assert_instance_of('URI-Type parameter', Pcore::TYPE_URI, parameters, true)
    @parameters = uri_to_hash(URI.parse(parameters))
  when URI
    @parameters = uri_to_hash(parameters)
  when Hash
    params = TypeAsserter.assert_instance_of('URI-Type parameter', TYPE_URI_PARAM_TYPE, parameters, true)
    @parameters = params.empty? ? nil : params
  end
end

Instance Attribute Details

#parametersObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



105
106
107
# File 'lib/puppet/pops/types/p_uri_type.rb', line 105

def parameters
  @parameters
end

Class Method Details

.new_function(type) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/puppet/pops/types/p_uri_type.rb', line 81

def self.new_function(type)
  @new_function ||= Puppet::Functions.create_loaded_function(:new_error, type.loader) do
    dispatch :create do
      param 'String[1]', :uri
    end

    dispatch :from_hash do
      param TYPE_URI_INIT_HASH, :hash
    end

    def create(uri)
      URI.parse(uri)
    end

    def from_hash(init_hash)
      sym_hash = {}
      init_hash.each_pair { |k, v| sym_hash[k.to_sym] = v }
      scheme = sym_hash[:scheme]
      scheme_class = scheme.nil? ? URI::Generic : (URI.scheme_list[scheme.upcase] || URI::Generic)
      scheme_class.build(sym_hash)
    end
  end
end

.register_ptype(loader, ir) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



74
75
76
77
78
79
# File 'lib/puppet/pops/types/p_uri_type.rb', line 74

def self.register_ptype(loader, ir)
  create_ptype(loader, ir, 'AnyType',
               {
                 'parameters' => { KEY_TYPE => TypeFactory.optional(TYPE_URI_PARAM_TYPE), KEY_VALUE => nil }
               })
end

Instance Method Details

#==(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



124
125
126
# File 'lib/puppet/pops/types/p_uri_type.rb', line 124

def ==(o)
  eql?(o)
end

#[](key) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



128
129
130
# File 'lib/puppet/pops/types/p_uri_type.rb', line 128

def [](key)
  URI_MEMBERS[key]
end

#_pcore_init_hashObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



152
153
154
# File 'lib/puppet/pops/types/p_uri_type.rb', line 152

def _pcore_init_hash
  @parameters == nil? ? EMPTY_HASH : { 'parameters' => @parameters }
end

#eql?(o) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


120
121
122
# File 'lib/puppet/pops/types/p_uri_type.rb', line 120

def eql?(o)
  self.class == o.class && @parameters == o.parameters
end

#generalizeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



132
133
134
# File 'lib/puppet/pops/types/p_uri_type.rb', line 132

def generalize
  DEFAULT
end

#hashObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



136
137
138
# File 'lib/puppet/pops/types/p_uri_type.rb', line 136

def hash
  self.class.hash ^ @parameters.hash
end

#instance?(o, guard = nil) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


140
141
142
143
144
145
146
# File 'lib/puppet/pops/types/p_uri_type.rb', line 140

def instance?(o, guard = nil)
  return false unless o.is_a?(URI)
  return true if @parameters.nil?

  eval = Parser::EvaluatingParser.singleton.evaluator
  @parameters.keys.all? { |pn| eval.match?(o.send(pn), @parameters[pn]) }
end

#roundtrip_with_string?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


148
149
150
# File 'lib/puppet/pops/types/p_uri_type.rb', line 148

def roundtrip_with_string?
  true
end