scarpe 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/.yardopts +12 -0
- data/CHANGELOG.md +16 -2
- data/Gemfile +3 -0
- data/Gemfile.lock +116 -0
- data/README.md +53 -30
- data/Rakefile +13 -1
- data/docs/yard/catscradle.md +44 -0
- data/docs/yard/template/default/fulldoc/html/setup.rb +13 -0
- data/docs/yard/template/default/layout/html/setup.rb +9 -0
- data/examples/animate.rb +20 -0
- data/examples/arrow.rb +10 -0
- data/examples/background_with_image.rb +16 -0
- data/examples/bloopsaphone/working/bronx_army_knife.rb +66 -0
- data/examples/bloopsaphone/working/morning_serenity.rb +21 -0
- data/examples/bloopsaphone/working/simpsons_theme_song_by_why.rb +6 -4
- data/examples/btn_tooltip.rb +7 -0
- data/examples/button_go_away.rb +1 -1
- data/examples/button_style_changed.rb +7 -0
- data/examples/button_styles_default.rb +6 -0
- data/examples/check.rb +18 -0
- data/examples/clear_and_append.rb +24 -0
- data/examples/download_and_show_image.rb +28 -0
- data/examples/edit_box.rb +3 -5
- data/examples/fonts.rb +2 -2
- data/examples/gen.rb +8 -8
- data/examples/get_headers.rb +10 -0
- data/examples/highlander.rb +4 -2
- data/examples/legacy/README.md +6 -0
- data/examples/legacy/not_checked/shoes-contrib/basic/shoes-notes.rb +1 -1
- data/examples/legacy/not_checked/simple/anim-shapes.rb +1 -1
- data/examples/legacy/not_checked/speedometer_app.rb +55 -0
- data/examples/legacy/working/simple/image-icon.rb +3 -0
- data/examples/legacy/{not_checked → working}/simple/image.rb +1 -1
- data/examples/link.rb +2 -2
- data/examples/list_box_choose.rb +17 -0
- data/examples/local_assets/local_file_server.rb +82 -0
- data/examples/local_assets/sample.gif +0 -0
- data/examples/local_assets/sample.mp4 +0 -0
- data/examples/local_fonts.rb +4 -0
- data/examples/local_images.rb +3 -0
- data/examples/motion_events.rb +20 -0
- data/examples/para/para_text.rb +14 -0
- data/examples/parse_xl_funnies.rb +58 -0
- data/examples/progress.rb +31 -0
- data/examples/radio/radio.rb +16 -0
- data/examples/radio/radio_groups.rb +18 -0
- data/examples/radio/radio_same_slot.rb +6 -0
- data/examples/rect.rb +4 -0
- data/examples/rotate_shapes.rb +17 -0
- data/examples/ruby_racer.rb +13 -15
- data/examples/selfitude.rb +18 -0
- data/examples/shapes/shapes_fill.rb +4 -3
- data/examples/shoes_school.rb +2 -4
- data/examples/show_hide.rb +6 -0
- data/examples/simpler-menu.rb +21 -0
- data/examples/skip_ci/change_my_audio_source.rb +21 -0
- data/examples/skip_ci/guitar_fretboard.rb +137 -0
- data/examples/video.rb +10 -0
- data/exe/scarpe +43 -66
- data/fonts/Pacifico.ttf +0 -0
- data/lacci/Gemfile +24 -0
- data/lacci/Gemfile.lock +79 -0
- data/lacci/Rakefile +12 -0
- data/lacci/lacci.gemspec +37 -0
- data/lacci/lib/lacci/scarpe_cli.rb +71 -0
- data/lacci/lib/lacci/scarpe_core.rb +22 -0
- data/lacci/lib/lacci/version.rb +13 -0
- data/lacci/lib/scarpe/niente/app.rb +23 -0
- data/lacci/lib/scarpe/niente/display_service.rb +62 -0
- data/lacci/lib/scarpe/niente/drawable.rb +57 -0
- data/lacci/lib/scarpe/niente/logger.rb +29 -0
- data/lacci/lib/scarpe/niente/shoes_spec.rb +87 -0
- data/lacci/lib/scarpe/niente.rb +20 -0
- data/lacci/lib/shoes/app.rb +309 -0
- data/{lib/scarpe → lacci/lib/shoes}/background.rb +2 -2
- data/{lib/scarpe → lacci/lib/shoes}/border.rb +2 -2
- data/lacci/lib/shoes/builtins.rb +63 -0
- data/lacci/lib/shoes/changelog.rb +52 -0
- data/{lib/scarpe → lacci/lib/shoes}/colors.rb +3 -1
- data/lacci/lib/shoes/constants.rb +47 -0
- data/{lib/scarpe → lacci/lib/shoes}/display_service.rb +71 -53
- data/lacci/lib/shoes/download.rb +123 -0
- data/lacci/lib/shoes/drawable.rb +380 -0
- data/lacci/lib/shoes/drawables/arc.rb +49 -0
- data/lacci/lib/shoes/drawables/arrow.rb +41 -0
- data/lacci/lib/shoes/drawables/button.rb +73 -0
- data/lacci/lib/shoes/drawables/check.rb +29 -0
- data/lacci/lib/shoes/drawables/document_root.rb +20 -0
- data/lacci/lib/shoes/drawables/edit_box.rb +29 -0
- data/{lib/scarpe → lacci/lib/shoes/drawables}/edit_line.rb +6 -6
- data/lacci/lib/shoes/drawables/flow.rb +22 -0
- data/{lib/scarpe → lacci/lib/shoes/drawables}/image.rb +7 -11
- data/lacci/lib/shoes/drawables/line.rb +20 -0
- data/lacci/lib/shoes/drawables/link.rb +34 -0
- data/lacci/lib/shoes/drawables/list_box.rb +56 -0
- data/lacci/lib/shoes/drawables/para.rb +118 -0
- data/lacci/lib/shoes/drawables/progress.rb +14 -0
- data/lacci/lib/shoes/drawables/radio.rb +33 -0
- data/lacci/lib/shoes/drawables/rect.rb +17 -0
- data/lacci/lib/shoes/drawables/shape.rb +36 -0
- data/lacci/lib/shoes/drawables/slot.rb +87 -0
- data/{lib/scarpe → lacci/lib/shoes/drawables}/span.rb +8 -7
- data/lacci/lib/shoes/drawables/stack.rb +26 -0
- data/lacci/lib/shoes/drawables/star.rb +50 -0
- data/lacci/lib/shoes/drawables/subscription_item.rb +93 -0
- data/lacci/lib/shoes/drawables/text_drawable.rb +63 -0
- data/lacci/lib/shoes/drawables/video.rb +16 -0
- data/lacci/lib/shoes/drawables/widget.rb +69 -0
- data/lacci/lib/shoes/drawables.rb +31 -0
- data/lacci/lib/shoes/errors.rb +28 -0
- data/lacci/lib/shoes/log.rb +71 -0
- data/lacci/lib/shoes/ruby_extensions.rb +15 -0
- data/lacci/lib/shoes/spacing.rb +9 -0
- data/lacci/lib/shoes-spec.rb +93 -0
- data/lacci/lib/shoes.rb +147 -0
- data/lacci/test/test_colors.rb +39 -0
- data/lacci/test/test_helper.rb +63 -0
- data/lacci/test/test_lacci.rb +18 -0
- data/lacci/test/test_shoes_errors.rb +49 -0
- data/lib/scarpe/cats_cradle.rb +271 -0
- data/lib/scarpe/errors.rb +77 -0
- data/lib/scarpe/evented_assertions.rb +121 -0
- data/lib/scarpe/shoes_spec.rb +181 -0
- data/lib/scarpe/version.rb +2 -2
- data/lib/scarpe/wv/app.rb +45 -23
- data/lib/scarpe/wv/arc.rb +4 -48
- data/lib/scarpe/wv/arrow.rb +9 -0
- data/lib/scarpe/wv/button.rb +7 -33
- data/lib/scarpe/wv/check.rb +27 -0
- data/lib/scarpe/wv/control_interface.rb +32 -40
- data/lib/scarpe/wv/document_root.rb +66 -31
- data/lib/scarpe/wv/drawable.rb +273 -0
- data/lib/scarpe/wv/edit_box.rb +4 -19
- data/lib/scarpe/wv/edit_line.rb +4 -18
- data/lib/scarpe/wv/flow.rb +2 -28
- data/lib/scarpe/wv/image.rb +10 -25
- data/lib/scarpe/wv/line.rb +3 -28
- data/lib/scarpe/wv/link.rb +3 -15
- data/lib/scarpe/wv/list_box.rb +6 -29
- data/lib/scarpe/wv/para.rb +11 -28
- data/lib/scarpe/wv/progress.rb +19 -0
- data/lib/scarpe/wv/radio.rb +33 -0
- data/lib/scarpe/wv/rect.rb +13 -0
- data/lib/scarpe/wv/shape.rb +41 -10
- data/lib/scarpe/wv/slot.rb +64 -0
- data/lib/scarpe/wv/span.rb +3 -25
- data/lib/scarpe/wv/stack.rb +2 -38
- data/lib/scarpe/wv/star.rb +3 -54
- data/lib/scarpe/wv/subscription_item.rb +84 -0
- data/lib/scarpe/wv/text_drawable.rb +32 -0
- data/lib/scarpe/wv/video.rb +34 -0
- data/lib/scarpe/wv/web_wrangler.rb +449 -299
- data/lib/scarpe/wv/webview_local_display.rb +63 -26
- data/lib/scarpe/wv/webview_relay_display.rb +24 -125
- data/lib/scarpe/wv/webview_relay_util.rb +140 -0
- data/lib/scarpe/wv/wv_display_worker.rb +19 -6
- data/lib/scarpe/wv.rb +76 -14
- data/lib/scarpe/wv_local.rb +1 -1
- data/lib/scarpe/wv_relay.rb +1 -1
- data/lib/scarpe.rb +4 -32
- data/logger/debug_web_wrangler.json +1 -1
- data/logger/scarpe_wv_test.json +1 -1
- data/scarpe-components/.gitignore +1 -0
- data/scarpe-components/Gemfile +22 -0
- data/scarpe-components/Gemfile.lock +86 -0
- data/scarpe-components/README.md +35 -0
- data/scarpe-components/Rakefile +12 -0
- data/scarpe-components/lib/scarpe/components/base64.rb +25 -0
- data/scarpe-components/lib/scarpe/components/calzini/alert.rb +49 -0
- data/scarpe-components/lib/scarpe/components/calzini/art_widgets.rb +203 -0
- data/scarpe-components/lib/scarpe/components/calzini/button.rb +39 -0
- data/scarpe-components/lib/scarpe/components/calzini/misc.rb +146 -0
- data/scarpe-components/lib/scarpe/components/calzini/para.rb +35 -0
- data/scarpe-components/lib/scarpe/components/calzini/slots.rb +155 -0
- data/scarpe-components/lib/scarpe/components/calzini/text_widgets.rb +65 -0
- data/scarpe-components/lib/scarpe/components/calzini.rb +149 -0
- data/scarpe-components/lib/scarpe/components/errors.rb +20 -0
- data/scarpe-components/lib/scarpe/components/file_helpers.rb +66 -0
- data/scarpe-components/lib/scarpe/components/html.rb +131 -0
- data/scarpe-components/lib/scarpe/components/minitest_export_reporter.rb +75 -0
- data/scarpe-components/lib/scarpe/components/minitest_import_runnable.rb +98 -0
- data/scarpe-components/lib/scarpe/components/minitest_result.rb +86 -0
- data/scarpe-components/lib/scarpe/components/modular_logger.rb +113 -0
- data/scarpe-components/lib/scarpe/components/print_logger.rb +47 -0
- data/{lib/scarpe → scarpe-components/lib/scarpe/components}/promises.rb +115 -48
- data/scarpe-components/lib/scarpe/components/segmented_file_loader.rb +189 -0
- data/scarpe-components/lib/scarpe/components/string_helpers.rb +10 -0
- data/scarpe-components/lib/scarpe/components/tiranti.rb +225 -0
- data/scarpe-components/lib/scarpe/components/unit_test_helpers.rb +257 -0
- data/scarpe-components/lib/scarpe/components/version.rb +7 -0
- data/scarpe-components/scarpe-components.gemspec +38 -0
- data/scarpe-components/test/calzini/test_calzini_alert.rb +30 -0
- data/scarpe-components/test/calzini/test_calzini_art_drawables.rb +105 -0
- data/scarpe-components/test/calzini/test_calzini_button.rb +52 -0
- data/scarpe-components/test/calzini/test_calzini_misc.rb +115 -0
- data/scarpe-components/test/calzini/test_calzini_para.rb +37 -0
- data/scarpe-components/test/calzini/test_calzini_slots.rb +130 -0
- data/scarpe-components/test/calzini/test_calzini_text_drawables.rb +41 -0
- data/scarpe-components/test/mtr_data/exception.json +1 -0
- data/scarpe-components/test/mtr_data/fail_with_message.json +1 -0
- data/scarpe-components/test/mtr_data/skipped_no_message.json +1 -0
- data/scarpe-components/test/mtr_data/skipped_w_msg.json +1 -0
- data/scarpe-components/test/mtr_data/succeed_2_asserts.json +1 -0
- data/scarpe-components/test/test_components.rb +9 -0
- data/scarpe-components/test/test_dimensions.rb +26 -0
- data/scarpe-components/test/test_helper.rb +43 -0
- data/scarpe-components/test/test_html.rb +65 -0
- data/scarpe-components/test/test_minitest_result.rb +61 -0
- data/scarpe-components/test/test_promises.rb +261 -0
- data/scarpe-components/test/test_segmented_app_files.rb +184 -0
- data/scarpegen.rb +14 -14
- data/sig/scarpe.rbs +1 -1
- data/{lib/scarpe → spikes}/glibui/widget.rb +2 -2
- data/{lib/scarpe → spikes}/glibui.rb +1 -1
- data/templates/basic_class_template.erb +13 -14
- data/templates/class_template_with_event_bind.erb +4 -4
- data/templates/class_template_with_shapes.erb +8 -17
- data/templates/example_template.erb +1 -1
- data/templates/module_template.erb +4 -4
- data/templates/webview_template.erb +3 -5
- metadata +236 -145
- data/examples/fill.rb +0 -25
- data/examples/legacy/not_checked/shoes-contrib/basic/class-book.yaml +0 -387
- data/examples/legacy/not_checked/shoes-contrib/elements/image-icon.rb +0 -3
- data/examples/legacy/not_checked/shoes-contrib/good/good-clock.rb +0 -51
- data/examples/legacy/not_checked/shoes-contrib/good/good-follow.rb +0 -26
- data/examples/legacy/not_checked/shoes-contrib/good/good-reminder.rb +0 -174
- data/examples/legacy/not_checked/shoes-contrib/good/good-vjot.rb +0 -56
- data/examples/legacy/not_checked/shoes-contrib/simple/simple-timer.rb +0 -13
- data/examples/legacy/not_checked/shoes-dep-samples/good-clock.rb +0 -51
- data/examples/legacy/not_checked/shoes-dep-samples/good-follow.rb +0 -26
- data/examples/legacy/not_checked/shoes-dep-samples/good-reminder.rb +0 -174
- data/examples/legacy/not_checked/shoes-dep-samples/good-vjot.rb +0 -56
- data/examples/legacy/not_checked/shoes-dep-samples/simple-accordion.rb +0 -75
- data/examples/legacy/not_checked/shoes-dep-samples/simple-anim-shapes.rb +0 -17
- data/examples/legacy/not_checked/shoes-dep-samples/simple-anim-text.rb +0 -13
- data/examples/legacy/not_checked/shoes-dep-samples/simple-arc.rb +0 -23
- data/examples/legacy/not_checked/shoes-dep-samples/simple-bounce.rb +0 -24
- data/examples/legacy/not_checked/shoes-dep-samples/simple-calc.rb +0 -70
- data/examples/legacy/not_checked/shoes-dep-samples/simple-chipmunk.rb +0 -26
- data/examples/legacy/not_checked/shoes-dep-samples/simple-control-sizes.rb +0 -24
- data/examples/legacy/not_checked/shoes-dep-samples/simple-curve.rb +0 -26
- data/examples/legacy/not_checked/shoes-dep-samples/simple-dialogs.rb +0 -29
- data/examples/legacy/not_checked/shoes-dep-samples/simple-draw.rb +0 -13
- data/examples/legacy/not_checked/shoes-dep-samples/simple-editor.rb +0 -28
- data/examples/legacy/not_checked/shoes-dep-samples/simple-form.rb +0 -28
- data/examples/legacy/not_checked/shoes-dep-samples/simple-form.shy +0 -0
- data/examples/legacy/not_checked/shoes-dep-samples/simple-mask.rb +0 -21
- data/examples/legacy/not_checked/shoes-dep-samples/simple-menu.rb +0 -31
- data/examples/legacy/not_checked/shoes-dep-samples/simple-menu1.rb +0 -35
- data/examples/legacy/not_checked/shoes-dep-samples/simple-rubygems.rb +0 -29
- data/examples/legacy/not_checked/shoes-dep-samples/simple-slide.rb +0 -45
- data/examples/legacy/not_checked/shoes-dep-samples/simple-sphere.rb +0 -28
- data/examples/legacy/not_checked/shoes-dep-samples/simple-sqlite3.rb +0 -13
- data/examples/legacy/not_checked/shoes-dep-samples/simple-timer.rb +0 -13
- data/examples/legacy/not_checked/shoes-dep-samples/simple-video.rb +0 -13
- data/examples/legacy/not_checked/simple/anim-text.rb +0 -13
- data/examples/legacy/not_checked/simple/arc.rb +0 -23
- data/examples/legacy/not_checked/simple/bounce.rb +0 -24
- data/examples/legacy/not_checked/simple/chipmunk.rb +0 -26
- data/examples/legacy/not_checked/simple/curve.rb +0 -26
- data/examples/legacy/not_checked/simple/dialogs.rb +0 -29
- data/examples/legacy/not_checked/simple/downloader.rb +0 -40
- data/examples/legacy/not_checked/simple/draw.rb +0 -13
- data/examples/legacy/not_checked/simple/mask.rb +0 -21
- data/examples/legacy/not_checked/simple/slide.rb +0 -45
- data/examples/legacy/not_checked/simple/sphere.rb +0 -28
- data/lib/constants.rb +0 -5
- data/lib/scarpe/alert.rb +0 -19
- data/lib/scarpe/app.rb +0 -78
- data/lib/scarpe/arc.rb +0 -49
- data/lib/scarpe/button.rb +0 -35
- data/lib/scarpe/document_root.rb +0 -20
- data/lib/scarpe/edit_box.rb +0 -24
- data/lib/scarpe/fill.rb +0 -23
- data/lib/scarpe/flow.rb +0 -19
- data/lib/scarpe/line.rb +0 -25
- data/lib/scarpe/link.rb +0 -25
- data/lib/scarpe/list_box.rb +0 -25
- data/lib/scarpe/logger.rb +0 -155
- data/lib/scarpe/para.rb +0 -90
- data/lib/scarpe/shape.rb +0 -19
- data/lib/scarpe/spacing.rb +0 -9
- data/lib/scarpe/stack.rb +0 -70
- data/lib/scarpe/star.rb +0 -47
- data/lib/scarpe/text_widget.rb +0 -42
- data/lib/scarpe/unit_test_helpers.rb +0 -163
- data/lib/scarpe/widget.rb +0 -198
- data/lib/scarpe/widgets.rb +0 -30
- data/lib/scarpe/wv/alert.rb +0 -65
- data/lib/scarpe/wv/background.rb +0 -18
- data/lib/scarpe/wv/border.rb +0 -22
- data/lib/scarpe/wv/control_interface_test.rb +0 -253
- data/lib/scarpe/wv/dimensions.rb +0 -22
- data/lib/scarpe/wv/fill.rb +0 -30
- data/lib/scarpe/wv/html.rb +0 -107
- data/lib/scarpe/wv/shape_helper.rb +0 -44
- data/lib/scarpe/wv/spacing.rb +0 -41
- data/lib/scarpe/wv/text_widget.rb +0 -30
- data/lib/scarpe/wv/widget.rb +0 -181
- data/scarpe-0.2.0.gem +0 -0
- /data/examples/legacy/not_checked/{expert → shoes-contrib/basic}/definr.rb +0 -0
- /data/examples/legacy/not_checked/{expert → shoes-contrib/basic}/funnies.rb +0 -0
- /data/examples/legacy/not_checked/shoes-contrib/{elements → basic}/list_box-select-class.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/basic → working/simple}/basic-edit-box.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/elements → working/simple}/basic-fps.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/elements → working/simple}/border-cat.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/elements → working/simple}/check-mate.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/manipulation → working/simple}/clear-slot.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/basic → working/simple}/clock.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/basic → working/simple}/gradient-shoes.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/basic → working/simple}/list_box-shape-report.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/elements → working/simple}/list_box.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/elements → working/simple}/phat-button.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib → working}/simple/simple-calc.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/position → working/simple}/stack-width.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/elements → working/simple}/width-introspec.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/README.md +0 -0
- /data/{lib/scarpe → spikes}/glibui/alert.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/app.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/background.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/border.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/button.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/dimensions.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/document_root.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/edit_box.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/edit_line.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/flow.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/html.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/image.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/link.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/local_display.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/para.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/spacing.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/stack.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/text_widget.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/alert.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/button.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/colors.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/core.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/flow.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/libui.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/notepad.md +0 -0
- /data/{lib/scarpe → spikes}/libui/para.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/stack.rb +0 -0
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "minitest"
|
4
|
+
require "json"
|
5
|
+
require "json/add/exception"
|
6
|
+
|
7
|
+
module Scarpe; module Components; end; end
|
8
|
+
module Scarpe::Components::ImportRunnables
|
9
|
+
# Minitest Runnables are unusual - we expect to declare a class (like a Test) with
|
10
|
+
# a lot of methods to run. The ImportRunnable is a single Runnable. But whenever
|
11
|
+
# you tell it to import a JSON file, it will add all of the described tests to
|
12
|
+
# its runnable methods.
|
13
|
+
#
|
14
|
+
# Normally that means that your subclass tests will run up front and produce
|
15
|
+
# JSON files, then Minitest will autorun at the end and report all their
|
16
|
+
# results.
|
17
|
+
#
|
18
|
+
# It wouldn't really make sense to create these runnables during the testing
|
19
|
+
# phase, because Minitest has already decided what to run at that point.
|
20
|
+
class ImportRunnable #< Minitest::Runnable
|
21
|
+
# Import JSON from an exported Minitest run. Note that running this multiple
|
22
|
+
# times with overlapping class names may be really bad.
|
23
|
+
def self.import_json_data(data)
|
24
|
+
@imported_classes ||= {}
|
25
|
+
@imported_tests ||= {}
|
26
|
+
|
27
|
+
JSON.parse(data).each do |item|
|
28
|
+
klass = item["klass"]
|
29
|
+
meth = item["name"]
|
30
|
+
@imported_tests[klass] ||= {}
|
31
|
+
@imported_tests[klass][meth] = item
|
32
|
+
end
|
33
|
+
|
34
|
+
@imported_tests.each do |klass_name, test_method_hash|
|
35
|
+
klass = @imported_classes[klass_name]
|
36
|
+
unless klass
|
37
|
+
new_klass = Class.new(Minitest::Runnable)
|
38
|
+
@imported_classes[klass_name] = new_klass
|
39
|
+
ImportRunnable.const_set(klass_name, new_klass)
|
40
|
+
klass = new_klass
|
41
|
+
|
42
|
+
klass.define_singleton_method(:run_one_method) do |klass, method_name, reporter|
|
43
|
+
reporter.prerecord klass, method_name
|
44
|
+
imp = test_method_hash[method_name]
|
45
|
+
|
46
|
+
res = Minitest::Result.new imp["name"]
|
47
|
+
res.klass = imp["klass"]
|
48
|
+
res.assertions = imp["assertions"]
|
49
|
+
res.time = imp["time"]
|
50
|
+
res.failures = ImportRunnable.deserialize_failures imp["failures"]
|
51
|
+
res.metadata = imp["metadata"] if imp["metadata"]
|
52
|
+
|
53
|
+
# Record the synthetic result built from imported data
|
54
|
+
reporter.record res
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Update "runnables" method to reflect all current known runnable tests
|
59
|
+
klass_methods = test_method_hash.keys
|
60
|
+
klass.define_singleton_method(:runnable_methods) do
|
61
|
+
klass_methods
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.json_to_err(err_json)
|
67
|
+
klass = begin
|
68
|
+
Object.const_get(err_json["json_class"])
|
69
|
+
rescue
|
70
|
+
nil
|
71
|
+
end
|
72
|
+
if klass && klass <= Minitest::Assertion
|
73
|
+
klass.json_create(err_json)
|
74
|
+
else
|
75
|
+
err = Exception.json_create(err_json)
|
76
|
+
Minitest::UnexpectedError.new(err)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.deserialize_failures(failures)
|
81
|
+
failures.map do |fail|
|
82
|
+
# Instantiate the Minitest::Assertion or Minitest::UnexpectedError
|
83
|
+
if fail[0] == "exception"
|
84
|
+
exc_json = JSON.parse(fail[1])
|
85
|
+
json_to_err exc_json
|
86
|
+
elsif fail[0] == "unexpected"
|
87
|
+
unexpected_json = JSON.parse(fail[1])
|
88
|
+
inner_json = JSON.parse(fail[2])
|
89
|
+
outer_err = json_to_err unexpected_json
|
90
|
+
inner_err = json_to_err inner_json
|
91
|
+
outer_err.error = inner_err
|
92
|
+
else
|
93
|
+
raise "Unknown exception data when trying to deserialize! #{fail.inspect}"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "minitest"
|
4
|
+
require "json"
|
5
|
+
#require "json/add/exception"
|
6
|
+
|
7
|
+
module Scarpe; module Components; end; end
|
8
|
+
|
9
|
+
# A MinitestResult imports a JSON file from a minitest_export_reporter.
|
10
|
+
# But instead of creating a Minitest::Test to report the result, the
|
11
|
+
# MinitestResult is just a queryable Ruby object.
|
12
|
+
#
|
13
|
+
# MinitestResult assumes there will be only one class and one method
|
14
|
+
# in the JSON, which is true for Scarpe but not necessarily in general.
|
15
|
+
class Scarpe::Components::MinitestResult
|
16
|
+
attr_reader :assertions
|
17
|
+
attr_reader :method_name
|
18
|
+
attr_reader :class_name
|
19
|
+
|
20
|
+
def initialize(filename)
|
21
|
+
data = JSON.parse File.read(filename)
|
22
|
+
|
23
|
+
unless data.size == 1
|
24
|
+
# We would want a different interface to support this in general. For now we don't
|
25
|
+
# need it to work in general.
|
26
|
+
raise "Scarpe::Components::MinitestResult only supports one class and method in results!"
|
27
|
+
end
|
28
|
+
|
29
|
+
item = data.first
|
30
|
+
|
31
|
+
@assertions = item["assertions"]
|
32
|
+
@method_name = item["name"]
|
33
|
+
@class_name = item["klass"]
|
34
|
+
@time = item["time"]
|
35
|
+
@metadata = item.key?("metadata") ? item["metadata"]: {}
|
36
|
+
|
37
|
+
@skip = false
|
38
|
+
@exceptions = []
|
39
|
+
@failures = []
|
40
|
+
item["failures"].each do |f|
|
41
|
+
# JSON.parse ignores json_class and won't create an arbitrary object. That's good
|
42
|
+
# because Minitest::UnexpectedError seems to load in a bad way, so we don't want
|
43
|
+
# it to auto-instantiate.
|
44
|
+
d = JSON.parse f[1]
|
45
|
+
msg = d["m"]
|
46
|
+
case d["json_class"]
|
47
|
+
when "Minitest::UnexpectedError"
|
48
|
+
@exceptions << msg
|
49
|
+
when "Minitest::Skip"
|
50
|
+
@skip = msg
|
51
|
+
when "Minitest::Assertion"
|
52
|
+
@failures << msg
|
53
|
+
else
|
54
|
+
raise Scarpe::InternalError, "Didn't expect type #{t.inspect} as exception type when importing Minitest tests!"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def error?
|
60
|
+
!@exceptions.empty?
|
61
|
+
end
|
62
|
+
|
63
|
+
def fail?
|
64
|
+
!@failures.empty?
|
65
|
+
end
|
66
|
+
|
67
|
+
def skip?
|
68
|
+
@skip ? true : false
|
69
|
+
end
|
70
|
+
|
71
|
+
def passed?
|
72
|
+
@exceptions.empty? && @failures.empty? && !@skip
|
73
|
+
end
|
74
|
+
|
75
|
+
def error_message
|
76
|
+
@exceptions[0]
|
77
|
+
end
|
78
|
+
|
79
|
+
def fail_message
|
80
|
+
@failures[0]
|
81
|
+
end
|
82
|
+
|
83
|
+
def skip_message
|
84
|
+
@skip
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "logging"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
require "shoes/log"
|
7
|
+
|
8
|
+
# Requires the logging gem
|
9
|
+
|
10
|
+
module Scarpe; end
|
11
|
+
module Scarpe::Components; end
|
12
|
+
module Scarpe
|
13
|
+
class Components::ModularLogImpl
|
14
|
+
include Shoes::Log # for constants
|
15
|
+
|
16
|
+
def logger_for_component(component)
|
17
|
+
Logging.logger[component]
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def name_to_severity(data)
|
23
|
+
case data
|
24
|
+
when "debug"
|
25
|
+
:debug
|
26
|
+
when "info"
|
27
|
+
:info
|
28
|
+
when "warn"
|
29
|
+
:warn
|
30
|
+
when "err", "error"
|
31
|
+
:error
|
32
|
+
when "fatal"
|
33
|
+
:fatal
|
34
|
+
else
|
35
|
+
raise Shoes::Errors::InvalidAttributeValueError, "Don't know how to treat #{data.inspect} as a logger severity!"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def json_to_appender(data)
|
40
|
+
case data.downcase
|
41
|
+
when "stdout"
|
42
|
+
Logging.appenders.stdout layout: @custom_log_layout
|
43
|
+
when "stderr"
|
44
|
+
Logging.appenders.stderr layout: @custom_log_layout
|
45
|
+
when String
|
46
|
+
Logging.appenders.file data, layout: @custom_log_layout
|
47
|
+
else
|
48
|
+
raise Shoes::Errors::InvalidAttributeValueError, "Don't know how to convert #{data.inspect} to an appender!"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def json_configure_logger(logger, data)
|
53
|
+
case data
|
54
|
+
in String
|
55
|
+
sev = name_to_severity(data)
|
56
|
+
logger.level = sev
|
57
|
+
in [level, *locations]
|
58
|
+
if logger.name != "root"
|
59
|
+
# The Logging gem doesn't have an additive property on the root logger
|
60
|
+
logger.additive = false # Don't also log to parent/root loggers
|
61
|
+
end
|
62
|
+
|
63
|
+
logger.appenders = locations.map { |where| json_to_appender(where) }
|
64
|
+
|
65
|
+
logger.level = name_to_severity(level)
|
66
|
+
else
|
67
|
+
raise Shoes::Errors::InvalidAttributeValueError, "Don't know how to use #{data.inspect} to specify a logger!"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def freeze_log_config(log_config)
|
72
|
+
log_config.each do |k, v|
|
73
|
+
k.freeze
|
74
|
+
v.freeze
|
75
|
+
v.each(&:freeze) if v.is_a?(Array)
|
76
|
+
end
|
77
|
+
log_config.freeze
|
78
|
+
end
|
79
|
+
|
80
|
+
public
|
81
|
+
|
82
|
+
def configure_logger(log_config)
|
83
|
+
# TODO: custom coloring? https://github.com/TwP/logging/blob/master/examples/colorization.rb
|
84
|
+
@custom_log_layout = Logging.layouts.pattern pattern: '[%r] %-5l %c: %m\n'
|
85
|
+
|
86
|
+
if log_config.is_a?(String) && File.exist?(log_config)
|
87
|
+
log_config = JSON.load_file(log_config)
|
88
|
+
end
|
89
|
+
|
90
|
+
log_config = freeze_log_config(log_config) unless log_config.nil?
|
91
|
+
@current_log_config = log_config # Save a copy for later
|
92
|
+
|
93
|
+
Logging.reset # Reset all Logging settings to defaults
|
94
|
+
Logging.reopen # For log-reconfig (e.g. test failures), often important to *not* store an open handle to a moved file
|
95
|
+
return if log_config.nil?
|
96
|
+
|
97
|
+
Logging.logger.root.appenders = [Logging.appenders.stdout]
|
98
|
+
|
99
|
+
default_logger = log_config[DEFAULT_COMPONENT] || "info"
|
100
|
+
json_configure_logger(Logging.logger.root, default_logger)
|
101
|
+
|
102
|
+
log_config.each do |component, logger_data|
|
103
|
+
next if component == DEFAULT_COMPONENT
|
104
|
+
|
105
|
+
sublogger = Logging.logger[component]
|
106
|
+
json_configure_logger(sublogger, logger_data)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
#Shoes::Log.instance = Scarpe::Components::ModularLogImpl.new
|
113
|
+
#Shoes::Log.configure_logger(Shoes::Log::DEFAULT_LOG_CONFIG)
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "shoes/log"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module Scarpe; end
|
7
|
+
module Scarpe::Components; end
|
8
|
+
class Scarpe::Components::PrintLogImpl
|
9
|
+
include Shoes::Log # for constants
|
10
|
+
|
11
|
+
class PrintLogger
|
12
|
+
class << self
|
13
|
+
attr_accessor :silence
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(component_name)
|
17
|
+
@comp_name = component_name
|
18
|
+
end
|
19
|
+
|
20
|
+
def error(msg)
|
21
|
+
puts "#{@comp_name} error: #{msg}" unless PrintLogger.silence
|
22
|
+
end
|
23
|
+
|
24
|
+
def warn(msg)
|
25
|
+
puts "#{@comp_name} warn: #{msg}" unless PrintLogger.silence
|
26
|
+
end
|
27
|
+
|
28
|
+
def debug(msg)
|
29
|
+
puts "#{@comp_name} debug: #{msg}" unless PrintLogger.silence
|
30
|
+
end
|
31
|
+
|
32
|
+
def info(msg)
|
33
|
+
puts "#{@comp_name} info: #{msg}" unless PrintLogger.silence
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def logger_for_component(component)
|
38
|
+
PrintLogger.new(component.to_s)
|
39
|
+
end
|
40
|
+
|
41
|
+
def configure_logger(log_config)
|
42
|
+
# For now, ignore
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
#Shoes::Log.instance = Scarpe::PrintLogImpl.new
|
47
|
+
#Shoes::Log.configure_logger(Shoes::Log::DEFAULT_LOG_CONFIG)
|
@@ -1,42 +1,56 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# for
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# and we
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
|
27
|
-
|
3
|
+
module Scarpe; end
|
4
|
+
module Scarpe::Components; end
|
5
|
+
module Scarpe
|
6
|
+
# Scarpe::Promise is a promises library, but one with no form of built-in
|
7
|
+
# concurrency. Instead, promise callbacks are executed synchronously.
|
8
|
+
# Even execution is usually synchronous, but can also be handled manually
|
9
|
+
# for forms of execution not controlled in Ruby (like Webview.)
|
10
|
+
#
|
11
|
+
# Funny thing... We need promises as an API concept since we have a JS event
|
12
|
+
# loop doing its thing, and we need to respond to actions that it takes.
|
13
|
+
# But there's not really a Ruby implementation of Promises *without* an
|
14
|
+
# attached form of concurrency. So here we are, writing our own :-/
|
15
|
+
#
|
16
|
+
# In theory you could probably write some kind of "no-op thread pool"
|
17
|
+
# for the ruby-concurrency gem, pass it manually to every promise we
|
18
|
+
# created and then raise an exception any time we tried to do something
|
19
|
+
# in the background. That's probably more code than writing our own, though,
|
20
|
+
# and we'd be fighting it constantly.
|
21
|
+
#
|
22
|
+
# This class is inspired by concurrent-ruby [Promise](https://ruby-concurrency.github.io/concurrent-ruby/1.1.5/Concurrent/Promise.html)
|
23
|
+
# which is inspired by Javascript Promises, which is what we actually need
|
24
|
+
# for our use case. We can't easily tell when our WebView begins processing
|
25
|
+
# our request, which removes the :processing state. This can be used for
|
26
|
+
# executing JS, but also generally waiting on events.
|
27
|
+
#
|
28
|
+
# We don't fully control ordering here, so it *is* conceivable that a
|
29
|
+
# child waiting on a parent can be randomly fulfilled, even if we didn't
|
30
|
+
# expect it. We don't consider that an error. Similarly, we'll call
|
31
|
+
# on_scheduled callbacks if a promise is fulfilled, even though we
|
32
|
+
# never explicitly scheduled it. If a promise is *rejected* without
|
33
|
+
# ever being scheduled, we won't call those callbacks.
|
28
34
|
class Promise
|
29
|
-
include
|
35
|
+
include Shoes::Log
|
30
36
|
|
37
|
+
# The unscheduled promise state means it's waiting on a parent promise that
|
38
|
+
# hasn't completed yet. The pending state means it's waiting to execute.
|
39
|
+
# Fulfilled means it has completed successfully and returned a value,
|
40
|
+
# while rejected means it has failed, normally producing a reason.
|
31
41
|
PROMISE_STATES = [:unscheduled, :pending, :fulfilled, :rejected]
|
32
42
|
|
43
|
+
# The state of the promise, which should be one of PROMISE_STATES
|
33
44
|
attr_reader :state
|
45
|
+
|
46
|
+
# The parent promises of this promise, sometimes an empty array
|
34
47
|
attr_reader :parents
|
48
|
+
|
49
|
+
# If the promise is fulfilled, this is the value returned
|
35
50
|
attr_reader :returned_value
|
36
|
-
attr_reader :reason
|
37
51
|
|
38
|
-
#
|
39
|
-
|
52
|
+
# If the promise is rejected, this is the reason, sometimes an exception
|
53
|
+
attr_reader :reason
|
40
54
|
|
41
55
|
# Create a promise and then instantly fulfill it.
|
42
56
|
def self.fulfilled(return_val = nil, parents: [], &block)
|
@@ -52,19 +66,19 @@ class Scarpe
|
|
52
66
|
p
|
53
67
|
end
|
54
68
|
|
55
|
-
#
|
56
|
-
|
69
|
+
# Fulfill the promise, setting the returned_value to value
|
57
70
|
def fulfilled!(value = nil)
|
58
71
|
set_state(:fulfilled, value)
|
59
72
|
end
|
60
73
|
|
74
|
+
# Reject the promise, setting the reason to reason
|
61
75
|
def rejected!(reason = nil)
|
62
76
|
set_state(:rejected, reason)
|
63
77
|
end
|
64
78
|
|
79
|
+
# Create a new promise with this promise as a parent. It runs the
|
80
|
+
# specified code in block when scheduled.
|
65
81
|
def then(&block)
|
66
|
-
# Create a new promise. It's waiting on us. It runs the
|
67
|
-
# specified code when scheduled.
|
68
82
|
Promise.new(parents: [self], &block)
|
69
83
|
end
|
70
84
|
|
@@ -73,7 +87,15 @@ class Scarpe
|
|
73
87
|
# the prettiest. However, they ensure that guarantees are made
|
74
88
|
# and so on, so they're great as plumbing under the syntactic
|
75
89
|
# sugar above.
|
76
|
-
|
90
|
+
#
|
91
|
+
# Note that the state passed in may not be the actual initial
|
92
|
+
# state. If a parent is rejected, the state will become
|
93
|
+
# rejected. If no parents are waiting or failed then a state
|
94
|
+
# of nil or :unscheduled will become :pending.
|
95
|
+
#
|
96
|
+
# @param state [Symbol] One of PROMISE_STATES for the initial state
|
97
|
+
# @param parents [Array] A list of promises that must be fulfilled before this one is scheduled
|
98
|
+
# @yield A block that executes when this promise is scheduled - when its parents, if any, are all fulfilled
|
77
99
|
def initialize(state: nil, parents: [], &scheduler)
|
78
100
|
log_init("Promise")
|
79
101
|
|
@@ -131,15 +153,43 @@ class Scarpe
|
|
131
153
|
end
|
132
154
|
end
|
133
155
|
|
156
|
+
# Return true if the Promise is either fulfilled or rejected.
|
157
|
+
#
|
158
|
+
# @return [Boolean] true if the promise is fulfilled or rejected
|
134
159
|
def complete?
|
135
160
|
@state == :fulfilled || @state == :rejected
|
136
161
|
end
|
137
162
|
|
163
|
+
# Return true if the promise is already fulfilled.
|
164
|
+
#
|
165
|
+
# @return [Boolean] true if the promise is fulfilled
|
166
|
+
def fulfilled?
|
167
|
+
@state == :fulfilled
|
168
|
+
end
|
169
|
+
|
170
|
+
# Return true if the promise is already rejected.
|
171
|
+
#
|
172
|
+
# @return [Boolean] true if the promise is rejected
|
173
|
+
def rejected?
|
174
|
+
@state == :rejected
|
175
|
+
end
|
176
|
+
|
177
|
+
# An inspect method to give slightly smaller output, for ease of reading in irb
|
178
|
+
def inspect
|
179
|
+
"#<Scarpe::Promise:#{object_id} " +
|
180
|
+
"@state=#{@state.inspect} @parents=#{@parents.inspect} " +
|
181
|
+
"@waiting_on=#{@waiting_on.inspect} @on_fulfilled=#{@on_fulfilled.size} " +
|
182
|
+
"@on_rejected=#{@on_rejected.size} @on_scheduled=#{@on_scheduled.size} " +
|
183
|
+
"@scheduler=#{@scheduler ? "Y" : "N"} @executor=#{@executor ? "Y" : "N"} " +
|
184
|
+
"@returned_value=#{@returned_value.inspect} @reason=#{@reason.inspect}" +
|
185
|
+
">"
|
186
|
+
end
|
187
|
+
|
138
188
|
# These promises are mostly designed for external execution.
|
139
189
|
# You could put together your own thread-pool, or use RPC,
|
140
190
|
# a WebView, a database or similar source of external calculation.
|
141
|
-
# But in
|
142
|
-
# In those cases, you can register an executor
|
191
|
+
# But in many cases it's reasonable to execute locally.
|
192
|
+
# In those cases, you can register an executor which will be
|
143
193
|
# called when the promise is ready to execute but has not yet
|
144
194
|
# done so. Registering an executor on a promise that is
|
145
195
|
# already fulfilled is an error. Registering an executor on
|
@@ -148,7 +198,7 @@ class Scarpe
|
|
148
198
|
case @state
|
149
199
|
when :fulfilled
|
150
200
|
# Should this be a no-op instead?
|
151
|
-
raise "Registering an executor on an already fulfilled promise means it will never run!"
|
201
|
+
raise Scarpe::NoOperationError, "Registering an executor on an already fulfilled promise means it will never run!"
|
152
202
|
when :rejected
|
153
203
|
return
|
154
204
|
when :unscheduled
|
@@ -157,7 +207,7 @@ class Scarpe
|
|
157
207
|
@executor = block
|
158
208
|
call_executor
|
159
209
|
else
|
160
|
-
raise "Internal error, illegal state!"
|
210
|
+
raise Scarpe::InternalError, "Internal error, illegal state!"
|
161
211
|
end
|
162
212
|
|
163
213
|
self
|
@@ -172,16 +222,16 @@ class Scarpe
|
|
172
222
|
|
173
223
|
# First, filter out illegal input
|
174
224
|
unless PROMISE_STATES.include?(old_state)
|
175
|
-
raise "Internal Promise error! Internal state was #{old_state.inspect}! Legal states: #{PROMISE_STATES.inspect}"
|
225
|
+
raise Scarpe::InternalError, "Internal Promise error! Internal state was #{old_state.inspect}! Legal states: #{PROMISE_STATES.inspect}"
|
176
226
|
end
|
177
227
|
|
178
228
|
unless PROMISE_STATES.include?(new_state)
|
179
|
-
raise "Internal Promise error! Internal state was set to #{new_state.inspect}! " +
|
229
|
+
raise Scarpe::InternalError, "Internal Promise error! Internal state was set to #{new_state.inspect}! " +
|
180
230
|
"Legal states: #{PROMISE_STATES.inspect}"
|
181
231
|
end
|
182
232
|
|
183
233
|
if new_state != :fulfilled && new_state != :rejected && !value_or_reason.nil?
|
184
|
-
raise "Internal promise error! Non-completed state transitions should not specify a value or reason!"
|
234
|
+
raise Scarpe::InternalError, "Internal promise error! Non-completed state transitions should not specify a value or reason!"
|
185
235
|
end
|
186
236
|
|
187
237
|
# Here's our state-transition grid for what we're doing here.
|
@@ -204,11 +254,11 @@ class Scarpe
|
|
204
254
|
|
205
255
|
# Transitioning to any *different* state after being fulfilled or rejected? Nope. Those states are final.
|
206
256
|
if complete?
|
207
|
-
raise "Internal Promise error! Trying to change state from #{old_state.inspect} to #{new_state.inspect}!"
|
257
|
+
raise Scarpe::InternalError, "Internal Promise error! Trying to change state from #{old_state.inspect} to #{new_state.inspect}!"
|
208
258
|
end
|
209
259
|
|
210
260
|
if old_state == :pending && new_state == :unscheduled
|
211
|
-
raise "Can't change state from :pending to :unscheduled! Scheduling is not reversible!"
|
261
|
+
raise Shoes::Errors::InvalidAttributeValueError, "Can't change state from :pending to :unscheduled! Scheduling is not reversible!"
|
212
262
|
end
|
213
263
|
|
214
264
|
# The next three checks should all be followed by calling handlers for the newly-changed state.
|
@@ -291,7 +341,7 @@ class Scarpe
|
|
291
341
|
@on_scheduled.each { |h| h.call(*@parents.map(&:returned_value)) }
|
292
342
|
@on_scheduled = []
|
293
343
|
else
|
294
|
-
raise "Internal error! Trying to call handlers for #{state.inspect}!"
|
344
|
+
raise Scarpe::InternalError, "Internal error! Trying to call handlers for #{state.inspect}!"
|
295
345
|
end
|
296
346
|
end
|
297
347
|
|
@@ -317,7 +367,7 @@ class Scarpe
|
|
317
367
|
end
|
318
368
|
|
319
369
|
def call_executor
|
320
|
-
raise("Internal error! Should not call_executor with no executor!") unless @executor
|
370
|
+
raise(Scarpe::InternalError, "Internal error! Should not call_executor with no executor!") unless @executor
|
321
371
|
|
322
372
|
begin
|
323
373
|
result = @executor.call(*@parents.map(&:returned_value))
|
@@ -332,9 +382,14 @@ class Scarpe
|
|
332
382
|
|
333
383
|
public
|
334
384
|
|
385
|
+
# Register a handler to be called when the promise is fulfilled.
|
386
|
+
# If called on a fulfilled promise, the handler will be called immediately.
|
387
|
+
#
|
388
|
+
# @yield Handler to be called on fulfilled
|
389
|
+
# @return [Scarpe::Promise] self
|
335
390
|
def on_fulfilled(&handler)
|
336
391
|
unless handler
|
337
|
-
raise "You must pass a block to on_fulfilled!"
|
392
|
+
raise Shoes::Errors::InvalidAttributeValueError, "You must pass a block to on_fulfilled!"
|
338
393
|
end
|
339
394
|
|
340
395
|
case @state
|
@@ -349,9 +404,14 @@ class Scarpe
|
|
349
404
|
self
|
350
405
|
end
|
351
406
|
|
407
|
+
# Register a handler to be called when the promise is rejected.
|
408
|
+
# If called on a rejected promise, the handler will be called immediately.
|
409
|
+
#
|
410
|
+
# @yield Handler to be called on rejected
|
411
|
+
# @return [Scarpe::Promise] self
|
352
412
|
def on_rejected(&handler)
|
353
413
|
unless handler
|
354
|
-
raise "You must pass a block to on_rejected!"
|
414
|
+
raise Shoes::Errors::InvalidAttributeValueError, "You must pass a block to on_rejected!"
|
355
415
|
end
|
356
416
|
|
357
417
|
case @state
|
@@ -366,9 +426,15 @@ class Scarpe
|
|
366
426
|
self
|
367
427
|
end
|
368
428
|
|
429
|
+
# Register a handler to be called when the promise is scheduled.
|
430
|
+
# If called on a promise that was scheduled earlier, the handler
|
431
|
+
# will be called immediately.
|
432
|
+
#
|
433
|
+
# @yield Handler to be called on scheduled
|
434
|
+
# @return [Scarpe::Promise] self
|
369
435
|
def on_scheduled(&handler)
|
370
436
|
unless handler
|
371
|
-
raise "You must pass a block to on_scheduled!"
|
437
|
+
raise Shoes::Errors::InvalidAttributeValueError, "You must pass a block to on_scheduled!"
|
372
438
|
end
|
373
439
|
|
374
440
|
# Add a pending handler or call it now
|
@@ -384,4 +450,5 @@ class Scarpe
|
|
384
450
|
self
|
385
451
|
end
|
386
452
|
end
|
453
|
+
Components::Promise = Promise
|
387
454
|
end
|