Class: Puppet::Pops::Types::PArrayType
- Inherits:
-
PCollectionType
- Object
- TypedModelObject
- PAnyType
- PCollectionType
- Puppet::Pops::Types::PArrayType
- Defined in:
- lib/puppet/pops/types/types.rb
Constant Summary collapse
- DATA =
PArrayType.new(PDataType::DEFAULT, DEFAULT_SIZE)
- DEFAULT =
PArrayType.new(nil)
- EMPTY =
PArrayType.new(PUnitType::DEFAULT, ZERO_SIZE)
Constants inherited from PCollectionType
Puppet::Pops::Types::PCollectionType::DEFAULT_SIZE, Puppet::Pops::Types::PCollectionType::ZERO_SIZE
Instance Attribute Summary
Attributes inherited from PCollectionType
Class Method Summary collapse
-
.new_function(_, loader) ⇒ Object
Returns a new function that produces an Array.
Instance Method Summary collapse
- #callable_args?(callable, guard = nil) ⇒ Boolean private
- #generalize ⇒ Object
- #instance?(o, guard = nil) ⇒ Boolean
- #normalize(guard = nil) ⇒ Object
Methods inherited from PCollectionType
#accept, #eql?, #has_empty_range?, #hash, #initialize, #iterable?, #iterable_type, #size_range
Methods inherited from PAnyType
#==, #accept, #assignable?, #callable?, #check_self_recursion, #eql?, #hash, #iterable?, #iterable_type, #kind_of_callable?, #name, #new_function, #really_instance?, #resolve, #simple_name, #to_alias_expanded_s, #to_s
Methods included from Visitable
Constructor Details
This class inherits a constructor from Puppet::Pops::Types::PCollectionType
Class Method Details
.new_function(_, loader) ⇒ Object
Returns a new function that produces an Array
1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 |
# File 'lib/puppet/pops/types/types.rb', line 1949 def self.new_function(_, loader) @new_function ||= Puppet::Functions.create_loaded_function(:new_array, loader) do dispatch :from_args do param 'Any', :from optional_param 'Boolean', :wrap end def from_args(from, wrap = false) case from when NilClass if wrap [nil] else throw :undefined_value end when Array from when Hash wrap ? [from] : from.to_a else if wrap [from] else if PIterableType::DEFAULT.instance?(from) Iterable.on(from).to_a else t = Puppet::Pops::Types::TypeCalculator.singleton.infer(from).generalize raise TypeConversionError.new("Value of type '#{t}' cannot be converted to Array") end end end end end end |
Instance Method Details
#callable_args?(callable, 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.
1916 1917 1918 1919 1920 1921 |
# File 'lib/puppet/pops/types/types.rb', line 1916 def callable_args?(callable, guard = nil) param_t = callable.param_types block_t = callable.block_type # does not support calling with a block, but have to check that callable is ok with missing block (param_t.nil? || param_t.assignable?(self, guard)) && (block_t.nil? || block_t.assignable(PUndefType::DEFAULT, guard)) end |
#generalize ⇒ Object
1923 1924 1925 1926 1927 1928 1929 |
# File 'lib/puppet/pops/types/types.rb', line 1923 def generalize if self == DATA self else super end end |
#instance?(o, guard = nil) ⇒ Boolean
1939 1940 1941 1942 1943 1944 1945 |
# File 'lib/puppet/pops/types/types.rb', line 1939 def instance?(o, guard = nil) return false unless o.is_a?(Array) element_t = element_type return false unless element_t.nil? || o.all? {|element| element_t.instance?(element, guard) } size_t = size_type size_t.nil? || size_t.instance?(o.size, guard) end |