class Puppet::Pops::Types::PBooleanType

@api public

Constants

DEFAULT
FALSE
TRUE

Attributes

value[R]

Public Class Methods

new(value = nil) click to toggle source
     # File lib/puppet/pops/types/types.rb
1849 def initialize(value = nil)
1850   @value = value
1851 end
new_function(type) click to toggle source
     # File lib/puppet/pops/types/types.rb
1869 def self.new_function(type)
1870   @new_function ||= Puppet::Functions.create_loaded_function(:new_boolean, type.loader) do
1871     dispatch :from_args do
1872       param "Variant[Integer, Float, Boolean, Enum['false','true','yes','no','y','n',true]]",  :from
1873     end
1874 
1875     argument_mismatch :on_error do
1876       param  'Any', :from
1877     end
1878 
1879     def from_args(from)
1880       from = from.downcase if from.is_a?(String)
1881       case from
1882       when Float
1883         from != 0.0
1884       when Integer
1885         from != 0
1886       when false, 'false', 'no', 'n'
1887         false
1888       else
1889         true
1890       end
1891     end
1892 
1893     def on_error(from)
1894       if from.is_a?(String)
1895         _("The string '%{str}' cannot be converted to Boolean") % { str: from }
1896       else
1897         t = TypeCalculator.singleton.infer(from).generalize
1898         _("Value of type %{type} cannot be converted to Boolean") % { type: t }
1899       end
1900     end
1901   end
1902 end
register_ptype(loader, ir) click to toggle source
     # File lib/puppet/pops/types/types.rb
1843 def self.register_ptype(loader, ir)
1844   create_ptype(loader, ir, 'ScalarDataType')
1845 end

Public Instance Methods

eql?(o) click to toggle source
     # File lib/puppet/pops/types/types.rb
1853 def eql?(o)
1854   o.is_a?(PBooleanType) && @value == o.value
1855 end
from_args(from) click to toggle source
     # File lib/puppet/pops/types/types.rb
1879 def from_args(from)
1880   from = from.downcase if from.is_a?(String)
1881   case from
1882   when Float
1883     from != 0.0
1884   when Integer
1885     from != 0
1886   when false, 'false', 'no', 'n'
1887     false
1888   else
1889     true
1890   end
1891 end
generalize() click to toggle source
     # File lib/puppet/pops/types/types.rb
1857 def generalize
1858   PBooleanType::DEFAULT
1859 end
hash() click to toggle source
     # File lib/puppet/pops/types/types.rb
1861 def hash
1862   31 ^ @value.hash
1863 end
instance?(o, guard = nil) click to toggle source
     # File lib/puppet/pops/types/types.rb
1865 def instance?(o, guard = nil)
1866   (o == true || o == false) && (@value.nil? || value == o)
1867 end
on_error(from) click to toggle source
     # File lib/puppet/pops/types/types.rb
1893 def on_error(from)
1894   if from.is_a?(String)
1895     _("The string '%{str}' cannot be converted to Boolean") % { str: from }
1896   else
1897     t = TypeCalculator.singleton.infer(from).generalize
1898     _("Value of type %{type} cannot be converted to Boolean") % { type: t }
1899   end
1900 end

Protected Instance Methods

_assignable?(o, guard) click to toggle source

@api private

     # File lib/puppet/pops/types/types.rb
1912 def _assignable?(o, guard)
1913   o.is_a?(PBooleanType) && (@value.nil? || @value == o.value)
1914 end