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
1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 |
# File 'lib/puppet/pops/types/types.rb', line 1969 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.
1936 1937 1938 1939 1940 1941 |
# File 'lib/puppet/pops/types/types.rb', line 1936 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
1943 1944 1945 1946 1947 1948 1949 |
# File 'lib/puppet/pops/types/types.rb', line 1943 def generalize if self == DATA self else super end end |
#instance?(o, guard = nil) ⇒ Boolean
1959 1960 1961 1962 1963 1964 1965 |
# File 'lib/puppet/pops/types/types.rb', line 1959 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 |