Class: Puppet::Pops::Types::PURIType Private
- Inherits:
-
PAnyType
- Object
- TypedModelObject
- PAnyType
- Puppet::Pops::Types::PURIType
- 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'.freeze
- 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'.freeze
- 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'.freeze
- 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'.freeze
- 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'.freeze
- 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'.freeze
- 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'.freeze
- 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'.freeze
- 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
- #parameters ⇒ Object readonly private
Class Method Summary collapse
- .new_function(type) ⇒ Object private
- .register_ptype(loader, ir) ⇒ Object private
Instance Method Summary collapse
- #==(o) ⇒ Object private
- #[](key) ⇒ Object private
- #_pcore_init_hash ⇒ Object private
- #eql?(o) ⇒ Boolean private
- #generalize ⇒ Object private
- #hash ⇒ Object private
-
#initialize(parameters = nil) ⇒ PURIType
constructor
private
A new instance of PURIType.
- #instance?(o, guard = nil) ⇒ Boolean private
- #roundtrip_with_string? ⇒ Boolean private
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
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.
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/puppet/pops/types/p_uri_type.rb', line 101 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
#parameters ⇒ Object (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.
99 100 101 |
# File 'lib/puppet/pops/types/p_uri_type.rb', line 99 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.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/puppet/pops/types/p_uri_type.rb', line 75 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.
67 68 69 70 71 72 73 |
# File 'lib/puppet/pops/types/p_uri_type.rb', line 67 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.
117 118 119 |
# File 'lib/puppet/pops/types/p_uri_type.rb', line 117 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.
121 122 123 |
# File 'lib/puppet/pops/types/p_uri_type.rb', line 121 def [](key) URI_MEMBERS[key] end |
#_pcore_init_hash ⇒ 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.
145 146 147 |
# File 'lib/puppet/pops/types/p_uri_type.rb', line 145 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.
113 114 115 |
# File 'lib/puppet/pops/types/p_uri_type.rb', line 113 def eql?(o) self.class == o.class && @parameters == o.parameters end |
#generalize ⇒ 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.
125 126 127 |
# File 'lib/puppet/pops/types/p_uri_type.rb', line 125 def generalize DEFAULT end |
#hash ⇒ 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.
129 130 131 |
# File 'lib/puppet/pops/types/p_uri_type.rb', line 129 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.
133 134 135 136 137 138 139 |
# File 'lib/puppet/pops/types/p_uri_type.rb', line 133 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.
141 142 143 |
# File 'lib/puppet/pops/types/p_uri_type.rb', line 141 def roundtrip_with_string? true end |