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

Inherits:
PScalarType 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 PAnyType

#==, #accept, #assignable?, #callable?, #callable_args?, #callable_with?, #check_self_recursion, #create, #eql?, #generalize, #hash, #iterable?, #iterable_type, #kind_of_callable?, #name, #new_function, #normalize, #really_instance?, #resolve, #simple_name, simple_name, #to_alias_expanded_s, #to_s

Methods inherited from TypedModelObject

_ptype, create_ptype, register_ptypes

Methods included from Visitable

#accept

Methods included from PuppetObject

#_ptype

Class Method Details

.new_function(_, loader) ⇒ Object



1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
# File 'lib/puppet/pops/types/types.rb', line 1680

def self.new_function(_, loader)
  @new_function ||= Puppet::Functions.create_loaded_function(:new_boolean, 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



1672
1673
1674
# File 'lib/puppet/pops/types/types.rb', line 1672

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

Instance Method Details

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

Returns:

  • (Boolean)


1676
1677
1678
# File 'lib/puppet/pops/types/types.rb', line 1676

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