bolt 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bolt might be problematic. Click here for more details.

Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bolt/cli.rb +127 -31
  3. data/lib/bolt/config.rb +39 -6
  4. data/lib/bolt/execution_result.rb +109 -0
  5. data/lib/bolt/executor.rb +4 -1
  6. data/lib/bolt/node.rb +6 -1
  7. data/lib/bolt/node/orch.rb +20 -2
  8. data/lib/bolt/node/winrm.rb +22 -10
  9. data/lib/bolt/node_uri.rb +5 -7
  10. data/lib/bolt/outputter/human.rb +60 -1
  11. data/lib/bolt/outputter/json.rb +11 -0
  12. data/lib/bolt/target.rb +32 -0
  13. data/lib/bolt/version.rb +1 -1
  14. data/modules/boltlib/lib/puppet/datatypes/executionresult.rb +30 -0
  15. data/modules/boltlib/lib/puppet/datatypes/target.rb +12 -0
  16. data/modules/boltlib/lib/puppet/functions/file_upload.rb +3 -3
  17. data/modules/boltlib/lib/puppet/functions/run_command.rb +3 -3
  18. data/modules/boltlib/lib/puppet/functions/run_script.rb +3 -3
  19. data/modules/boltlib/lib/puppet/functions/run_task.rb +10 -2
  20. data/vendored/puppet/lib/puppet/application/describe.rb +0 -1
  21. data/vendored/puppet/lib/puppet/configurer.rb +1 -1
  22. data/vendored/puppet/lib/puppet/configurer/plugin_handler.rb +15 -9
  23. data/vendored/puppet/lib/puppet/datatypes.rb +213 -0
  24. data/vendored/puppet/lib/puppet/datatypes/error.rb +19 -0
  25. data/vendored/puppet/lib/puppet/datatypes/impl/error.rb +42 -0
  26. data/vendored/puppet/lib/puppet/error.rb +1 -1
  27. data/vendored/puppet/lib/puppet/face/catalog.rb +1 -1
  28. data/vendored/puppet/lib/puppet/face/epp.rb +3 -3
  29. data/vendored/puppet/lib/puppet/face/help.rb +12 -14
  30. data/vendored/puppet/lib/puppet/face/man.rb +1 -0
  31. data/vendored/puppet/lib/puppet/face/module/search.rb +1 -1
  32. data/vendored/puppet/lib/puppet/face/node.rb +1 -0
  33. data/vendored/puppet/lib/puppet/face/parser.rb +0 -1
  34. data/vendored/puppet/lib/puppet/face/status.rb +1 -0
  35. data/vendored/puppet/lib/puppet/feature/base.rb +1 -1
  36. data/vendored/puppet/lib/puppet/file_bucket/dipper.rb +0 -1
  37. data/vendored/puppet/lib/puppet/file_system/uniquefile.rb +2 -2
  38. data/vendored/puppet/lib/puppet/forge/errors.rb +21 -29
  39. data/vendored/puppet/lib/puppet/functions.rb +64 -84
  40. data/vendored/puppet/lib/puppet/functions/defined.rb +0 -3
  41. data/vendored/puppet/lib/puppet/functions/find_file.rb +0 -1
  42. data/vendored/puppet/lib/puppet/functions/map.rb +0 -1
  43. data/vendored/puppet/lib/puppet/functions/regsubst.rb +1 -1
  44. data/vendored/puppet/lib/puppet/graph/simple_graph.rb +6 -10
  45. data/vendored/puppet/lib/puppet/indirector/catalog/compiler.rb +37 -25
  46. data/vendored/puppet/lib/puppet/indirector/file_server.rb +1 -1
  47. data/vendored/puppet/lib/puppet/indirector/indirection.rb +0 -2
  48. data/vendored/puppet/lib/puppet/indirector/rest.rb +9 -8
  49. data/vendored/puppet/lib/puppet/info_service/class_information_service.rb +1 -1
  50. data/vendored/puppet/lib/puppet/interface/option_manager.rb +1 -1
  51. data/vendored/puppet/lib/puppet/loaders.rb +1 -0
  52. data/vendored/puppet/lib/puppet/module.rb +6 -2
  53. data/vendored/puppet/lib/puppet/module_tool/applications/unpacker.rb +1 -1
  54. data/vendored/puppet/lib/puppet/module_tool/errors/installer.rb +29 -41
  55. data/vendored/puppet/lib/puppet/module_tool/errors/shared.rb +63 -138
  56. data/vendored/puppet/lib/puppet/module_tool/errors/uninstaller.rb +15 -37
  57. data/vendored/puppet/lib/puppet/module_tool/errors/upgrader.rb +18 -30
  58. data/vendored/puppet/lib/puppet/module_tool/installed_modules.rb +1 -1
  59. data/vendored/puppet/lib/puppet/module_tool/metadata.rb +0 -1
  60. data/vendored/puppet/lib/puppet/network/http/api/indirected_routes.rb +1 -1
  61. data/vendored/puppet/lib/puppet/network/rights.rb +1 -1
  62. data/vendored/puppet/lib/puppet/node.rb +1 -1
  63. data/vendored/puppet/lib/puppet/node/environment.rb +1 -1
  64. data/vendored/puppet/lib/puppet/parameter/value_collection.rb +4 -17
  65. data/vendored/puppet/lib/puppet/parser/compiler.rb +1 -0
  66. data/vendored/puppet/lib/puppet/parser/functions.rb +0 -1
  67. data/vendored/puppet/lib/puppet/parser/functions/scanf.rb +1 -1
  68. data/vendored/puppet/lib/puppet/parser/scope.rb +4 -3
  69. data/vendored/puppet/lib/puppet/parser/script_compiler.rb +1 -0
  70. data/vendored/puppet/lib/puppet/parser/templatewrapper.rb +3 -2
  71. data/vendored/puppet/lib/puppet/parser/type_loader.rb +1 -1
  72. data/vendored/puppet/lib/puppet/pops.rb +1 -0
  73. data/vendored/puppet/lib/puppet/pops/evaluator/access_operator.rb +3 -2
  74. data/vendored/puppet/lib/puppet/pops/evaluator/closure.rb +1 -1
  75. data/vendored/puppet/lib/puppet/pops/evaluator/evaluator_impl.rb +2 -2
  76. data/vendored/puppet/lib/puppet/pops/functions/dispatch.rb +6 -5
  77. data/vendored/puppet/lib/puppet/pops/functions/function.rb +2 -2
  78. data/vendored/puppet/lib/puppet/pops/loader/loader.rb +1 -1
  79. data/vendored/puppet/lib/puppet/pops/loader/loader_paths.rb +40 -4
  80. data/vendored/puppet/lib/puppet/pops/loader/module_loaders.rb +6 -2
  81. data/vendored/puppet/lib/puppet/pops/loader/puppet_resource_type_impl_instantiator.rb +8 -8
  82. data/vendored/puppet/lib/puppet/pops/loader/ruby_data_type_instantiator.rb +40 -0
  83. data/vendored/puppet/lib/puppet/pops/loader/static_loader.rb +6 -26
  84. data/vendored/puppet/lib/puppet/pops/loaders.rb +11 -2
  85. data/vendored/puppet/lib/puppet/pops/lookup/data_dig_function_provider.rb +1 -1
  86. data/vendored/puppet/lib/puppet/pops/lookup/lookup_adapter.rb +4 -14
  87. data/vendored/puppet/lib/puppet/pops/model/model_tree_dumper.rb +1 -1
  88. data/vendored/puppet/lib/puppet/pops/parser/code_merger.rb +2 -2
  89. data/vendored/puppet/lib/puppet/pops/parser/eparser.rb +1471 -1501
  90. data/vendored/puppet/lib/puppet/pops/parser/epp_support.rb +0 -2
  91. data/vendored/puppet/lib/puppet/pops/parser/evaluating_parser.rb +1 -1
  92. data/vendored/puppet/lib/puppet/pops/parser/interpolation_support.rb +1 -1
  93. data/vendored/puppet/lib/puppet/pops/parser/lexer2.rb +2 -26
  94. data/vendored/puppet/lib/puppet/pops/parser/locator.rb +5 -7
  95. data/vendored/puppet/lib/puppet/pops/parser/parser_support.rb +2 -2
  96. data/vendored/puppet/lib/puppet/pops/parser/slurp_support.rb +0 -3
  97. data/vendored/puppet/lib/puppet/pops/pcore.rb +0 -11
  98. data/vendored/puppet/lib/puppet/pops/serialization/object.rb +3 -4
  99. data/vendored/puppet/lib/puppet/pops/serialization/to_data_converter.rb +1 -1
  100. data/vendored/puppet/lib/puppet/pops/time/timespan.rb +1 -1
  101. data/vendored/puppet/lib/puppet/pops/types/iterable.rb +14 -7
  102. data/vendored/puppet/lib/puppet/pops/types/p_object_type.rb +38 -7
  103. data/vendored/puppet/lib/puppet/pops/types/p_object_type_extension.rb +21 -22
  104. data/vendored/puppet/lib/puppet/pops/types/p_sem_ver_range_type.rb +0 -1
  105. data/vendored/puppet/lib/puppet/pops/types/p_type_set_type.rb +0 -1
  106. data/vendored/puppet/lib/puppet/pops/types/p_uri_type.rb +0 -1
  107. data/vendored/puppet/lib/puppet/pops/types/puppet_object.rb +1 -1
  108. data/vendored/puppet/lib/puppet/pops/types/string_converter.rb +5 -1
  109. data/vendored/puppet/lib/puppet/pops/types/type_calculator.rb +5 -1
  110. data/vendored/puppet/lib/puppet/pops/types/type_factory.rb +1 -5
  111. data/vendored/puppet/lib/puppet/pops/types/type_formatter.rb +21 -0
  112. data/vendored/puppet/lib/puppet/pops/types/types.rb +2 -7
  113. data/vendored/puppet/lib/puppet/pops/validation/checker4_0.rb +1 -3
  114. data/vendored/puppet/lib/puppet/property.rb +1 -1
  115. data/vendored/puppet/lib/puppet/provider/augeas/augeas.rb +3 -4
  116. data/vendored/puppet/lib/puppet/provider/exec.rb +0 -2
  117. data/vendored/puppet/lib/puppet/provider/nameservice.rb +6 -1
  118. data/vendored/puppet/lib/puppet/provider/nameservice/directoryservice.rb +3 -3
  119. data/vendored/puppet/lib/puppet/provider/package/appdmg.rb +0 -1
  120. data/vendored/puppet/lib/puppet/provider/package/apple.rb +0 -1
  121. data/vendored/puppet/lib/puppet/provider/package/macports.rb +2 -2
  122. data/vendored/puppet/lib/puppet/provider/package/pkgdmg.rb +0 -1
  123. data/vendored/puppet/lib/puppet/provider/package/portage.rb +0 -1
  124. data/vendored/puppet/lib/puppet/provider/package/zypper.rb +2 -2
  125. data/vendored/puppet/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +2 -2
  126. data/vendored/puppet/lib/puppet/provider/service/init.rb +1 -0
  127. data/vendored/puppet/lib/puppet/provider/service/launchd.rb +3 -3
  128. data/vendored/puppet/lib/puppet/provider/user/aix.rb +1 -1
  129. data/vendored/puppet/lib/puppet/provider/user/openbsd.rb +1 -1
  130. data/vendored/puppet/lib/puppet/provider/user/pw.rb +1 -1
  131. data/vendored/puppet/lib/puppet/provider/yumrepo/inifile.rb +2 -4
  132. data/vendored/puppet/lib/puppet/provider/zfs/zfs.rb +1 -1
  133. data/vendored/puppet/lib/puppet/provider/zpool/zpool.rb +1 -1
  134. data/vendored/puppet/lib/puppet/reference/type.rb +0 -1
  135. data/vendored/puppet/lib/puppet/resource.rb +1 -2
  136. data/vendored/puppet/lib/puppet/resource/status.rb +0 -1
  137. data/vendored/puppet/lib/puppet/resource/type.rb +3 -3
  138. data/vendored/puppet/lib/puppet/resource/type_collection.rb +1 -1
  139. data/vendored/puppet/lib/puppet/settings/environment_conf.rb +0 -1
  140. data/vendored/puppet/lib/puppet/ssl/host.rb +1 -1
  141. data/vendored/puppet/lib/puppet/syntax_checkers/base64.rb +1 -1
  142. data/vendored/puppet/lib/puppet/transaction/persistence.rb +1 -1
  143. data/vendored/puppet/lib/puppet/type.rb +17 -4
  144. data/vendored/puppet/lib/puppet/type/file.rb +3 -3
  145. data/vendored/puppet/lib/puppet/type/mount.rb +9 -0
  146. data/vendored/puppet/lib/puppet/type/schedule.rb +25 -13
  147. data/vendored/puppet/lib/puppet/type/tidy.rb +2 -2
  148. data/vendored/puppet/lib/puppet/type/user.rb +1 -1
  149. data/vendored/puppet/lib/puppet/util.rb +19 -14
  150. data/vendored/puppet/lib/puppet/util/filetype.rb +2 -2
  151. data/vendored/puppet/lib/puppet/util/json_lockfile.rb +1 -1
  152. data/vendored/puppet/lib/puppet/util/log.rb +5 -3
  153. data/vendored/puppet/lib/puppet/util/log/destinations.rb +0 -1
  154. data/vendored/puppet/lib/puppet/util/monkey_patches.rb +1 -1
  155. data/vendored/puppet/lib/puppet/util/network_device/config.rb +2 -2
  156. data/vendored/puppet/lib/puppet/util/plist.rb +6 -4
  157. data/vendored/puppet/lib/puppet/util/rdoc/generators/puppet_generator.rb +1 -1
  158. data/vendored/puppet/lib/puppet/util/rdoc/parser/puppet_parser_rdoc2.rb +1 -1
  159. data/vendored/puppet/lib/puppet/util/storage.rb +2 -2
  160. data/vendored/puppet/lib/puppet/util/windows/registry.rb +2 -2
  161. data/vendored/puppet/lib/puppet/util/windows/sid.rb +0 -2
  162. data/vendored/puppet/lib/puppet/version.rb +1 -1
  163. data/vendored/puppet/lib/puppet_pal.rb +30 -17
  164. metadata +28 -7
  165. data/vendored/puppet/lib/puppet/pops/types/execution_result.rb +0 -137
@@ -71,7 +71,6 @@ module Puppet::Util::Windows
71
71
  raw_sid_bytes = nil
72
72
  begin
73
73
  string_to_sid_ptr(name) do |sid_ptr|
74
- valid = ! sid_ptr.nil? && ! sid_ptr.null?
75
74
  raw_sid_bytes = sid_ptr.read_array_of_uchar(get_length_sid(sid_ptr))
76
75
  end
77
76
  rescue
@@ -105,7 +104,6 @@ module Puppet::Util::Windows
105
104
  sid_bytes = []
106
105
  begin
107
106
  string_to_sid_ptr(value) do |ptr|
108
- valid = ! ptr.nil? && ! ptr.null?
109
107
  sid_bytes = ptr.read_array_of_uchar(get_length_sid(ptr))
110
108
  end
111
109
  rescue Puppet::Util::Windows::Error => e
@@ -6,7 +6,7 @@
6
6
  # Raketasks and such to set the version based on the output of `git describe`
7
7
 
8
8
  module Puppet
9
- PUPPETVERSION = '5.3.3'
9
+ PUPPETVERSION = '5.3.4'
10
10
 
11
11
  ##
12
12
  # version is a public API method intended to always provide a fast and
@@ -530,18 +530,10 @@ module Pal
530
530
  Puppet[:tasks] = true
531
531
  # After the assertions, if code_string is non nil - it has the highest precedence
532
532
  Puppet[:code] = code_string unless code_string.nil?
533
- overrides = {}
534
- unless facts.nil?
535
- overrides[:pal_facts] = Puppet.lookup(:pal_facts).merge(facts)
536
- end
537
- unless variables.nil?
538
- overrides[:pal_variables] = Puppet.lookup(:pal_variables).merge(variables)
539
- end
540
- Puppet.override(overrides, "PAL::with_script_compiler") do # TRANSLATORS: Do not translate, symbolic name
541
- # If manifest_file is nil, the #main method will use the env configured manifest
542
- # do things in block while a Script Compiler is in effect
543
- main(manifest_file, &block)
544
- end
533
+
534
+ # If manifest_file is nil, the #main method will use the env configured manifest
535
+ # to do things in the block while a Script Compiler is in effect
536
+ main(manifest_file, facts, variables, &block)
545
537
  end
546
538
 
547
539
  # Evaluates a Puppet Language script string.
@@ -749,7 +741,7 @@ module Pal
749
741
  # Picks up information from the puppet context and configures a script compiler which is given to
750
742
  # the provided block
751
743
  #
752
- def self.main(manifest = nil, &block)
744
+ def self.main(manifest, facts, variables)
753
745
  # Configure the load path
754
746
  env = Puppet.lookup(:pal_env)
755
747
  env.each_plugin_directory do |dir|
@@ -761,7 +753,20 @@ module Pal
761
753
  Facter.reset
762
754
 
763
755
  node = Puppet.lookup(:pal_current_node)
764
- prepare_node_facts(node, Puppet.lookup(:pal_facts))
756
+ pal_facts = Puppet.lookup(:pal_facts)
757
+ pal_variables = Puppet.lookup(:pal_variables)
758
+
759
+ overrides = {}
760
+ unless facts.nil? || facts.empty?
761
+ pal_facts = pal_facts.merge(facts)
762
+ overrides[:pal_facts] = pal_facts
763
+ end
764
+ unless variables.nil? || variables.empty?
765
+ pal_variables = pal_variables.merge(variables)
766
+ overrides[:pal_variables] = pal_variables
767
+ end
768
+
769
+ prepare_node_facts(node, pal_facts)
765
770
 
766
771
  configured_environment = node.environment || Puppet.lookup(:current_environment)
767
772
 
@@ -805,15 +810,23 @@ module Pal
805
810
  # create the $settings:: variables
806
811
  topscope.merge_settings(node.environment.name, false)
807
812
 
808
- add_variables(topscope, Puppet.lookup(:pal_variables))
813
+ add_variables(topscope, pal_variables)
809
814
 
810
815
  # compiler.compile(&block)
811
816
  compiler.compile do | internal_compiler |
812
817
  # wrap the internal compiler to prevent it from leaking in the PAL API
813
- block.call(ScriptCompiler.new(internal_compiler)) unless !block_given?
818
+ if block_given?
819
+ script_compiler = ScriptCompiler.new(internal_compiler)
820
+
821
+ # Make compiler available to Puppet#lookup
822
+ overrides[:pal_script_compiler] = script_compiler
823
+ Puppet.override(overrides, "PAL::with_script_compiler") do # TRANSLATORS: Do not translate, symbolic name
824
+ yield(script_compiler)
825
+ end
826
+ end
814
827
  end
815
828
 
816
- rescue Puppet::ParseErrorWithIssue, Puppet::Error => detail
829
+ rescue Puppet::ParseErrorWithIssue, Puppet::Error
817
830
  # already logged and handled by the compiler for these two cases
818
831
  raise
819
832
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bolt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-13 00:00:00.000000000 Z
11
+ date: 2017-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.2.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: terminal-table
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.8.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.8.0
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: winrm
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -230,16 +244,16 @@ dependencies:
230
244
  name: puppetlabs_spec_helper
231
245
  requirement: !ruby/object:Gem::Requirement
232
246
  requirements:
233
- - - '='
247
+ - - "~>"
234
248
  - !ruby/object:Gem::Version
235
- version: 2.5.1
249
+ version: '2.6'
236
250
  type: :development
237
251
  prerelease: false
238
252
  version_requirements: !ruby/object:Gem::Requirement
239
253
  requirements:
240
- - - '='
254
+ - - "~>"
241
255
  - !ruby/object:Gem::Version
242
- version: 2.5.1
256
+ version: '2.6'
243
257
  - !ruby/object:Gem::Dependency
244
258
  name: bundler
245
259
  requirement: !ruby/object:Gem::Requirement
@@ -295,6 +309,7 @@ files:
295
309
  - lib/bolt/cli.rb
296
310
  - lib/bolt/config.rb
297
311
  - lib/bolt/error.rb
312
+ - lib/bolt/execution_result.rb
298
313
  - lib/bolt/executor.rb
299
314
  - lib/bolt/formatter.rb
300
315
  - lib/bolt/node.rb
@@ -309,7 +324,10 @@ files:
309
324
  - lib/bolt/outputter/human.rb
310
325
  - lib/bolt/outputter/json.rb
311
326
  - lib/bolt/result.rb
327
+ - lib/bolt/target.rb
312
328
  - lib/bolt/version.rb
329
+ - modules/boltlib/lib/puppet/datatypes/executionresult.rb
330
+ - modules/boltlib/lib/puppet/datatypes/target.rb
313
331
  - modules/boltlib/lib/puppet/functions/file_upload.rb
314
332
  - modules/boltlib/lib/puppet/functions/run_command.rb
315
333
  - modules/boltlib/lib/puppet/functions/run_plan.rb
@@ -532,6 +550,9 @@ files:
532
550
  - vendored/puppet/lib/puppet/context/trusted_information.rb
533
551
  - vendored/puppet/lib/puppet/daemon.rb
534
552
  - vendored/puppet/lib/puppet/data_binding.rb
553
+ - vendored/puppet/lib/puppet/datatypes.rb
554
+ - vendored/puppet/lib/puppet/datatypes/error.rb
555
+ - vendored/puppet/lib/puppet/datatypes/impl/error.rb
535
556
  - vendored/puppet/lib/puppet/defaults.rb
536
557
  - vendored/puppet/lib/puppet/environments.rb
537
558
  - vendored/puppet/lib/puppet/error.rb
@@ -1004,6 +1025,7 @@ files:
1004
1025
  - vendored/puppet/lib/puppet/pops/loader/puppet_function_instantiator.rb
1005
1026
  - vendored/puppet/lib/puppet/pops/loader/puppet_plan_instantiator.rb
1006
1027
  - vendored/puppet/lib/puppet/pops/loader/puppet_resource_type_impl_instantiator.rb
1028
+ - vendored/puppet/lib/puppet/pops/loader/ruby_data_type_instantiator.rb
1007
1029
  - vendored/puppet/lib/puppet/pops/loader/ruby_function_instantiator.rb
1008
1030
  - vendored/puppet/lib/puppet/pops/loader/runtime3_type_loader.rb
1009
1031
  - vendored/puppet/lib/puppet/pops/loader/simple_environment_loader.rb
@@ -1080,7 +1102,6 @@ files:
1080
1102
  - vendored/puppet/lib/puppet/pops/types/annotation.rb
1081
1103
  - vendored/puppet/lib/puppet/pops/types/class_loader.rb
1082
1104
  - vendored/puppet/lib/puppet/pops/types/enumeration.rb
1083
- - vendored/puppet/lib/puppet/pops/types/execution_result.rb
1084
1105
  - vendored/puppet/lib/puppet/pops/types/implementation_registry.rb
1085
1106
  - vendored/puppet/lib/puppet/pops/types/iterable.rb
1086
1107
  - vendored/puppet/lib/puppet/pops/types/p_binary_type.rb
@@ -1,137 +0,0 @@
1
- module Puppet::Pops
2
- module Types
3
- class ExecutionResult
4
- include PuppetObject
5
- include Iterable
6
- include IteratorProducer
7
-
8
- TYPE_RESULT_HASH = TypeFactory.hash_kv(PStringType::NON_EMPTY, TypeFactory.struct({
9
- TypeFactory.optional('value') => TypeFactory.data,
10
- TypeFactory.optional('error') => TypeFactory.struct({
11
- 'msg' => PStringType::NON_EMPTY,
12
- TypeFactory.optional('kind') => PStringType::NON_EMPTY,
13
- TypeFactory.optional('issue_code') => PStringType::NON_EMPTY,
14
- TypeFactory.optional('details') => TypeFactory.hash_of_data,
15
- })
16
- }))
17
-
18
- TYPE_RESULT_ERRORS = TypeFactory.hash_kv(PStringType::NON_EMPTY, TypeFactory.variant(TypeFactory.error, TypeFactory.data))
19
-
20
- def self.register_ptype(loader, ir)
21
- @type = Pcore::create_object_type(loader, ir, self, 'ExecutionResult', nil,
22
- { 'result_hash' => TYPE_RESULT_HASH },
23
- {
24
- 'count' => TypeFactory.callable([], TypeFactory.integer),
25
- 'empty' => TypeFactory.callable([], TypeFactory.boolean),
26
- 'error_nodes' => TypeFactory.callable([], TypeFactory.type_reference('ExecutionResult')),
27
- 'names' => TypeFactory.callable([], TypeFactory.array_of(PStringType::NON_EMPTY)),
28
- 'ok' => TypeFactory.callable([], TypeFactory.boolean),
29
- 'ok_nodes' => TypeFactory.callable([], TypeFactory.type_reference('ExecutionResult')),
30
- 'value' => TypeFactory.callable([PStringType::NON_EMPTY], TypeFactory.variant(TypeFactory.error, TypeFactory.data)),
31
- 'values' => TypeFactory.callable([], TypeFactory.array_of(TypeFactory.variant(TypeFactory.error, TypeFactory.data))),
32
- '[]' => TypeFactory.callable([PStringType::NON_EMPTY], TypeFactory.variant(TypeFactory.error, TypeFactory.data)),
33
- })
34
- end
35
-
36
- def self._pcore_type
37
- @type
38
- end
39
-
40
- # Creates a pure Data hash from a result hash returned from the Bolt::Executor
41
- # @return [Hash{String => Data}] The data hash
42
- def self.from_bolt(result_hash)
43
- data_result = {}
44
- result_hash.each_pair { |k, v| data_result[k.uri] = v.to_h }
45
- self.new(data_result)
46
- end
47
-
48
- attr_reader :result_hash
49
-
50
- def initialize(result_hash)
51
- @result_hash = convert_errors(result_hash)
52
- end
53
-
54
- def count
55
- @result_hash.size
56
- end
57
-
58
- def empty
59
- @result_hash.empty?
60
- end
61
- alias_method :empty?, :empty
62
-
63
- def error_nodes
64
- result = {}
65
- t = TypeFactory.error
66
- @result_hash.each_pair { |k, v| result[k] = v if t.instance?(v) }
67
- self.class.new(result)
68
- end
69
-
70
- def iterator
71
- Iterable.on(@result_hash)
72
- end
73
-
74
- def names
75
- @result_hash.keys
76
- end
77
-
78
- def ok
79
- t = TypeFactory.error
80
- !@result_hash.values.any? { |v| t.instance?(v) }
81
- end
82
- alias_method :ok?, :ok
83
-
84
- def ok_nodes
85
- result = {}
86
- t = TypeFactory.error
87
- @result_hash.each_pair { |k, v| result[k] = v unless t.instance?(v) }
88
- self.class.new(result)
89
- end
90
-
91
- def [](node_uri)
92
- @result_hash[node_uri]
93
- end
94
-
95
- def value(node_uri)
96
- self[node_uri]
97
- end
98
-
99
- def values
100
- @result_hash.values
101
- end
102
-
103
- def _pcore_init_hash
104
- @result_hash
105
- end
106
-
107
- def eql?(o)
108
- self.class == o.class && self.result_hash == o.result_hash
109
- end
110
-
111
- def ==(o)
112
- eql?(o)
113
- end
114
-
115
- private
116
-
117
- def convert_errors(result_hash)
118
- return result_hash unless TYPE_RESULT_HASH.instance?(result_hash)
119
- converted = {}
120
- result_hash.each_pair { |k, v| converted[k] = convert_error(v) }
121
- converted
122
- end
123
-
124
- def convert_error(value_or_error)
125
- error = value_or_error['error']
126
- value = value_or_error['value']
127
- if error.nil?
128
- value
129
- else
130
- TypeFactory.error.create(error['msg'], error['kind'], error['issue_code'], value, error['details'])
131
- end
132
- end
133
-
134
- EMPTY_RESULT = ExecutionResult.new(EMPTY_HASH)
135
- end
136
- end
137
- end