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

Public Instance Methods

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

Protected Instance Methods

_assignable?(o, guard) click to toggle source

@api private

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