Class: Puppet::Pops::Evaluator::CompareOperator
- Includes:
- Runtime3Support, Utils
- Defined in:
- lib/puppet/pops/evaluator/compare_operator.rb
Overview
Compares the puppet DSL way
Equality
All string vs. numeric equalities check for numeric equality first, then string equality Arrays are equal to arrays if they have the same length, and each element #equals Hashes are equal to hashes if they have the same size and keys and values #equals. All other objects are equal if they are ruby #== equal
Constant Summary
Constants included from Runtime3Support
Runtime3Support::CLASS_STRING, Runtime3Support::NAME_SPACE_SEPARATOR
Instance Method Summary collapse
-
#compare(a, b) ⇒ Object
Performs a comparison of a and b, and return > 0 if a is bigger, 0 if equal, and < 0 if b is bigger.
- #equals(a, b) ⇒ Object
-
#include?(a, b, scope) ⇒ Boolean
Answers is b included in a.
-
#initialize ⇒ CompareOperator
constructor
A new instance of CompareOperator.
-
#match(a, b, scope) ⇒ Object
Performs a match of a and b, and returns true if b matches a.
Methods included from Runtime3Support
#add_relationship, #call_function, #capitalize_qualified_name, #coerce_numeric, #convert, #create_local_scope_from, #create_match_scope_from, #create_resource_defaults, #create_resource_overrides, #create_resource_parameter, #create_resources, #diagnostic_producer, #external_call_function, #extract_file_line, #fail, #find_closest_positioned, #find_resource, #get_resource_parameter_value, #get_scope_nesting_level, #get_variable_value, #is_boolean?, #is_parameter_of_resource?, #is_true?, #optionally_fail, #resource_to_ptype, #set_match_data, #set_scope_nesting_level, #set_variable, #variable_bound?, #variable_exists?
Methods included from Utils
find_adapter, find_closest_positioned, is_absolute?, is_numeric?, match_to_fp, name_to_segments, relativize_name, to_n, to_n_with_radix
Constructor Details
#initialize ⇒ CompareOperator
Returns a new instance of CompareOperator.
17 18 19 20 21 22 23 |
# File 'lib/puppet/pops/evaluator/compare_operator.rb', line 17 def initialize @@equals_visitor ||= Puppet::Pops::Visitor.new(self, "equals", 1, 1) @@compare_visitor ||= Puppet::Pops::Visitor.new(self, "cmp", 1, 1) @@match_visitor ||= Puppet::Pops::Visitor.new(self, "match", 2, 2) @@include_visitor ||= Puppet::Pops::Visitor.new(self, "include", 2, 2) @type_calculator = Puppet::Pops::Types::TypeCalculator.new() end |
Instance Method Details
#compare(a, b) ⇒ Object
Performs a comparison of a and b, and return > 0 if a is bigger, 0 if equal, and < 0 if b is bigger. Comparison of String vs. Numeric always compares using numeric.
31 32 33 |
# File 'lib/puppet/pops/evaluator/compare_operator.rb', line 31 def compare(a, b) @@compare_visitor.visit_this_1(self, a, b) end |
#equals(a, b) ⇒ Object
25 26 27 |
# File 'lib/puppet/pops/evaluator/compare_operator.rb', line 25 def equals (a, b) @@equals_visitor.visit_this_1(self, a, b) end |
#include?(a, b, scope) ⇒ Boolean
Answers is b included in a
41 42 43 |
# File 'lib/puppet/pops/evaluator/compare_operator.rb', line 41 def include?(a, b, scope) @@include_visitor.visit_this_2(self, a, b, scope) end |
#match(a, b, scope) ⇒ Object
Performs a match of a and b, and returns true if b matches a
36 37 38 |
# File 'lib/puppet/pops/evaluator/compare_operator.rb', line 36 def match(a, b, scope) @@match_visitor.visit_this_2(self, b, a, scope) end |