Browse Source

Import of plugin's code

Change-Id: Ic773558145bd86d46f02151644f1dc435c7b23c2
changes/28/486928/5
Danila Troschinsky 1 year ago
parent
commit
983230fe86
100 changed files with 5757 additions and 0 deletions
  1. 71
    0
      README.md
  2. 22
    0
      deployment_scripts/puppet/files/embedded/bin/check-cpu.rb
  3. 22
    0
      deployment_scripts/puppet/files/embedded/bin/check-influxdb-query.rb
  4. 22
    0
      deployment_scripts/puppet/files/embedded/bin/check-influxdb.rb
  5. 22
    0
      deployment_scripts/puppet/files/embedded/bin/jsonpath
  6. 22
    0
      deployment_scripts/puppet/files/embedded/bin/metrics-cpu-mpstat.rb
  7. 22
    0
      deployment_scripts/puppet/files/embedded/bin/metrics-cpu-pcnt-usage.rb
  8. 22
    0
      deployment_scripts/puppet/files/embedded/bin/metrics-cpu.rb
  9. 22
    0
      deployment_scripts/puppet/files/embedded/bin/metrics-influxdb.rb
  10. 22
    0
      deployment_scripts/puppet/files/embedded/bin/metrics-numastat.rb
  11. 22
    0
      deployment_scripts/puppet/files/embedded/bin/metrics-user-pct-usage.rb
  12. 22
    0
      deployment_scripts/puppet/files/embedded/bin/mutator-influxdb-line-protocol.rb
  13. 19
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/LICENCE.MIT
  14. 32
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/README.md
  15. 17
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/cause.gemspec
  16. 12
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/lib/cause.rb
  17. 11
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.gitignore
  18. 2
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.pryrc
  19. 13
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.travis.yml
  20. 141
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/CHANGELOG.md
  21. 9
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/Gemfile
  22. 297
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/README.md
  23. 28
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/Rakefile
  24. 27
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/dentaku.gemspec
  25. 43
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku.rb
  26. 21
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast.rb
  27. 129
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/arithmetic.rb
  28. 52
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case.rb
  29. 23
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_conditional.rb
  30. 21
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_else.rb
  31. 21
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_switch_variable.rb
  32. 21
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_then.rb
  33. 21
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_when.rb
  34. 36
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/combinators.rb
  35. 51
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/comparators.rb
  36. 73
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/function.rb
  37. 30
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/if.rb
  38. 5
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/max.rb
  39. 5
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/min.rb
  40. 5
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/not.rb
  41. 5
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/round.rb
  42. 7
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/rounddown.rb
  43. 7
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/roundup.rb
  44. 8
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/ruby_math.rb
  45. 111
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/string_functions.rb
  46. 21
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/grouping.rb
  47. 36
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/identifier.rb
  48. 20
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/literal.rb
  49. 8
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/logical.rb
  50. 40
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/negation.rb
  51. 9
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/nil.rb
  52. 17
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/node.rb
  53. 8
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/numeric.rb
  54. 22
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/operation.rb
  55. 8
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/string.rb
  56. 99
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/bulk_expression_solver.rb
  57. 124
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/calculator.rb
  58. 24
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/dependency_resolver.rb
  59. 25
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/exceptions.rb
  60. 222
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/parser.rb
  61. 32
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token.rb
  62. 137
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_matcher.rb
  63. 29
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_matchers.rb
  64. 142
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_scanner.rb
  65. 54
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/tokenizer.rb
  66. 3
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/version.rb
  67. 29
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/addition_spec.rb
  68. 32
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/and_spec.rb
  69. 80
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/case_spec.rb
  70. 29
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/division_spec.rb
  71. 21
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/function_spec.rb
  72. 40
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/node_spec.rb
  73. 16
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/numeric_spec.rb
  74. 135
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/ast/string_functions_spec.rb
  75. 70
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/benchmark.rb
  76. 77
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/bulk_expression_solver_spec.rb
  77. 450
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/calculator_spec.rb
  78. 22
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/dentaku_spec.rb
  79. 9
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/exceptions_spec.rb
  80. 56
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/external_function_spec.rb
  81. 150
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/parser_spec.rb
  82. 41
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/spec_helper.rb
  83. 135
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_matcher_spec.rb
  84. 53
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_scanner_spec.rb
  85. 10
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/token_spec.rb
  86. 212
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/spec/tokenizer_spec.rb
  87. 23
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.gitignore
  88. 35
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.rubocop.yml
  89. 52
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/.travis.yml
  90. 125
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/CHANGELOG.md
  91. 14
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/Gemfile
  92. 22
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/LICENSE.txt
  93. 687
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/README.md
  94. 51
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/Rakefile
  95. 30
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/influxdb.gemspec
  96. 19
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb.rb
  97. 82
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/client.rb
  98. 134
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/client/http.rb
  99. 120
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/config.rb
  100. 0
    0
      deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/influxdb-0.3.13/lib/influxdb/errors.rb

+ 71
- 0
README.md View File

@@ -0,0 +1,71 @@
1
+Sensu plugin for Fuel
2
+=================================
3
+
4
+Overview
5
+--------
6
+
7
+Sensu plugin for Fuel extends Mirantis OpenStack functionality by adding
8
+Sensu monitoring. It can be deployed on hosts with Stacklight plugins roles.
9
+Sensu plugin is 100% hot-pluggable.
10
+
11
+
12
+Compatible Fuel versions
13
+------------------------
14
+
15
+9.0
16
+
17
+
18
+User Guide
19
+----------
20
+
21
+1. Create an environment or open existing. In case of new environment select new nodes
22
+   with LMA Stacklights roles
23
+2. Enable the plugin on the Settings/Other tab of the Fuel web UI and fill in form
24
+    fields:
25
+   * in development
26
+
27
+3. Deploy the environment.
28
+
29
+
30
+Installation Guide
31
+==================
32
+
33
+Sensu Plugin for Fuel installation
34
+----------------------------------------------
35
+
36
+To install Sensu plugin, follow these steps:
37
+
38
+1. Download the plugin
39
+    git clone https://github.com/openstack/fuel-plugin-sensu
40
+
41
+2. Copy the plugin on already installed Fuel Master node; ssh can be used for
42
+    that. If you do not have the Fuel Master node yet, see
43
+    [Quick Start Guide](https://software.mirantis.com/quick-start/):
44
+
45
+        # scp fuel-plugin-sensu-0.1.1-1.noarch.rpm root@<Fuel_master_ip>:/tmp
46
+
47
+3. Log into the Fuel Master node. Install the plugin:
48
+
49
+        # cd /tmp
50
+        # fuel plugins --install fuel-plugin-sensu-0.1.1-1.noarch.rpm
51
+
52
+4. Check if the plugin was installed successfully:
53
+
54
+        # fuel plugins
55
+        id | name                            | version | package_version
56
+        ---|---------------------------------|---------|----------------
57
+        1  | fuel-plugin-sensu   | 0.1.1  | 4.0.0
58
+
59
+
60
+Requirements
61
+------------
62
+
63
+| Requirement                      | Version/Comment |
64
+|:---------------------------------|:----------------|
65
+| Mirantis OpenStack compatibility | 9.0             |
66
+
67
+
68
+Limitations
69
+-----------
70
+
71
+This plugin can be used only with Stacklight LMA nodes

+ 22
- 0
deployment_scripts/puppet/files/embedded/bin/check-cpu.rb View File

@@ -0,0 +1,22 @@
1
+#!/opt/sensu/embedded/bin/ruby
2
+#
3
+# This file was generated by RubyGems.
4
+#
5
+# The application 'sensu-plugins-cpu-checks' is installed as part of a gem, and
6
+# this file is here to facilitate running it.
7
+#
8
+
9
+require 'rubygems'
10
+
11
+version = ">= 0.a"
12
+
13
+if ARGV.first
14
+  str = ARGV.first
15
+  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
16
+  if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
17
+    version = $1
18
+    ARGV.shift
19
+  end
20
+end
21
+
22
+load Gem.activate_bin_path('sensu-plugins-cpu-checks', 'check-cpu.rb', version)

+ 22
- 0
deployment_scripts/puppet/files/embedded/bin/check-influxdb-query.rb View File

@@ -0,0 +1,22 @@
1
+#!/opt/sensu/embedded/bin/ruby
2
+#
3
+# This file was generated by RubyGems.
4
+#
5
+# The application 'sensu-plugins-influxdb' is installed as part of a gem, and
6
+# this file is here to facilitate running it.
7
+#
8
+
9
+require 'rubygems'
10
+
11
+version = ">= 0.a"
12
+
13
+if ARGV.first
14
+  str = ARGV.first
15
+  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
16
+  if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
17
+    version = $1
18
+    ARGV.shift
19
+  end
20
+end
21
+
22
+load Gem.activate_bin_path('sensu-plugins-influxdb', 'check-influxdb-query.rb', version)

+ 22
- 0
deployment_scripts/puppet/files/embedded/bin/check-influxdb.rb View File

@@ -0,0 +1,22 @@
1
+#!/opt/sensu/embedded/bin/ruby
2
+#
3
+# This file was generated by RubyGems.
4
+#
5
+# The application 'sensu-plugins-influxdb' is installed as part of a gem, and
6
+# this file is here to facilitate running it.
7
+#
8
+
9
+require 'rubygems'
10
+
11
+version = ">= 0.a"
12
+
13
+if ARGV.first
14
+  str = ARGV.first
15
+  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
16
+  if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
17
+    version = $1
18
+    ARGV.shift
19
+  end
20
+end
21
+
22
+load Gem.activate_bin_path('sensu-plugins-influxdb', 'check-influxdb.rb', version)

+ 22
- 0
deployment_scripts/puppet/files/embedded/bin/jsonpath View File

@@ -0,0 +1,22 @@
1
+#!/opt/sensu/embedded/bin/ruby
2
+#
3
+# This file was generated by RubyGems.
4
+#
5
+# The application 'jsonpath' is installed as part of a gem, and
6
+# this file is here to facilitate running it.
7
+#
8
+
9
+require 'rubygems'
10
+
11
+version = ">= 0.a"
12
+
13
+if ARGV.first
14
+  str = ARGV.first
15
+  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
16
+  if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
17
+    version = $1
18
+    ARGV.shift
19
+  end
20
+end
21
+
22
+load Gem.activate_bin_path('jsonpath', 'jsonpath', version)

+ 22
- 0
deployment_scripts/puppet/files/embedded/bin/metrics-cpu-mpstat.rb View File

@@ -0,0 +1,22 @@
1
+#!/opt/sensu/embedded/bin/ruby
2
+#
3
+# This file was generated by RubyGems.
4
+#
5
+# The application 'sensu-plugins-cpu-checks' is installed as part of a gem, and
6
+# this file is here to facilitate running it.
7
+#
8
+
9
+require 'rubygems'
10
+
11
+version = ">= 0.a"
12
+
13
+if ARGV.first
14
+  str = ARGV.first
15
+  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
16
+  if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
17
+    version = $1
18
+    ARGV.shift
19
+  end
20
+end
21
+
22
+load Gem.activate_bin_path('sensu-plugins-cpu-checks', 'metrics-cpu-mpstat.rb', version)

+ 22
- 0
deployment_scripts/puppet/files/embedded/bin/metrics-cpu-pcnt-usage.rb View File

@@ -0,0 +1,22 @@
1
+#!/opt/sensu/embedded/bin/ruby
2
+#
3
+# This file was generated by RubyGems.
4
+#
5
+# The application 'sensu-plugins-cpu-checks' is installed as part of a gem, and
6
+# this file is here to facilitate running it.
7
+#
8
+
9
+require 'rubygems'
10
+
11
+version = ">= 0.a"
12
+
13
+if ARGV.first
14
+  str = ARGV.first
15
+  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
16
+  if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
17
+    version = $1
18
+    ARGV.shift
19
+  end
20
+end
21
+
22
+load Gem.activate_bin_path('sensu-plugins-cpu-checks', 'metrics-cpu-pcnt-usage.rb', version)

+ 22
- 0
deployment_scripts/puppet/files/embedded/bin/metrics-cpu.rb View File

@@ -0,0 +1,22 @@
1
+#!/opt/sensu/embedded/bin/ruby
2
+#
3
+# This file was generated by RubyGems.
4
+#
5
+# The application 'sensu-plugins-cpu-checks' is installed as part of a gem, and
6
+# this file is here to facilitate running it.
7
+#
8
+
9
+require 'rubygems'
10
+
11
+version = ">= 0.a"
12
+
13
+if ARGV.first
14
+  str = ARGV.first
15
+  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
16
+  if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
17
+    version = $1
18
+    ARGV.shift
19
+  end
20
+end
21
+
22
+load Gem.activate_bin_path('sensu-plugins-cpu-checks', 'metrics-cpu.rb', version)

+ 22
- 0
deployment_scripts/puppet/files/embedded/bin/metrics-influxdb.rb View File

@@ -0,0 +1,22 @@
1
+#!/opt/sensu/embedded/bin/ruby
2
+#
3
+# This file was generated by RubyGems.
4
+#
5
+# The application 'sensu-plugins-influxdb' is installed as part of a gem, and
6
+# this file is here to facilitate running it.
7
+#
8
+
9
+require 'rubygems'
10
+
11
+version = ">= 0.a"
12
+
13
+if ARGV.first
14
+  str = ARGV.first
15
+  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
16
+  if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
17
+    version = $1
18
+    ARGV.shift
19
+  end
20
+end
21
+
22
+load Gem.activate_bin_path('sensu-plugins-influxdb', 'metrics-influxdb.rb', version)

+ 22
- 0
deployment_scripts/puppet/files/embedded/bin/metrics-numastat.rb View File

@@ -0,0 +1,22 @@
1
+#!/opt/sensu/embedded/bin/ruby
2
+#
3
+# This file was generated by RubyGems.
4
+#
5
+# The application 'sensu-plugins-cpu-checks' is installed as part of a gem, and
6
+# this file is here to facilitate running it.
7
+#
8
+
9
+require 'rubygems'
10
+
11
+version = ">= 0.a"
12
+
13
+if ARGV.first
14
+  str = ARGV.first
15
+  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
16
+  if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
17
+    version = $1
18
+    ARGV.shift
19
+  end
20
+end
21
+
22
+load Gem.activate_bin_path('sensu-plugins-cpu-checks', 'metrics-numastat.rb', version)

+ 22
- 0
deployment_scripts/puppet/files/embedded/bin/metrics-user-pct-usage.rb View File

@@ -0,0 +1,22 @@
1
+#!/opt/sensu/embedded/bin/ruby
2
+#
3
+# This file was generated by RubyGems.
4
+#
5
+# The application 'sensu-plugins-cpu-checks' is installed as part of a gem, and
6
+# this file is here to facilitate running it.
7
+#
8
+
9
+require 'rubygems'
10
+
11
+version = ">= 0.a"
12
+
13
+if ARGV.first
14
+  str = ARGV.first
15
+  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
16
+  if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
17
+    version = $1
18
+    ARGV.shift
19
+  end
20
+end
21
+
22
+load Gem.activate_bin_path('sensu-plugins-cpu-checks', 'metrics-user-pct-usage.rb', version)

+ 22
- 0
deployment_scripts/puppet/files/embedded/bin/mutator-influxdb-line-protocol.rb View File

@@ -0,0 +1,22 @@
1
+#!/opt/sensu/embedded/bin/ruby
2
+#
3
+# This file was generated by RubyGems.
4
+#
5
+# The application 'sensu-plugins-influxdb' is installed as part of a gem, and
6
+# this file is here to facilitate running it.
7
+#
8
+
9
+require 'rubygems'
10
+
11
+version = ">= 0.a"
12
+
13
+if ARGV.first
14
+  str = ARGV.first
15
+  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
16
+  if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
17
+    version = $1
18
+    ARGV.shift
19
+  end
20
+end
21
+
22
+load Gem.activate_bin_path('sensu-plugins-influxdb', 'mutator-influxdb-line-protocol.rb', version)

+ 19
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/LICENCE.MIT View File

@@ -0,0 +1,19 @@
1
+Copyright (c) 2013 Conrad Irwin <conrad@bugsnag.com>
2
+
3
+Permission is hereby granted, free of charge, to any person obtaining a copy
4
+of this software and associated documentation files (the "Software"), to deal
5
+in the Software without restriction, including without limitation the rights
6
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+copies of the Software, and to permit persons to whom the Software is
8
+furnished to do so, subject to the following conditions:
9
+
10
+The above copyright notice and this permission notice shall be included in
11
+all copies or substantial portions of the Software.
12
+
13
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+THE SOFTWARE.

+ 32
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/README.md View File

@@ -0,0 +1,32 @@
1
+This is a back-port of Ruby 2.1.0's [`Exception#cause`](http://www.ruby-doc.org/core-2.1.0/Exception.html#method-i-cause) to older versions of Ruby.
2
+
3
+Installation
4
+------------
5
+
6
+Add `gem 'cause'` to your `Gemfile`, then run `bundle install`. If you're not
7
+using bundler, then just `gem install cause`.
8
+
9
+Usage
10
+-----
11
+
12
+Just continue programming as normal. When you rescue from exceptions they'll
13
+have a third property, cause, in addition to backtrace and message. The cause
14
+is the exception object that was being handled when the error was raised.
15
+
16
+While this is not directly useful in normal programming, it's very useful for
17
+debugging. Exception trackers like [Bugsnag](https://bugsnag.com/) can then pick up
18
+the cause of the exception to help you find out what went wrong.
19
+
20
+Limitations
21
+-----------
22
+
23
+At the moment you cannot set the cause yourself.  Overriding `raise` is hairy
24
+business and I wrote this gem late at night, but with sufficient care it's
25
+probably doable.
26
+
27
+Meta-fu
28
+-------
29
+
30
+This gem is Copyright under the MIT licence. See LICENCE.MIT for details.
31
+
32
+Contributions and bug-reports are welcome.

+ 17
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/cause.gemspec View File

@@ -0,0 +1,17 @@
1
+Gem::Specification.new do |gem|
2
+  gem.name = 'cause'
3
+  gem.version = '0.1'
4
+
5
+  gem.summary = 'A backport of Exception#cause from Ruby 2.1.0'
6
+  gem.description = "Allows you access to the error that was being handled when this exception was raised."
7
+
8
+  gem.authors = ['Conrad Irwin']
9
+  gem.email = %w(conrad@bugsnag.com)
10
+  gem.homepage = 'http://github.com/ConradIrwin/cause'
11
+
12
+  gem.license = 'MIT'
13
+
14
+  gem.required_ruby_version = '>= 1.8.7'
15
+
16
+  gem.files = `git ls-files`.split("\n")
17
+end

+ 12
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/cause-0.1/lib/cause.rb View File

@@ -0,0 +1,12 @@
1
+class Exception
2
+  unless method_defined?(:cause)
3
+    attr_reader :cause
4
+
5
+    alias old_initialize initialize
6
+
7
+    def initialize(*a)
8
+      @cause = $!
9
+      old_initialize(*a)
10
+    end
11
+  end
12
+end

+ 11
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.gitignore View File

@@ -0,0 +1,11 @@
1
+*.gem
2
+.bundle
3
+.rbenv-version
4
+Gemfile.lock
5
+bin/*
6
+pkg/*
7
+vendor/*
8
+
9
+/.ruby-gemset
10
+/.ruby-version
11
+/.rspec

+ 2
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.pryrc View File

@@ -0,0 +1,2 @@
1
+require "bundler"
2
+Bundler.require

+ 13
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/.travis.yml View File

@@ -0,0 +1,13 @@
1
+language: ruby
2
+sudo: false
3
+rvm:
4
+  - 1.9.3
5
+  - 2.0.0
6
+  - 2.1.0
7
+  - 2.1.1
8
+  - 2.2.0
9
+  - 2.2.1
10
+  - 2.2.2
11
+  - 2.2.3
12
+  - 2.3.0
13
+  - rbx-2

+ 141
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/CHANGELOG.md View File

@@ -0,0 +1,141 @@
1
+# Change Log
2
+
3
+## [v2.0.9] 2016-09-19
4
+- namespace tokenization errors
5
+- automatically coerce arguments to string functions as strings
6
+- selectively disable or clear AST cache
7
+
8
+## [v2.0.8] 2016-05-10
9
+- numeric input validations
10
+- fail with gem-specific error for invalid arithmetic operands
11
+- add `LEFT`, `RIGHT`, `MID`, `LEN`, `FIND`, `SUBSTITUTE`, and `CONCAT` string functions
12
+
13
+## [v2.0.7] 2016-02-25
14
+- fail with gem-specific error for parsing issues
15
+- support NULL literals and nil variables
16
+- keep reference to variable that caused failure when bulk-solving
17
+
18
+## [v2.0.6] 2016-01-26
19
+- support array parameters for external functions
20
+- support case statements
21
+- support precision for `ROUNDUP` and `ROUNDDOWN` functions
22
+- prevent errors from corrupting calculator memory
23
+
24
+## [v2.0.5] 2015-09-03
25
+- fix bug with detecting unbound nodes
26
+- silence warnings
27
+- allow registration of custom token scanners
28
+
29
+## [v2.0.4] 2015-09-03
30
+- fix BigDecimal conversion bug
31
+- add caching for bulk expression solving dependency order
32
+- allow for custom configuration for token scanners
33
+
34
+## [v2.0.3] 2015-08-25
35
+- bug fixes
36
+- performance enhancements
37
+- code cleanup
38
+
39
+## [v2.0.1] 2015-08-15
40
+- add support for boolean literals
41
+- implement basic parse-time type checking
42
+
43
+## [v2.0.0] 2015-08-07
44
+- shunting-yard parser for performance enhancement and AST generation
45
+- AST caching for performance enhancement
46
+- support comments in formulas
47
+- support all functions from the Ruby Math module
48
+
49
+## [v1.2.6] 2015-05-30
50
+- support custom error handlers for systems of formulas
51
+
52
+## [v1.2.5] 2015-05-23
53
+- fix memory leak
54
+
55
+## [v1.2.2] 2014-12-19
56
+- performance enhancements
57
+- unary minus bug fixes
58
+- preserve provided hash keys for systems of formulas
59
+
60
+## [v1.2.0] 2014-10-21
61
+- add dependency resolution to automatically solve systems of formulas
62
+
63
+## [v1.1.0] 2014-07-30
64
+- add strict evaluation mode to raise `UnboundVariableError` if not all variable values are provided
65
+- return division results as `BigDecimal` values
66
+
67
+## [v1.0.0] 2014-03-06
68
+- cleanup and 1.0 release
69
+
70
+## [v0.2.14] 2014-01-24
71
+- add modulo operator
72
+- add unary percentage operator
73
+- support registration of custom functions at runtime
74
+
75
+## [v0.2.10] 2012-12-10
76
+- return integer result for exact division, decimal otherwise
77
+
78
+## [v0.2.9] 2012-10-17
79
+- add `ROUNDUP` / `ROUNDDOWN` functions
80
+
81
+## [v0.2.8] 2012-09-30
82
+- make function name matching case-insensitive
83
+
84
+## [v0.2.7] 2012-09-26
85
+- support passing arbitrary expressions as function arguments
86
+
87
+## [v0.2.6] 2012-09-19
88
+- add `NOT` function
89
+
90
+## [v0.2.5] 2012-06-20
91
+- add exponent operator
92
+- add support for digits in variable identifiers
93
+
94
+## [v0.2.4] 2012-02-29
95
+- add support for `min < x < max` syntax for inequality ranges
96
+
97
+## [v0.2.2] 2012-02-22
98
+- support `ROUND` to arbitrary decimal place on older Rubies
99
+- ensure case is preserved for string values
100
+
101
+## [v0.2.1] 2012-02-12
102
+- add `ROUND` function
103
+
104
+## [v0.1.3] 2012-01-31
105
+- add support for string datatype
106
+
107
+## [v0.1.1] 2012-01-24
108
+- change from square bracket to parentheses for top-level evaluation
109
+- add `IF` function
110
+
111
+## [v0.1.0] 2012-01-20
112
+- initial release
113
+
114
+[v2.0.9]:  https://github.com/rubysolo/dentaku/compare/v2.0.8...v2.0.9
115
+[v2.0.8]:  https://github.com/rubysolo/dentaku/compare/v2.0.7...v2.0.8
116
+[v2.0.7]:  https://github.com/rubysolo/dentaku/compare/v2.0.6...v2.0.7
117
+[v2.0.6]:  https://github.com/rubysolo/dentaku/compare/v2.0.5...v2.0.6
118
+[v2.0.5]:  https://github.com/rubysolo/dentaku/compare/v2.0.4...v2.0.5
119
+[v2.0.4]:  https://github.com/rubysolo/dentaku/compare/v2.0.3...v2.0.4
120
+[v2.0.3]:  https://github.com/rubysolo/dentaku/compare/v2.0.1...v2.0.3
121
+[v2.0.1]:  https://github.com/rubysolo/dentaku/compare/v2.0.0...v2.0.1
122
+[v2.0.0]:  https://github.com/rubysolo/dentaku/compare/v1.2.6...v2.0.0
123
+[v1.2.6]:  https://github.com/rubysolo/dentaku/compare/v1.2.5...v1.2.6
124
+[v1.2.5]:  https://github.com/rubysolo/dentaku/compare/v1.2.2...v1.2.5
125
+[v1.2.2]:  https://github.com/rubysolo/dentaku/compare/v1.2.0...v1.2.2
126
+[v1.2.0]:  https://github.com/rubysolo/dentaku/compare/v1.1.0...v1.2.0
127
+[v1.1.0]:  https://github.com/rubysolo/dentaku/compare/v1.0.0...v1.1.0
128
+[v1.0.0]:  https://github.com/rubysolo/dentaku/compare/v0.2.14...v1.0.0
129
+[v0.2.14]: https://github.com/rubysolo/dentaku/compare/v0.2.10...v0.2.14
130
+[v0.2.10]: https://github.com/rubysolo/dentaku/compare/v0.2.9...v0.2.10
131
+[v0.2.9]:  https://github.com/rubysolo/dentaku/compare/v0.2.8...v0.2.9
132
+[v0.2.8]:  https://github.com/rubysolo/dentaku/compare/v0.2.7...v0.2.8
133
+[v0.2.7]:  https://github.com/rubysolo/dentaku/compare/v0.2.6...v0.2.7
134
+[v0.2.6]:  https://github.com/rubysolo/dentaku/compare/v0.2.5...v0.2.6
135
+[v0.2.5]:  https://github.com/rubysolo/dentaku/compare/v0.2.4...v0.2.5
136
+[v0.2.4]:  https://github.com/rubysolo/dentaku/compare/v0.2.2...v0.2.4
137
+[v0.2.2]:  https://github.com/rubysolo/dentaku/compare/v0.2.1...v0.2.2
138
+[v0.2.1]:  https://github.com/rubysolo/dentaku/compare/v0.1.3...v0.2.1
139
+[v0.1.3]:  https://github.com/rubysolo/dentaku/compare/v0.1.1...v0.1.3
140
+[v0.1.1]:  https://github.com/rubysolo/dentaku/compare/v0.1.0...v0.1.1
141
+[v0.1.0]:  https://github.com/rubysolo/dentaku/commit/68724fd9c8fa637baf7b9d5515df0caa31e226bd

+ 9
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/Gemfile View File

@@ -0,0 +1,9 @@
1
+source "http://rubygems.org"
2
+
3
+# Specify your gem's dependencies in dentaku.gemspec
4
+gemspec
5
+
6
+if RUBY_VERSION.to_f >= 2.0 && RUBY_ENGINE == 'ruby'
7
+  gem 'pry-byebug'
8
+  gem 'pry-stack_explorer'
9
+end

+ 297
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/README.md View File

@@ -0,0 +1,297 @@
1
+Dentaku
2
+=======
3
+
4
+[![Join the chat at https://gitter.im/rubysolo/dentaku](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/rubysolo/dentaku?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5
+[![Gem Version](https://badge.fury.io/rb/dentaku.png)](http://badge.fury.io/rb/dentaku)
6
+[![Build Status](https://travis-ci.org/rubysolo/dentaku.png?branch=master)](https://travis-ci.org/rubysolo/dentaku)
7
+[![Code Climate](https://codeclimate.com/github/rubysolo/dentaku.png)](https://codeclimate.com/github/rubysolo/dentaku)
8
+[![Hakiri](https://hakiri.io/github/rubysolo/dentaku/master.svg)](https://hakiri.io/github/rubysolo/dentaku)
9
+
10
+DESCRIPTION
11
+-----------
12
+
13
+Dentaku is a parser and evaluator for a mathematical and logical formula
14
+language that allows run-time binding of values to variables referenced in the
15
+formulas.  It is intended to safely evaluate untrusted expressions without
16
+opening security holes.
17
+
18
+EXAMPLE
19
+-------
20
+
21
+This is probably simplest to illustrate in code:
22
+
23
+```ruby
24
+calculator = Dentaku::Calculator.new
25
+calculator.evaluate('10 * 2')
26
+#=> 20
27
+```
28
+
29
+Okay, not terribly exciting.  But what if you want to have a reference to a
30
+variable, and evaluate it at run-time?  Here's how that would look:
31
+
32
+```ruby
33
+calculator.evaluate('kiwi + 5', kiwi: 2)
34
+#=> 7
35
+```
36
+
37
+You can also store the variable values in the calculator's memory and then
38
+evaluate expressions against those stored values:
39
+
40
+```ruby
41
+calculator.store(peaches: 15)
42
+calculator.evaluate('peaches - 5')
43
+#=> 10
44
+calculator.evaluate('peaches >= 15')
45
+#=> true
46
+```
47
+
48
+For maximum CS geekery, `bind` is an alias of `store`.
49
+
50
+Dentaku understands precedence order and using parentheses to group expressions
51
+to ensure proper evaluation:
52
+
53
+```ruby
54
+calculator.evaluate('5 + 3 * 2')
55
+#=> 11
56
+calculator.evaluate('(5 + 3) * 2')
57
+#=> 16
58
+```
59
+
60
+The `evaluate` method will return `nil` if there is an error in the formula.
61
+If this is not the desired behavior, use `evaluate!`, which will raise an
62
+exception.
63
+
64
+```ruby
65
+calculator.evaluate('10 * x')
66
+#=> nil
67
+calculator.evaluate!('10 * x')
68
+Dentaku::UnboundVariableError: Dentaku::UnboundVariableError
69
+```
70
+
71
+Dentaku has built-in functions (including `if`, `not`, `min`, `max`, and
72
+`round`) and the ability to define custom functions (see below). Functions
73
+generally work like their counterparts in Excel:
74
+
75
+```ruby
76
+calculator.evaluate('if (pears < 10, 10, 20)', pears: 5)
77
+#=> 10
78
+calculator.evaluate('if (pears < 10, 10, 20)', pears: 15)
79
+#=> 20
80
+```
81
+
82
+`round` can be called with or without the number of decimal places:
83
+
84
+```ruby
85
+calculator.evaluate('round(8.2)')
86
+#=> 8
87
+calculator.evaluate('round(8.2759, 2)')
88
+#=> 8.28
89
+```
90
+
91
+`round` follows rounding rules, while `roundup` and `rounddown` are `ceil` and
92
+`floor`, respectively.
93
+
94
+If you're too lazy to be building calculator objects, there's a shortcut just
95
+for you:
96
+
97
+```ruby
98
+Dentaku('plums * 1.5', plums: 2)
99
+#=> 3.0
100
+```
101
+
102
+PERFORMANCE
103
+-----------
104
+
105
+The flexibility and safety of Dentaku don't come without a price.  Tokenizing a
106
+string, parsing to an AST, and then evaluating that AST are about 2 orders of
107
+magnitude slower than doing the same math in pure Ruby!
108
+
109
+The good news is that most of the time is spent in the tokenization and parsing
110
+phases, so if performance is a concern, you can enable AST caching:
111
+
112
+```ruby
113
+Dentaku.enable_ast_cache!
114
+```
115
+
116
+After this, Dentaku will cache the AST of each formula that it evaluates, so
117
+subsequent evaluations (even with different values for variables) will be much
118
+faster -- closer to 4x native Ruby speed.  As usual, these benchmarks should be
119
+considered rough estimates, and you should measure with representative formulas
120
+from your application.  Also, if new formulas are constantly introduced to your
121
+application, AST caching will consume more memory with each new formula.
122
+
123
+BUILT-IN OPERATORS AND FUNCTIONS
124
+---------------------------------
125
+
126
+Math: `+`, `-`, `*`, `/`, `%`
127
+
128
+Logic: `<`, `>`, `<=`, `>=`, `<>`, `!=`, `=`, `AND`, `OR`
129
+
130
+Functions: `IF`, `NOT`, `MIN`, `MAX`, `ROUND`, `ROUNDDOWN`, `ROUNDUP`
131
+
132
+Selections: `CASE` (syntax see [spec](https://github.com/rubysolo/dentaku/blob/master/spec/calculator_spec.rb#L292))
133
+
134
+Math: all functions from Ruby's Math module, including `SIN`, `COS`, `TAN`, etc.
135
+
136
+String: `LEFT`, `RIGHT`, `MID`, `LEN`, `FIND`, `SUBSTITUTE`, `CONCAT`
137
+
138
+RESOLVING DEPENDENCIES
139
+----------------------
140
+
141
+If your formulas rely on one another, they may need to be resolved in a
142
+particular order. For example:
143
+
144
+```ruby
145
+calc = Dentaku::Calculator.new
146
+calc.store(monthly_income: 50)
147
+need_to_compute = {
148
+  income_taxes: "annual_income / 5",
149
+  annual_income: "monthly_income * 12"
150
+}
151
+```
152
+
153
+In the example, `annual_income` needs to be computed (and stored) before
154
+`income_taxes`.
155
+
156
+Dentaku provides two methods to help resolve formulas in order:
157
+
158
+#### Calculator.dependencies
159
+Pass a (string) expression to Dependencies and get back a list of variables (as
160
+`:symbols`) that are required for the expression. `Dependencies` also takes
161
+into account variables already (explicitly) stored into the calculator.
162
+
163
+```ruby
164
+calc.dependencies("monthly_income * 12")
165
+#=> []
166
+# (since monthly_income is in memory)
167
+
168
+calc.dependencies("annual_income / 5")
169
+#=> [:annual_income]
170
+```
171
+
172
+#### Calculator.solve! / Calculator.solve
173
+Have Dentaku figure out the order in which your formulas need to be evaluated.
174
+
175
+Pass in a hash of `{eventual_variable_name: "expression"}` to `solve!` and
176
+have Dentaku resolve dependencies (using `TSort`) for you.
177
+
178
+Raises `TSort::Cyclic` when a valid expression order cannot be found.
179
+
180
+```ruby
181
+calc = Dentaku::Calculator.new
182
+calc.store(monthly_income: 50)
183
+need_to_compute = {
184
+  income_taxes:  "annual_income / 5",
185
+  annual_income: "monthly_income * 12"
186
+}
187
+calc.solve!(need_to_compute)
188
+#=> {annual_income: 600, income_taxes: 120}
189
+
190
+calc.solve!(
191
+  make_money: "have_money",
192
+  have_money: "make_money"
193
+}
194
+#=> raises TSort::Cyclic
195
+```
196
+
197
+`solve!` will also raise an exception if any of the formulas in the set cannot
198
+be evaluated (e.g. raise `ZeroDivisionError`).  The non-bang `solve` method will
199
+find as many solutions as possible and return the symbol `:undefined` for the
200
+problem formulas.
201
+
202
+INLINE COMMENTS
203
+---------------------------------
204
+
205
+If your expressions grow long or complex, you may add inline comments for future
206
+reference. This is particularly useful if you save your expressions in a model.
207
+
208
+```ruby
209
+calculator.evaluate('kiwi + 5 /* This is a comment */', kiwi: 2)
210
+#=> 7
211
+```
212
+
213
+Comments can be single or multi-line. The following are also valid.
214
+
215
+```
216
+/*
217
+ * This is a multi-line comment
218
+ */
219
+
220
+/*
221
+ This is another type of multi-line comment
222
+ */
223
+```
224
+
225
+EXTERNAL FUNCTIONS
226
+------------------
227
+
228
+I don't know everything, so I might not have implemented all the functions you
229
+need.  Please implement your favorites and send a pull request!  Okay, so maybe
230
+that's not feasible because:
231
+
232
+1. You can't be bothered to share
233
+1. You can't wait for me to respond to a pull request, you need it `NOW()`
234
+1. The formula is the secret sauce for your startup
235
+
236
+Whatever your reasons, Dentaku supports adding functions at runtime.  To add a
237
+function, you'll need to specify a name, a return type, and a lambda that
238
+accepts all function arguments and returns the result value.
239
+
240
+Here's an example of adding a function named `POW` that implements
241
+exponentiation.
242
+
243
+```ruby
244
+> c = Dentaku::Calculator.new
245
+> c.add_function(:pow, :numeric, ->(mantissa, exponent) { mantissa ** exponent })
246
+> c.evaluate('POW(3,2)')
247
+#=> 9
248
+> c.evaluate('POW(2,3)')
249
+#=> 8
250
+```
251
+
252
+Here's an example of adding a variadic function:
253
+
254
+```ruby
255
+> c = Dentaku::Calculator.new
256
+> c.add_function(:max, :numeric, ->(*args) { args.max })
257
+> c.evaluate 'MAX(8,6,7,5,3,0,9)'
258
+#=> 9
259
+```
260
+
261
+(However both of these are already built-in -- the `^` operator and the `MAX`
262
+function)
263
+
264
+Functions can be added individually using Calculator#add_function, or en masse
265
+using Calculator#add_functions.
266
+
267
+THANKS
268
+------
269
+
270
+Big thanks to [ElkStone Basements](http://www.elkstonebasements.com/) for
271
+allowing me to extract and open source this code.  Thanks also to all the
272
+[contributors](https://github.com/rubysolo/dentaku/graphs/contributors)!
273
+
274
+
275
+LICENSE
276
+-------
277
+
278
+(The MIT License)
279
+
280
+Copyright © 2012-2016 Solomon White
281
+
282
+Permission is hereby granted, free of charge, to any person obtaining a copy of
283
+this software and associated documentation files (the ‘Software’), to deal in
284
+the Software without restriction, including without limitation the rights to
285
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
286
+the Software, and to permit persons to whom the Software is furnished to do so,
287
+subject to the following conditions:
288
+
289
+The above copyright notice and this permission notice shall be included in all
290
+copies or substantial portions of the Software.
291
+
292
+THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
293
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
294
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
295
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
296
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
297
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 28
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/Rakefile View File

@@ -0,0 +1,28 @@
1
+require 'bundler/gem_tasks'
2
+require 'rspec/core/rake_task'
3
+
4
+desc "Run specs"
5
+task :spec do
6
+  RSpec::Core::RakeTask.new(:spec) do |t|
7
+    t.rspec_opts = %w{--colour --format progress}
8
+    t.pattern = 'spec/**/*_spec.rb'
9
+  end
10
+end
11
+
12
+desc "Default: run specs."
13
+task default: :spec
14
+
15
+task :console do
16
+  begin
17
+    require 'pry'
18
+    console = Pry
19
+  rescue LoadError
20
+    require 'irb'
21
+    require 'irb/completion'
22
+    console = IRB
23
+  end
24
+
25
+  require 'dentaku'
26
+  ARGV.clear
27
+  console.start
28
+end

+ 27
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/dentaku.gemspec View File

@@ -0,0 +1,27 @@
1
+# -*- encoding: utf-8 -*-
2
+$:.push File.expand_path("../lib", __FILE__)
3
+require "dentaku/version"
4
+
5
+Gem::Specification.new do |s|
6
+  s.name        = "dentaku"
7
+  s.version     = Dentaku::VERSION
8
+  s.authors     = ["Solomon White"]
9
+  s.email       = ["rubysolo@gmail.com"]
10
+  s.homepage    = "http://github.com/rubysolo/dentaku"
11
+  s.licenses    = %w(MIT)
12
+  s.summary     = %q{A formula language parser and evaluator}
13
+  s.description = <<-DESC
14
+    Dentaku is a parser and evaluator for mathematical formulas
15
+  DESC
16
+
17
+  s.rubyforge_project = "dentaku"
18
+
19
+  s.add_development_dependency('rake')
20
+  s.add_development_dependency('rspec')
21
+  s.add_development_dependency('pry')
22
+
23
+  s.files         = `git ls-files`.split("\n")
24
+  s.test_files    = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+  s.executables   = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
26
+  s.require_paths = ["lib"]
27
+end

+ 43
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku.rb View File

@@ -0,0 +1,43 @@
1
+require "bigdecimal"
2
+require "dentaku/calculator"
3
+require "dentaku/version"
4
+
5
+module Dentaku
6
+  @enable_ast_caching = false
7
+  @enable_dependency_order_caching = false
8
+
9
+  def self.evaluate(expression, data={})
10
+    calculator.evaluate(expression, data)
11
+  end
12
+
13
+  def self.enable_caching!
14
+    enable_ast_cache!
15
+    enable_dependency_order_cache!
16
+  end
17
+
18
+  def self.enable_ast_cache!
19
+    @enable_ast_caching = true
20
+  end
21
+
22
+  def self.cache_ast?
23
+    @enable_ast_caching
24
+  end
25
+
26
+  def self.enable_dependency_order_cache!
27
+    @enable_dependency_order_caching = true
28
+  end
29
+
30
+  def self.cache_dependency_order?
31
+    @enable_dependency_order_caching
32
+  end
33
+
34
+  private
35
+
36
+  def self.calculator
37
+    @calculator ||= Dentaku::Calculator.new
38
+  end
39
+end
40
+
41
+def Dentaku(expression, data={})
42
+  Dentaku.evaluate(expression, data)
43
+end

+ 21
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast.rb View File

@@ -0,0 +1,21 @@
1
+require_relative './ast/node'
2
+require_relative './ast/nil'
3
+require_relative './ast/numeric'
4
+require_relative './ast/logical'
5
+require_relative './ast/string'
6
+require_relative './ast/identifier'
7
+require_relative './ast/arithmetic'
8
+require_relative './ast/negation'
9
+require_relative './ast/comparators'
10
+require_relative './ast/combinators'
11
+require_relative './ast/grouping'
12
+require_relative './ast/case'
13
+require_relative './ast/functions/if'
14
+require_relative './ast/functions/max'
15
+require_relative './ast/functions/min'
16
+require_relative './ast/functions/not'
17
+require_relative './ast/functions/round'
18
+require_relative './ast/functions/roundup'
19
+require_relative './ast/functions/rounddown'
20
+require_relative './ast/functions/ruby_math'
21
+require_relative './ast/functions/string_functions'

+ 129
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/arithmetic.rb View File

@@ -0,0 +1,129 @@
1
+require_relative './operation'
2
+require 'bigdecimal'
3
+require 'bigdecimal/util'
4
+
5
+module Dentaku
6
+  module AST
7
+    class Arithmetic < Operation
8
+      def initialize(*)
9
+        super
10
+        unless valid_node?(left) && valid_node?(right)
11
+          fail ParseError, "#{ self.class } requires numeric operands"
12
+        end
13
+      end
14
+
15
+      def type
16
+        :numeric
17
+      end
18
+
19
+      def value(context={})
20
+        l = cast(left.value(context))
21
+        r = cast(right.value(context))
22
+        l.public_send(operator, r)
23
+      end
24
+
25
+      private
26
+
27
+      def cast(value, prefer_integer=true)
28
+        validate_numeric(value)
29
+        v = BigDecimal.new(value, Float::DIG+1)
30
+        v = v.to_i if prefer_integer && v.frac.zero?
31
+        v
32
+      end
33
+
34
+      def valid_node?(node)
35
+        node && (node.dependencies.any? || node.type == :numeric)
36
+      end
37
+
38
+      def validate_numeric(value)
39
+        Float(value)
40
+      rescue ::ArgumentError, ::TypeError
41
+        fail Dentaku::ArgumentError, "#{ self.class } requires numeric operands"
42
+      end
43
+    end
44
+
45
+    class Addition < Arithmetic
46
+      def operator
47
+        :+
48
+      end
49
+
50
+      def self.precedence
51
+        10
52
+      end
53
+    end
54
+
55
+    class Subtraction < Arithmetic
56
+      def operator
57
+        :-
58
+      end
59
+
60
+      def self.precedence
61
+        10
62
+      end
63
+    end
64
+
65
+    class Multiplication < Arithmetic
66
+      def operator
67
+        :*
68
+      end
69
+
70
+      def self.precedence
71
+        20
72
+      end
73
+    end
74
+
75
+    class Division < Arithmetic
76
+      def value(context={})
77
+        r = cast(right.value(context), false)
78
+        raise Dentaku::ZeroDivisionError if r.zero?
79
+
80
+        cast(cast(left.value(context)) / r)
81
+      end
82
+
83
+      def self.precedence
84
+        20
85
+      end
86
+    end
87
+
88
+    class Modulo < Arithmetic
89
+      def initialize(left, right)
90
+        @left  = left
91
+        @right = right
92
+
93
+        unless (valid_node?(left) || left.nil?) && valid_node?(right)
94
+          fail ParseError, "#{ self.class } requires numeric operands"
95
+        end
96
+      end
97
+
98
+      def percent?
99
+        left.nil?
100
+      end
101
+
102
+      def value(context={})
103
+        if percent?
104
+          cast(right.value(context)) * 0.01
105
+        else
106
+          super
107
+        end
108
+      end
109
+
110
+      def operator
111
+        :%
112
+      end
113
+
114
+      def self.precedence
115
+        20
116
+      end
117
+    end
118
+
119
+    class Exponentiation < Arithmetic
120
+      def operator
121
+        :**
122
+      end
123
+
124
+      def self.precedence
125
+        30
126
+      end
127
+    end
128
+  end
129
+end

+ 52
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case.rb View File

@@ -0,0 +1,52 @@
1
+require_relative './case/case_conditional'
2
+require_relative './case/case_when'
3
+require_relative './case/case_then'
4
+require_relative './case/case_switch_variable'
5
+require_relative './case/case_else'
6
+
7
+module Dentaku
8
+  module AST
9
+    class Case < Node
10
+      def initialize(*nodes)
11
+        @switch = nodes.shift
12
+
13
+        unless @switch.is_a?(AST::CaseSwitchVariable)
14
+          raise 'Case missing switch variable'
15
+        end
16
+
17
+        @conditions = nodes
18
+
19
+        @else = @conditions.pop if @conditions.last.is_a?(AST::CaseElse)
20
+
21
+        @conditions.each do |condition|
22
+          unless condition.is_a?(AST::CaseConditional)
23
+            raise "#{condition} is not a CaseConditional"
24
+          end
25
+        end
26
+      end
27
+
28
+      def value(context={})
29
+        switch_value = @switch.value(context)
30
+        @conditions.each do |condition|
31
+          if condition.when.value(context) == switch_value
32
+            return condition.then.value(context)
33
+          end
34
+        end
35
+
36
+        if @else
37
+          return @else.value(context)
38
+        else
39
+          raise "No block matched the switch value '#{switch_value}'"
40
+        end
41
+      end
42
+
43
+      def dependencies(context={})
44
+        # TODO: should short-circuit
45
+        @switch.dependencies(context) +
46
+          @conditions.flat_map do |condition|
47
+            condition.dependencies(context)
48
+          end
49
+      end
50
+    end
51
+  end
52
+end

+ 23
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_conditional.rb View File

@@ -0,0 +1,23 @@
1
+module Dentaku
2
+  module AST
3
+    class CaseConditional < Node
4
+      attr_reader :when,
5
+                  :then
6
+
7
+      def initialize(when_statement, then_statement)
8
+        @when = when_statement
9
+        unless @when.is_a?(AST::CaseWhen)
10
+          raise 'Expected first argument to be a CaseWhen'
11
+        end
12
+        @then = then_statement
13
+        unless @then.is_a?(AST::CaseThen)
14
+          raise 'Expected second argument to be a CaseThen'
15
+        end
16
+      end
17
+
18
+      def dependencies(context={})
19
+        @when.dependencies(context) + @then.dependencies(context)
20
+      end
21
+    end
22
+  end
23
+end

+ 21
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_else.rb View File

@@ -0,0 +1,21 @@
1
+module Dentaku
2
+  module AST
3
+    class CaseElse < Node
4
+      def self.arity
5
+        1
6
+      end
7
+
8
+      def initialize(node)
9
+        @node = node
10
+      end
11
+
12
+      def value(context={})
13
+        @node.value(context)
14
+      end
15
+
16
+      def dependencies(context={})
17
+        @node.dependencies(context)
18
+      end
19
+    end
20
+  end
21
+end

+ 21
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_switch_variable.rb View File

@@ -0,0 +1,21 @@
1
+module Dentaku
2
+  module AST
3
+    class CaseSwitchVariable < Node
4
+      def initialize(node)
5
+        @node = node
6
+      end
7
+
8
+      def value(context={})
9
+        @node.value(context)
10
+      end
11
+
12
+      def dependencies(context={})
13
+        @node.dependencies(context)
14
+      end
15
+
16
+      def self.arity
17
+        1
18
+      end
19
+    end
20
+  end
21
+end

+ 21
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_then.rb View File

@@ -0,0 +1,21 @@
1
+module Dentaku
2
+  module AST
3
+    class CaseThen < Node
4
+      def self.arity
5
+        1
6
+      end
7
+
8
+      def initialize(node)
9
+        @node = node
10
+      end
11
+
12
+      def value(context={})
13
+        @node.value(context)
14
+      end
15
+
16
+      def dependencies(context={})
17
+        @node.dependencies(context)
18
+      end
19
+    end
20
+  end
21
+end

+ 21
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/case/case_when.rb View File

@@ -0,0 +1,21 @@
1
+module Dentaku
2
+  module AST
3
+    class CaseWhen < Operation
4
+      def self.arity
5
+        1
6
+      end
7
+
8
+      def initialize(node)
9
+        @node = node
10
+      end
11
+
12
+      def value(context={})
13
+        @node.value(context)
14
+      end
15
+
16
+      def dependencies(context={})
17
+        @node.dependencies(context)
18
+      end
19
+    end
20
+  end
21
+end

+ 36
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/combinators.rb View File

@@ -0,0 +1,36 @@
1
+require_relative './operation'
2
+
3
+module Dentaku
4
+  module AST
5
+    class Combinator < Operation
6
+      def initialize(*)
7
+        super
8
+        unless valid_node?(left) && valid_node?(right)
9
+          fail ParseError, "#{ self.class } requires logical operands"
10
+        end
11
+      end
12
+
13
+      def type
14
+        :logical
15
+      end
16
+
17
+      private
18
+
19
+      def valid_node?(node)
20
+        node.dependencies.any? || node.type == :logical
21
+      end
22
+    end
23
+
24
+    class And < Combinator
25
+      def value(context={})
26
+        left.value(context) && right.value(context)
27
+      end
28
+    end
29
+
30
+    class Or < Combinator
31
+      def value(context={})
32
+        left.value(context) || right.value(context)
33
+      end
34
+    end
35
+  end
36
+end

+ 51
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/comparators.rb View File

@@ -0,0 +1,51 @@
1
+require_relative './operation'
2
+
3
+module Dentaku
4
+  module AST
5
+    class Comparator < Operation
6
+      def self.precedence
7
+        5
8
+      end
9
+
10
+      def type
11
+        :logical
12
+      end
13
+    end
14
+
15
+    class LessThan < Comparator
16
+      def value(context={})
17
+        left.value(context) < right.value(context)
18
+      end
19
+    end
20
+
21
+    class LessThanOrEqual < Comparator
22
+      def value(context={})
23
+        left.value(context) <= right.value(context)
24
+      end
25
+    end
26
+
27
+    class GreaterThan < Comparator
28
+      def value(context={})
29
+        left.value(context) > right.value(context)
30
+      end
31
+    end
32
+
33
+    class GreaterThanOrEqual < Comparator
34
+      def value(context={})
35
+        left.value(context) >= right.value(context)
36
+      end
37
+    end
38
+
39
+    class NotEqual < Comparator
40
+      def value(context={})
41
+        left.value(context) != right.value(context)
42
+      end
43
+    end
44
+
45
+    class Equal < Comparator
46
+      def value(context={})
47
+        left.value(context) == right.value(context)
48
+      end
49
+    end
50
+  end
51
+end

+ 73
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/function.rb View File

@@ -0,0 +1,73 @@
1
+require_relative 'node'
2
+
3
+module Dentaku
4
+  module AST
5
+    class Function < Node
6
+      def initialize(*args)
7
+        @args = args
8
+      end
9
+
10
+      def dependencies(context={})
11
+        @args.flat_map { |a| a.dependencies(context) }
12
+      end
13
+
14
+      def self.get(name)
15
+        registry.fetch(function_name(name)) {
16
+          fail ParseError, "Undefined function #{ name }"
17
+        }
18
+      end
19
+
20
+      def self.register(name, type, implementation)
21
+        function = Class.new(self) do
22
+          def self.implementation=(impl)
23
+            @implementation = impl
24
+          end
25
+
26
+          def self.implementation
27
+            @implementation
28
+          end
29
+
30
+          def self.type=(type)
31
+            @type = type
32
+          end
33
+
34
+          def self.type
35
+            @type
36
+          end
37
+
38
+          def value(context={})
39
+            args = @args.map { |a| a.value(context) }
40
+            self.class.implementation.call(*args)
41
+          end
42
+
43
+          def type
44
+            self.class.type
45
+          end
46
+        end
47
+
48
+        function_class = name.to_s.capitalize
49
+        Dentaku::AST.send(:remove_const, function_class) if Dentaku::AST.const_defined?(function_class)
50
+        Dentaku::AST.const_set(function_class, function)
51
+
52
+        function.implementation = implementation
53
+        function.type = type
54
+
55
+        registry[function_name(name)] = function
56
+      end
57
+
58
+      def self.register_class(name, function_class)
59
+        registry[function_name(name)] = function_class
60
+      end
61
+
62
+      private
63
+
64
+      def self.function_name(name)
65
+        name.to_s.downcase
66
+      end
67
+
68
+      def self.registry
69
+        @registry ||= {}
70
+      end
71
+    end
72
+  end
73
+end

+ 30
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/if.rb View File

@@ -0,0 +1,30 @@
1
+require_relative '../function'
2
+
3
+module Dentaku
4
+  module AST
5
+    class If < Function
6
+      attr_reader :predicate, :left, :right
7
+
8
+      def initialize(predicate, left, right)
9
+        @predicate = predicate
10
+        @left      = left
11
+        @right     = right
12
+      end
13
+
14
+      def value(context={})
15
+        predicate.value(context) ? left.value(context) : right.value(context)
16
+      end
17
+
18
+      def type
19
+        left.type
20
+      end
21
+
22
+      def dependencies(context={})
23
+        # TODO : short-circuit?
24
+        (predicate.dependencies(context) + left.dependencies(context) + right.dependencies(context)).uniq
25
+      end
26
+    end
27
+  end
28
+end
29
+
30
+Dentaku::AST::Function.register_class(:if, Dentaku::AST::If)

+ 5
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/max.rb View File

@@ -0,0 +1,5 @@
1
+require_relative '../function'
2
+
3
+Dentaku::AST::Function.register(:max, :numeric, ->(*args) {
4
+  args.max
5
+})

+ 5
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/min.rb View File

@@ -0,0 +1,5 @@
1
+require_relative '../function'
2
+
3
+Dentaku::AST::Function.register(:min, :numeric, ->(*args) {
4
+  args.min
5
+})

+ 5
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/not.rb View File

@@ -0,0 +1,5 @@
1
+require_relative '../function'
2
+
3
+Dentaku::AST::Function.register(:not, :logical, ->(logical) {
4
+  ! logical
5
+})

+ 5
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/round.rb View File

@@ -0,0 +1,5 @@
1
+require_relative '../function'
2
+
3
+Dentaku::AST::Function.register(:round, :numeric, ->(numeric, places=nil) {
4
+  numeric.round(places || 0)
5
+})

+ 7
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/rounddown.rb View File

@@ -0,0 +1,7 @@
1
+require_relative '../function'
2
+
3
+Dentaku::AST::Function.register(:rounddown, :numeric, ->(numeric, precision=0) {
4
+  tens = 10.0**precision
5
+  result = (numeric * tens).floor / tens
6
+  precision <= 0 ? result.to_i : result
7
+})

+ 7
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/roundup.rb View File

@@ -0,0 +1,7 @@
1
+require_relative '../function'
2
+
3
+Dentaku::AST::Function.register(:roundup, :numeric, ->(numeric, precision=0) {
4
+  tens = 10.0**precision
5
+  result = (numeric * tens).ceil / tens
6
+  precision <= 0 ? result.to_i : result
7
+})

+ 8
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/ruby_math.rb View File

@@ -0,0 +1,8 @@
1
+# import all functions from Ruby's Math module
2
+require_relative "../function"
3
+
4
+Math.methods(false).each do |method|
5
+  Dentaku::AST::Function.register(method, :numeric, ->(*args) {
6
+    Math.send(method, *args)
7
+  })
8
+end

+ 111
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/functions/string_functions.rb View File

@@ -0,0 +1,111 @@
1
+require_relative '../function'
2
+
3
+module Dentaku
4
+  module AST
5
+    module StringFunctions
6
+      class Left < Function
7
+        def initialize(string, length)
8
+          @string = string
9
+          @length = length
10
+        end
11
+
12
+        def value(context={})
13
+          string = @string.value(context).to_s
14
+          length = @length.value(context)
15
+          string[0, length]
16
+        end
17
+      end
18
+
19
+      class Right < Function
20
+        def initialize(string, length)
21
+          @string = string
22
+          @length = length
23
+        end
24
+
25
+        def value(context={})
26
+          string = @string.value(context).to_s
27
+          length = @length.value(context)
28
+          string[length * -1, length] || string
29
+        end
30
+      end
31
+
32
+      class Mid < Function
33
+        def initialize(string, offset, length)
34
+          @string = string
35
+          @offset = offset
36
+          @length = length
37
+        end
38
+
39
+        def value(context={})
40
+          string = @string.value(context).to_s
41
+          offset = @offset.value(context)
42
+          length = @length.value(context)
43
+          string[offset - 1, length].to_s
44
+        end
45
+      end
46
+
47
+      class Len < Function
48
+        def initialize(string)
49
+          @string = string
50
+        end
51
+
52
+        def value(context={})
53
+          string = @string.value(context).to_s
54
+          string.length
55
+        end
56
+      end
57
+
58
+      class Find < Function
59
+        def initialize(needle, haystack)
60
+          @needle = needle
61
+          @haystack = haystack
62
+        end
63
+
64
+        def value(context={})
65
+          needle = @needle.value(context)
66
+          needle = needle.to_s unless needle.is_a?(Regexp)
67
+          haystack = @haystack.value(context).to_s
68
+          pos = haystack.index(needle)
69
+          pos && pos + 1
70
+        end
71
+      end
72
+
73
+      class Substitute < Function
74
+        def initialize(original, search, replacement)
75
+          @original = original
76
+          @search = search
77
+          @replacement = replacement
78
+        end
79
+
80
+        def value(context={})
81
+          original = @original.value(context).to_s
82
+          search = @search.value(context)
83
+          search = search.to_s unless search.is_a?(Regexp)
84
+          replacement = @replacement.value(context).to_s
85
+          original.sub(search, replacement)
86
+        end
87
+      end
88
+
89
+      class Concat < Function
90
+        def initialize(left, right)
91
+          @left  = left
92
+          @right = right
93
+        end
94
+
95
+        def value(context={})
96
+          left = @left.value(context).to_s
97
+          right = @right.value(context).to_s
98
+          left + right
99
+        end
100
+      end
101
+    end
102
+  end
103
+end
104
+
105
+Dentaku::AST::Function.register_class(:left,       Dentaku::AST::StringFunctions::Left)
106
+Dentaku::AST::Function.register_class(:right,      Dentaku::AST::StringFunctions::Right)
107
+Dentaku::AST::Function.register_class(:mid,        Dentaku::AST::StringFunctions::Mid)
108
+Dentaku::AST::Function.register_class(:len,        Dentaku::AST::StringFunctions::Len)
109
+Dentaku::AST::Function.register_class(:find,       Dentaku::AST::StringFunctions::Find)
110
+Dentaku::AST::Function.register_class(:substitute, Dentaku::AST::StringFunctions::Substitute)
111
+Dentaku::AST::Function.register_class(:concat,     Dentaku::AST::StringFunctions::Concat)

+ 21
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/grouping.rb View File

@@ -0,0 +1,21 @@
1
+module Dentaku
2
+  module AST
3
+    class Grouping
4
+      def initialize(node)
5
+        @node = node
6
+      end
7
+
8
+      def value(context={})
9
+        @node.value(context)
10
+      end
11
+
12
+      def type
13
+        @node.type
14
+      end
15
+
16
+      def dependencies(context={})
17
+        @node.dependencies(context)
18
+      end
19
+    end
20
+  end
21
+end

+ 36
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/identifier.rb View File

@@ -0,0 +1,36 @@
1
+require_relative '../exceptions'
2
+
3
+module Dentaku
4
+  module AST
5
+    class Identifier < Node
6
+      attr_reader :identifier
7
+
8
+      def initialize(token)
9
+        @identifier = token.value.downcase
10
+      end
11
+
12
+      def value(context={})
13
+        v = context.fetch(identifier) do
14
+          raise UnboundVariableError.new([identifier])
15
+        end
16
+
17
+        case v
18
+        when Node
19
+          v.value(context)
20
+        else
21
+          v
22
+        end
23
+      end
24
+
25
+      def dependencies(context={})
26
+        context.has_key?(identifier) ? dependencies_of(context[identifier]) : [identifier]
27
+      end
28
+
29
+      private
30
+
31
+      def dependencies_of(node)
32
+        node.respond_to?(:dependencies) ? node.dependencies : []
33
+      end
34
+    end
35
+  end
36
+end

+ 20
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/literal.rb View File

@@ -0,0 +1,20 @@
1
+module Dentaku
2
+  module AST
3
+    class Literal < Node
4
+      attr_reader :type
5
+
6
+      def initialize(token)
7
+        @value = token.value
8
+        @type  = token.category
9
+      end
10
+
11
+      def value(*)
12
+        @value
13
+      end
14
+
15
+      def dependencies(*)
16
+        []
17
+      end
18
+    end
19
+  end
20
+end

+ 8
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/logical.rb View File

@@ -0,0 +1,8 @@
1
+require_relative "./literal"
2
+
3
+module Dentaku
4
+  module AST
5
+    class Logical < Literal
6
+    end
7
+  end
8
+end

+ 40
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/negation.rb View File

@@ -0,0 +1,40 @@
1
+module Dentaku
2
+  module AST
3
+    class Negation < Operation
4
+      def initialize(node)
5
+        @node = node
6
+        fail ParseError, "Negation requires numeric operand" unless valid_node?(node)
7
+      end
8
+
9
+      def value(context={})
10
+        @node.value(context) * -1
11
+      end
12
+
13
+      def type
14
+        :numeric
15
+      end
16
+
17
+      def self.arity
18
+        1
19
+      end
20
+
21
+      def self.right_associative?
22
+        true
23
+      end
24
+
25
+      def self.precedence
26
+        40
27
+      end
28
+
29
+      def dependencies(context={})
30
+        @node.dependencies(context)
31
+      end
32
+
33
+      private
34
+
35
+      def valid_node?(node)
36
+        node && (node.dependencies.any? || node.type == :numeric)
37
+      end
38
+    end
39
+  end
40
+end

+ 9
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/nil.rb View File

@@ -0,0 +1,9 @@
1
+module Dentaku
2
+  module AST
3
+    class Nil < Node
4
+      def value(*)
5
+        nil
6
+      end
7
+    end
8
+  end
9
+end

+ 17
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/node.rb View File

@@ -0,0 +1,17 @@
1
+module Dentaku
2
+  module AST
3
+    class Node
4
+      def self.precedence
5
+        0
6
+      end
7
+
8
+      def self.arity
9
+        nil
10
+      end
11
+
12
+      def dependencies(context={})
13
+        []
14
+      end
15
+    end
16
+  end
17
+end

+ 8
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/numeric.rb View File

@@ -0,0 +1,8 @@
1
+require_relative "./literal"
2
+
3
+module Dentaku
4
+  module AST
5
+    class Numeric < Literal
6
+    end
7
+  end
8
+end

+ 22
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/operation.rb View File

@@ -0,0 +1,22 @@
1
+require_relative './node'
2
+
3
+module Dentaku
4
+  module AST
5
+    class Operation < Node
6
+      attr_reader :left, :right
7
+
8
+      def initialize(left, right)
9
+        @left  = left
10
+        @right = right
11
+      end
12
+
13
+      def dependencies(context={})
14
+        (left.dependencies(context) + right.dependencies(context)).uniq
15
+      end
16
+
17
+      def self.right_associative?
18
+        false
19
+      end
20
+    end
21
+  end
22
+end

+ 8
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/ast/string.rb View File

@@ -0,0 +1,8 @@
1
+require_relative "./literal"
2
+
3
+module Dentaku
4
+  module AST
5
+    class String < Literal
6
+    end
7
+  end
8
+end

+ 99
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/bulk_expression_solver.rb View File

@@ -0,0 +1,99 @@
1
+require 'dentaku/calculator'
2
+require 'dentaku/dependency_resolver'
3
+require 'dentaku/exceptions'
4
+require 'dentaku/parser'
5
+require 'dentaku/tokenizer'
6
+
7
+module Dentaku
8
+  class BulkExpressionSolver
9
+    def initialize(expression_hash, calculator)
10
+      self.expression_hash = expression_hash
11
+      self.calculator = calculator
12
+    end
13
+
14
+    def solve!
15
+      solve(&raise_exception_handler)
16
+    end
17
+
18
+    def solve(&block)
19
+      error_handler = block || return_undefined_handler
20
+      results = load_results(&error_handler)
21
+
22
+      expression_hash.each_with_object({}) do |(k, _), r|
23
+        r[k] = results[k.to_s]
24
+      end
25
+    end
26
+
27
+    private
28
+
29
+    def self.dependency_cache
30
+      @dep_cache ||= {}
31
+    end
32
+
33
+    attr_accessor :expression_hash, :calculator
34
+
35
+    def return_undefined_handler
36
+      ->(*) { :undefined }
37
+    end
38
+
39
+    def raise_exception_handler
40
+      ->(ex) { raise ex }
41
+    end
42
+
43
+    def load_results(&block)
44
+      variables_in_resolve_order.each_with_object({}) do |var_name, r|
45
+        begin
46
+          value_from_memory = calculator.memory[var_name]
47
+
48
+          if value_from_memory.nil? &&
49
+              expressions[var_name].nil? &&
50
+              !calculator.memory.has_key?(var_name)
51
+            next
52
+          end
53
+
54
+          value = value_from_memory ||
55
+            evaluate!(expressions[var_name], expressions.merge(r))
56
+
57
+          r[var_name] = value
58
+        rescue Dentaku::UnboundVariableError, ZeroDivisionError => ex
59
+          ex.recipient_variable = var_name
60
+          r[var_name] = block.call(ex)
61
+        end
62
+      end
63
+    end
64
+
65
+    def expressions
66
+      @expressions ||= Hash[expression_hash.map { |k,v| [k.to_s, v] }]
67
+    end
68
+
69
+    def expression_dependencies
70
+      Hash[expressions.map { |var, expr| [var, calculator.dependencies(expr)] }].tap do |d|
71
+        d.values.each do |deps|
72
+          unresolved = deps.reject { |ud| d.has_key?(ud) }
73
+          unresolved.each { |u| add_dependencies(d, u) }
74
+        end
75
+      end
76
+    end
77
+
78
+    def add_dependencies(current_dependencies, variable)
79
+      node = calculator.memory[variable]
80
+      if node.respond_to?(:dependencies)
81
+        current_dependencies[variable] = node.dependencies
82
+        node.dependencies.each { |d| add_dependencies(current_dependencies, d) }
83
+      end
84
+    end
85
+
86
+    def variables_in_resolve_order
87
+      cache_key = expressions.keys.map(&:to_s).sort.join("|")
88
+      @ordered_deps ||= self.class.dependency_cache.fetch(cache_key) {
89
+        DependencyResolver.find_resolve_order(expression_dependencies).tap do |d|
90
+          self.class.dependency_cache[cache_key] = d if Dentaku.cache_dependency_order?
91
+        end
92
+      }
93
+    end
94
+
95
+    def evaluate!(expression, results)
96
+      calculator.evaluate!(expression, results)
97
+    end
98
+  end
99
+end

+ 124
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/calculator.rb View File

@@ -0,0 +1,124 @@
1
+require 'dentaku/bulk_expression_solver'
2
+require 'dentaku/exceptions'
3
+require 'dentaku/token'
4
+require 'dentaku/dependency_resolver'
5
+require 'dentaku/parser'
6
+
7
+module Dentaku
8
+  class Calculator
9
+    attr_reader :result, :memory, :tokenizer
10
+
11
+    def initialize
12
+      clear
13
+      @tokenizer = Tokenizer.new
14
+      @ast_cache = {}
15
+      @disable_ast_cache = false
16
+    end
17
+
18
+    def add_function(name, type, body)
19
+      Dentaku::AST::Function.register(name, type, body)
20
+      self
21
+    end
22
+
23
+    def add_functions(fns)
24
+      fns.each { |(name, type, body)| add_function(name, type, body) }
25
+      self
26
+    end
27
+
28
+    def disable_cache
29
+      @disable_ast_cache = true
30
+      yield(self) if block_given?
31
+    ensure
32
+      @disable_ast_cache = false
33
+    end
34
+
35
+    def evaluate(expression, data={})
36
+      evaluate!(expression, data)
37
+    rescue UnboundVariableError, ArgumentError
38
+      yield expression if block_given?
39
+    end
40
+
41
+    def evaluate!(expression, data={})
42
+      store(data) do
43
+        node = expression
44
+        node = ast(node) unless node.is_a?(AST::Node)
45
+        node.value(memory)
46
+      end
47
+    end
48
+
49
+    def solve!(expression_hash)
50
+      BulkExpressionSolver.new(expression_hash, self).solve!
51
+    end
52
+
53
+    def solve(expression_hash, &block)
54
+      BulkExpressionSolver.new(expression_hash, self).solve(&block)
55
+    end
56
+
57
+    def dependencies(expression)
58
+      ast(expression).dependencies(memory)
59
+    end
60
+
61
+    def ast(expression)
62
+      @ast_cache.fetch(expression) {
63
+        Parser.new(tokenizer.tokenize(expression)).parse.tap do |node|
64
+          @ast_cache[expression] = node if cache_ast?
65
+        end
66
+      }
67
+    end
68
+
69
+    def clear_cache(pattern=:all)
70
+      case pattern
71
+      when :all
72
+        @ast_cache = {}
73
+      when String
74
+        @ast_cache.delete(pattern)
75
+      when Regexp
76
+        @ast_cache.delete_if { |k,_| k =~ pattern }
77
+      else
78
+        fail Dentaku::ArgumentError
79
+      end
80
+    end
81
+
82
+    def store(key_or_hash, value=nil)
83
+      restore = Hash[memory]
84
+
85
+      if value.nil?
86
+        key_or_hash.each do |key, val|
87
+          memory[key.to_s.downcase] = val
88
+        end
89
+      else
90
+        memory[key_or_hash.to_s.downcase] = value
91
+      end
92
+
93
+      if block_given?
94
+        begin
95
+          result = yield
96
+          @memory = restore
97
+          return result
98
+        rescue => e
99
+          @memory = restore
100
+          raise e
101
+        end
102
+      end
103
+
104
+      self
105
+    end
106
+    alias_method :bind, :store
107
+
108
+    def store_formula(key, formula)
109
+      store(key, ast(formula))
110
+    end
111
+
112
+    def clear
113
+      @memory = {}
114
+    end
115
+
116
+    def empty?
117
+      memory.empty?
118
+    end
119
+
120
+    def cache_ast?
121
+      Dentaku.cache_ast? && !@disable_ast_cache
122
+    end
123
+  end
124
+end

+ 24
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/dependency_resolver.rb View File

@@ -0,0 +1,24 @@
1
+require 'tsort'
2
+
3
+module Dentaku
4
+  class DependencyResolver
5
+    include TSort
6
+
7
+    def self.find_resolve_order(vars_to_dependencies_hash)
8
+      self.new(vars_to_dependencies_hash).tsort
9
+    end
10
+
11
+    def initialize(vars_to_dependencies_hash)
12
+      # ensure variables are strings
13
+      @vars_to_deps = Hash[vars_to_dependencies_hash.map { |k, v| [k.to_s, v]}]
14
+    end
15
+
16
+    def tsort_each_node(&block)
17
+      @vars_to_deps.each_key(&block)
18
+    end
19
+
20
+    def tsort_each_child(node, &block)
21
+      @vars_to_deps.fetch(node.to_s, []).each(&block)
22
+    end
23
+  end
24
+end

+ 25
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/exceptions.rb View File

@@ -0,0 +1,25 @@
1
+module Dentaku
2
+  class UnboundVariableError < StandardError
3
+    attr_accessor :recipient_variable
4
+
5
+    attr_reader :unbound_variables
6
+
7
+    def initialize(unbound_variables)
8
+      @unbound_variables = unbound_variables
9
+      super("no value provided for variables: #{ unbound_variables.join(', ') }")
10
+    end
11
+  end
12
+
13
+  class ParseError < StandardError
14
+  end
15
+
16
+  class TokenizerError < StandardError
17
+  end
18
+
19
+  class ArgumentError < ::ArgumentError
20
+  end
21
+
22
+  class ZeroDivisionError < ::ZeroDivisionError
23
+    attr_accessor :recipient_variable
24
+  end
25
+end

+ 222
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/parser.rb View File

@@ -0,0 +1,222 @@
1
+require_relative './ast'
2
+
3
+module Dentaku
4
+  class Parser
5
+    attr_reader :input, :output, :operations, :arities
6
+
7
+    def initialize(tokens, options={})
8
+      @input      = tokens.dup
9
+      @output     = []
10
+      @operations = options.fetch(:operations, [])
11
+      @arities    = options.fetch(:arities, [])
12
+    end
13
+
14
+    def get_args(count)
15
+      Array.new(count) { output.pop }.reverse
16
+    end
17
+
18
+    def consume(count=2)
19
+      operator = operations.pop
20
+      output.push operator.new(*get_args(operator.arity || count))
21
+    end
22
+
23
+    def parse
24
+      return AST::Nil.new if input.empty?
25
+
26
+      while token = input.shift
27
+        case token.category
28
+        when :numeric
29
+          output.push AST::Numeric.new(token)
30
+
31
+        when :logical
32
+          output.push AST::Logical.new(token)
33
+
34
+        when :string
35
+          output.push AST::String.new(token)
36
+
37
+        when :identifier
38
+          output.push AST::Identifier.new(token)
39
+
40
+        when :operator, :comparator, :combinator
41
+          op_class = operation(token)
42
+
43
+          if op_class.right_associative?
44
+            while operations.last && operations.last < AST::Operation && op_class.precedence < operations.last.precedence
45
+              consume
46
+            end
47
+
48
+            operations.push op_class
49
+          else
50
+            while operations.last && operations.last < AST::Operation && op_class.precedence <= operations.last.precedence
51
+              consume
52
+            end
53
+
54
+            operations.push op_class
55
+          end
56
+
57
+        when :null
58
+          output.push AST::Nil.new
59
+
60
+        when :function
61
+          arities.push 0
62
+          operations.push function(token)
63
+
64
+        when :case
65
+          case token.value
66
+          when :open
67
+            # special handling for case nesting: strip out inner case
68
+            # statements and parse their AST segments recursively
69
+            if operations.include?(AST::Case)
70
+              last_case_close_index = nil
71
+              first_nested_case_close_index = nil
72
+              input.each_with_index do |token, index|
73
+                first_nested_case_close_index = last_case_close_index
74
+                if token.category == :case && token.value == :close
75
+                  last_case_close_index = index
76
+                end
77
+              end
78
+              inner_case_inputs = input.slice!(0..first_nested_case_close_index)
79
+              subparser = Parser.new(
80
+                inner_case_inputs,
81
+                operations: [AST::Case],
82
+                arities: [0]
83
+              )
84
+              subparser.parse
85
+              output.concat(subparser.output)
86
+            else
87
+              operations.push AST::Case
88
+              arities.push(0)
89
+            end
90
+          when :close
91
+            if operations[1] == AST::CaseThen
92
+              while operations.last != AST::Case
93
+                consume
94
+              end
95
+
96
+              operations.push(AST::CaseConditional)
97
+              consume(2)
98
+              arities[-1] += 1
99
+            elsif operations[1] == AST::CaseElse
100
+              while operations.last != AST::Case
101
+                consume
102
+              end
103
+
104
+              arities[-1] += 1
105
+            end
106
+
107
+            unless operations.count == 1 && operations.last == AST::Case
108
+              fail ParseError, "Unprocessed token #{ token.value }"
109
+            end
110
+            consume(arities.pop.succ)
111
+          when :when
112
+            if operations[1] == AST::CaseThen
113
+              while ![AST::CaseWhen, AST::Case].include?(operations.last)
114
+                consume
115
+              end
116
+              operations.push(AST::CaseConditional)
117
+              consume(2)
118
+              arities[-1] += 1
119
+            elsif operations.last == AST::Case
120
+              operations.push(AST::CaseSwitchVariable)
121
+              consume
122
+            end
123
+
124
+            operations.push(AST::CaseWhen)
125
+          when :then
126
+            if operations[1] == AST::CaseWhen
127
+              while ![AST::CaseThen, AST::Case].include?(operations.last)
128
+                consume
129
+              end
130
+            end
131
+            operations.push(AST::CaseThen)
132
+          when :else
133
+            if operations[1] == AST::CaseThen
134
+              while operations.last != AST::Case
135
+                consume
136
+              end
137
+
138
+              operations.push(AST::CaseConditional)
139
+              consume(2)
140
+              arities[-1] += 1
141
+            end
142
+
143
+            operations.push(AST::CaseElse)
144
+          else
145
+            fail ParseError, "Unknown case token #{ token.value }"
146
+          end
147
+
148
+        when :grouping
149
+          case token.value
150
+          when :open
151
+            if input.first && input.first.value == :close
152
+              input.shift
153
+              consume(0)
154
+            else
155
+              operations.push AST::Grouping
156
+            end
157
+
158
+          when :close
159
+            while operations.any? && operations.last != AST::Grouping
160
+              consume
161
+            end
162
+
163
+            lparen = operations.pop
164
+            fail ParseError, "Unbalanced parenthesis" unless lparen == AST::Grouping
165
+
166
+            if operations.last && operations.last < AST::Function
167
+              consume(arities.pop.succ)
168
+            end
169
+
170
+          when :comma
171
+            arities[-1] += 1
172
+            while operations.any? && operations.last != AST::Grouping
173
+              consume
174
+            end
175
+
176
+          else
177
+            fail ParseError, "Unknown grouping token #{ token.value }"
178
+          end
179
+
180
+        else
181
+          fail ParseError, "Not implemented for tokens of category #{ token.category }"
182
+        end
183
+      end
184
+
185
+      while operations.any?
186
+        consume
187
+      end
188
+
189
+      unless output.count == 1
190
+        fail ParseError, "Invalid statement"
191
+      end
192
+
193
+      output.first
194
+    end
195
+
196
+    def operation(token)
197
+      {
198
+        add:      AST::Addition,
199
+        subtract: AST::Subtraction,
200
+        multiply: AST::Multiplication,
201
+        divide:   AST::Division,
202
+        pow:      AST::Exponentiation,
203
+        negate:   AST::Negation,
204
+        mod:      AST::Modulo,
205
+
206
+        lt:       AST::LessThan,
207
+        gt:       AST::GreaterThan,
208
+        le:       AST::LessThanOrEqual,
209
+        ge:       AST::GreaterThanOrEqual,
210
+        ne:       AST::NotEqual,
211
+        eq:       AST::Equal,
212
+
213
+        and:      AST::And,
214
+        or:       AST::Or,
215
+      }.fetch(token.value)
216
+    end
217
+
218
+    def function(token)
219
+      Dentaku::AST::Function.get(token.value)
220
+    end
221
+  end
222
+end

+ 32
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token.rb View File

@@ -0,0 +1,32 @@
1
+module Dentaku
2
+  class Token
3
+    attr_reader :category, :raw_value, :value
4
+
5
+    def initialize(category, value, raw_value=nil)
6
+      @category  = category
7
+      @value     = value
8
+      @raw_value = raw_value
9
+    end
10
+
11
+    def to_s
12
+      raw_value || value
13
+    end
14
+
15
+    def length
16
+      raw_value.to_s.length
17
+    end
18
+
19
+    def grouping?
20
+      is?(:grouping)
21
+    end
22
+
23
+    def is?(c)
24
+      category == c
25
+    end
26
+
27
+    def ==(other)
28
+      (category.nil? || other.category.nil? || category == other.category) &&
29
+      (value.nil?    || other.value.nil?    || value    == other.value)
30
+    end
31
+  end
32
+end

+ 137
- 0
deployment_scripts/puppet/files/embedded/lib/ruby/gems/2.3.0/gems/dentaku-2.0.9/lib/dentaku/token_matcher.rb View File

@@ -0,0 +1,137 @@
1
+require 'dentaku/token'
2
+
3
+module Dentaku
4
+  class TokenMatcher
5
+    attr_reader :children, :categories, :values
6
+
7
+    def initialize(categories=nil, values=nil, children=[])
8
+      # store categories and values as hash to optimize key lookup, h/t @jan-mangs
9
+      @categories = [categories].compact.flatten.each_with_object({}) { |c,h| h[c] = 1 }
10
+      @values     = [values].compact.flatten.each_with_object({}) { |v,h| h[v] = 1 }
11
+      @children   = children.compact
12
+      @invert     = false
13
+
14
+      @min = 1
15
+      @max = 1
16
+      @range = (@min..@max)
17
+    end
18
+
19
+    def | (other_matcher)
20
+      self.class.new(:nomatch, :nomatch, leaf_matchers + other_matcher.leaf_matchers)
21
+    end
22
+
23
+    def invert
24
+      @invert = ! @invert
25
+      self
26
+    end
27
+
28
+    def ==(token)
29
+      leaf_matcher? ? matches_token?(token) : any_child_matches_token?(token)
30
+    end
31
+
32
+    def match(token_stream, offset=0)
33
+      matched_tokens = []
34
+      matched = false
35
+
36
+      while self == token_stream[matched_tokens.length + offset] && matched_tokens.length < @max
37
+        matched_tokens << token_stream[matched_tokens.length + offset]
38
+      end
39
+
40
+      if @range.cover?(matched_tokens.length)
41
+        matched = true
42
<