Class: Puppet::Pops::Types::PBooleanType

Inherits:
PScalarDataType show all
Defined in:
lib/puppet/pops/types/types.rb

Constant Summary collapse

DEFAULT =
PBooleanType.new

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PScalarType

#roundtrip_with_string?

Methods inherited from PAnyType

#==, #accept, #assignable?, #callable?, #callable_args?, #callable_with?, #check_self_recursion, create, #create, #eql?, #generalize, #hash, #iterable?, #iterable_type, #kind_of_callable?, #loader, #name, #new_function, #normalize, #really_instance?, #resolve, #roundtrip_with_string?, #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_init_hash, #_pcore_type

Class Method Details

.new_function(type) ⇒ Object



1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
# File 'lib/puppet/pops/types/types.rb', line 1787

def self.new_function(type)
  @new_function ||= Puppet::Functions.create_loaded_function(:new_boolean, type.loader) do
    dispatch :from_args do
      param          'Variant[Undef, Integer, Float, Boolean, String]',  :from
    end

    def from_args(from)
      from = from.downcase if from.is_a?(String)
      case from
      when NilClass
        throw :undefined_value
      when Float
        from != 0.0
      when Integer
        from != 0
      when true, false
        from
      when 'false', 'no', 'n'
        false
      when 'true', 'yes', 'y'
        true
      else
        raise TypeConversionError.new("Value '#{from}' of type '#{from.class}' cannot be converted to Boolean")
      end
    end
  end
end

.register_ptype(loader, ir) ⇒ Object



1779
1780
1781
# File 'lib/puppet/pops/types/types.rb', line 1779

def self.register_ptype(loader, ir)
  create_ptype(loader, ir, 'ScalarDataType')
end

Instance Method Details

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

Returns:

  • (Boolean)


1783
1784
1785
# File 'lib/puppet/pops/types/types.rb', line 1783

def instance?(o, guard = nil)
  o == true || o == false
end