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.



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/puppet/pops/types/p_uri_type.rb', line 102

def initialize(parameters = nil)
  if parameters.is_a?(String)
    parameters = TypeAsserter.assert_instance_of('URI-Type parameter', Pcore::TYPE_URI, parameters, true)
    @parameters = uri_to_hash(URI.parse(parameters))
  elsif parameters.is_a?(URI)
    @parameters = uri_to_hash(parameters)
  elsif parameters.is_a?(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.



100
101
102
# File 'lib/puppet/pops/types/p_uri_type.rb', line 100

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.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/puppet/pops/types/p_uri_type.rb', line 76

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.



68
69
70
71
72
73
74
# File 'lib/puppet/pops/types/p_uri_type.rb', line 68

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.



118
119
120
# File 'lib/puppet/pops/types/p_uri_type.rb', line 118

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.



122
123
124
# File 'lib/puppet/pops/types/p_uri_type.rb', line 122

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.



146
147
148
# File 'lib/puppet/pops/types/p_uri_type.rb', line 146

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)


114
115
116
# File 'lib/puppet/pops/types/p_uri_type.rb', line 114

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.



126
127
128
# File 'lib/puppet/pops/types/p_uri_type.rb', line 126

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.



130
131
132
# File 'lib/puppet/pops/types/p_uri_type.rb', line 130

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)


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

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)


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

def roundtrip_with_string?
  true
end