convenient_service 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.dockerignore +1 -0
- data/.gem_release.yml +23 -0
- data/.github/workflows/cd.yml +54 -0
- data/.github/workflows/ci.yml +190 -0
- data/.gitignore +34 -0
- data/.inch.yml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +45 -0
- data/.rubocop_rspec.yml +58 -0
- data/.ruby-version +1 -0
- data/.tool-versions +1 -0
- data/.yardopts +13 -0
- data/Appraisals +124 -0
- data/CHANGELOG.md +1 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +55 -0
- data/ROADMAP.md +41 -0
- data/Rakefile +54 -0
- data/Taskfile.yml +316 -0
- data/convenient_service.gemspec +52 -0
- data/coverage/.gitkeep +0 -0
- data/docker/2.7/Dockerfile +73 -0
- data/docker/3.0/Dockerfile +73 -0
- data/docker/3.1/Dockerfile +73 -0
- data/env.rb +19 -0
- data/lib/convenient_service/common/plugins/aliases.rb +8 -0
- data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/concern.rb +21 -0
- data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/middleware.rb +29 -0
- data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment.rb +4 -0
- data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_dry_initializer/concern.rb +21 -0
- data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_dry_initializer.rb +3 -0
- data/lib/convenient_service/common/plugins/caches_constructor_params/concern.rb +22 -0
- data/lib/convenient_service/common/plugins/caches_constructor_params/entities/constructor_params.rb +34 -0
- data/lib/convenient_service/common/plugins/caches_constructor_params/entities.rb +3 -0
- data/lib/convenient_service/common/plugins/caches_constructor_params/middleware.rb +17 -0
- data/lib/convenient_service/common/plugins/caches_constructor_params.rb +5 -0
- data/lib/convenient_service/common/plugins/caches_return_value/entities/key.rb +79 -0
- data/lib/convenient_service/common/plugins/caches_return_value/entities.rb +3 -0
- data/lib/convenient_service/common/plugins/caches_return_value/middleware.rb +17 -0
- data/lib/convenient_service/common/plugins/caches_return_value.rb +4 -0
- data/lib/convenient_service/common/plugins/can_be_copied/concern.rb +33 -0
- data/lib/convenient_service/common/plugins/can_be_copied.rb +3 -0
- data/lib/convenient_service/common/plugins/has_around_callbacks/concern.rb +19 -0
- data/lib/convenient_service/common/plugins/has_around_callbacks/errors.rb +29 -0
- data/lib/convenient_service/common/plugins/has_around_callbacks/middleware.rb +113 -0
- data/lib/convenient_service/common/plugins/has_around_callbacks.rb +5 -0
- data/lib/convenient_service/common/plugins/has_attributes/using_active_model_attributes/concern.rb +19 -0
- data/lib/convenient_service/common/plugins/has_attributes/using_active_model_attributes/patches/active_model_attributes.rb +45 -0
- data/lib/convenient_service/common/plugins/has_attributes/using_active_model_attributes/patches.rb +3 -0
- data/lib/convenient_service/common/plugins/has_attributes/using_active_model_attributes.rb +4 -0
- data/lib/convenient_service/common/plugins/has_callbacks/concern.rb +36 -0
- data/lib/convenient_service/common/plugins/has_callbacks/entities/callback.rb +59 -0
- data/lib/convenient_service/common/plugins/has_callbacks/entities/callback_collection.rb +35 -0
- data/lib/convenient_service/common/plugins/has_callbacks/entities/type/class_methods.rb +26 -0
- data/lib/convenient_service/common/plugins/has_callbacks/entities/type.rb +50 -0
- data/lib/convenient_service/common/plugins/has_callbacks/entities/type_collection.rb +33 -0
- data/lib/convenient_service/common/plugins/has_callbacks/entities.rb +6 -0
- data/lib/convenient_service/common/plugins/has_callbacks/middleware.rb +21 -0
- data/lib/convenient_service/common/plugins/has_callbacks.rb +5 -0
- data/lib/convenient_service/common/plugins/has_constructor/concern.rb +18 -0
- data/lib/convenient_service/common/plugins/has_constructor.rb +3 -0
- data/lib/convenient_service/common/plugins/has_internals/commands/create_internals_class.rb +56 -0
- data/lib/convenient_service/common/plugins/has_internals/commands.rb +3 -0
- data/lib/convenient_service/common/plugins/has_internals/concern.rb +28 -0
- data/lib/convenient_service/common/plugins/has_internals/entities/internals/concern.rb +25 -0
- data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/concern.rb +30 -0
- data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/entities/cache.rb +81 -0
- data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/entities.rb +3 -0
- data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache.rb +4 -0
- data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins.rb +3 -0
- data/lib/convenient_service/common/plugins/has_internals/entities/internals.rb +18 -0
- data/lib/convenient_service/common/plugins/has_internals/entities.rb +3 -0
- data/lib/convenient_service/common/plugins/has_internals.rb +5 -0
- data/lib/convenient_service/common/plugins/normalizes_env/middleware.rb +29 -0
- data/lib/convenient_service/common/plugins/normalizes_env.rb +3 -0
- data/lib/convenient_service/common/plugins.rb +16 -0
- data/lib/convenient_service/common.rb +3 -0
- data/lib/convenient_service/configs/aliases.rb +7 -0
- data/lib/convenient_service/configs/standard.rb +193 -0
- data/lib/convenient_service/configs.rb +5 -0
- data/lib/convenient_service/core/aliases.rb +9 -0
- data/lib/convenient_service/core/class_methods.rb +81 -0
- data/lib/convenient_service/core/entities/classic_middleware.rb +32 -0
- data/lib/convenient_service/core/entities/config/entities/concerns/entities/default_concern.rb +18 -0
- data/lib/convenient_service/core/entities/config/entities/concerns/entities/middleware/commands/cast_middleware.rb +78 -0
- data/lib/convenient_service/core/entities/config/entities/concerns/entities/middleware/commands.rb +3 -0
- data/lib/convenient_service/core/entities/config/entities/concerns/entities/middleware.rb +103 -0
- data/lib/convenient_service/core/entities/config/entities/concerns/entities/stack.rb +206 -0
- data/lib/convenient_service/core/entities/config/entities/concerns/entities.rb +5 -0
- data/lib/convenient_service/core/entities/config/entities/concerns.rb +216 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/commands/generate_stack_name.rb +95 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/commands.rb +3 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands/cast_caller.rb +72 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands/define_method_middlewares_caller.rb +134 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands.rb +4 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/concern/class_methods.rb +29 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/concern/instance_methods.rb +66 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/concern.rb +32 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller.rb +25 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/chain.rb +71 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/commands/cast_container.rb +76 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/commands/resolve_methods_middlewares_callers.rb +72 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/commands.rb +4 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/concern/class_methods.rb +29 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/concern/instance_methods.rb +165 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/concern.rb +32 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container.rb +22 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middleware.rb +114 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/stack.rb +193 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities.rb +7 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares.rb +182 -0
- data/lib/convenient_service/core/entities/config/entities.rb +4 -0
- data/lib/convenient_service/core/entities/config/errors.rb +27 -0
- data/lib/convenient_service/core/entities/config.rb +147 -0
- data/lib/convenient_service/core/entities.rb +4 -0
- data/lib/convenient_service/core/instance_methods.rb +54 -0
- data/lib/convenient_service/core.rb +19 -0
- data/lib/convenient_service/dependencies/built_in.rb +36 -0
- data/lib/convenient_service/dependencies/extractions/active_support_concern/concern.rb +258 -0
- data/lib/convenient_service/dependencies/extractions/active_support_concern.rb +16 -0
- data/lib/convenient_service/dependencies/extractions/b.rb +12 -0
- data/lib/convenient_service/dependencies/extractions/byebug_syntax_highlighting.rb +58 -0
- data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/builder.rb +194 -0
- data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/logger.rb +60 -0
- data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/runner.rb +79 -0
- data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware.rb +8 -0
- data/lib/convenient_service/dependencies/extractions/ruby_middleware.rb +15 -0
- data/lib/convenient_service/dependencies/extractions.rb +10 -0
- data/lib/convenient_service/dependencies.rb +133 -0
- data/lib/convenient_service/error.rb +16 -0
- data/lib/convenient_service/examples/dry/gemfile/dry_service/config.rb +43 -0
- data/lib/convenient_service/examples/dry/gemfile/dry_service.rb +3 -0
- data/lib/convenient_service/examples/dry/gemfile/services/assert_file_exists.rb +29 -0
- data/lib/convenient_service/examples/dry/gemfile/services/assert_file_not_empty.rb +29 -0
- data/lib/convenient_service/examples/dry/gemfile/services/assert_node_available.rb +26 -0
- data/lib/convenient_service/examples/dry/gemfile/services/assert_npm_package_available.rb +39 -0
- data/lib/convenient_service/examples/dry/gemfile/services/assert_valid_ruby_syntax.rb +41 -0
- data/lib/convenient_service/examples/dry/gemfile/services/format.rb +37 -0
- data/lib/convenient_service/examples/dry/gemfile/services/format_body.rb +93 -0
- data/lib/convenient_service/examples/dry/gemfile/services/format_gems_with_envs.rb +96 -0
- data/lib/convenient_service/examples/dry/gemfile/services/format_gems_without_envs.rb +84 -0
- data/lib/convenient_service/examples/dry/gemfile/services/format_header.rb +74 -0
- data/lib/convenient_service/examples/dry/gemfile/services/parse_content.rb +93 -0
- data/lib/convenient_service/examples/dry/gemfile/services/print_shell_command.rb +37 -0
- data/lib/convenient_service/examples/dry/gemfile/services/read_file_content.rb +31 -0
- data/lib/convenient_service/examples/dry/gemfile/services/run_shell.rb +40 -0
- data/lib/convenient_service/examples/dry/gemfile/services/strip_comments.rb +109 -0
- data/lib/convenient_service/examples/dry/gemfile/services.rb +17 -0
- data/lib/convenient_service/examples/dry/gemfile.rb +24 -0
- data/lib/convenient_service/examples/rails/gemfile/rails_service/config.rb +54 -0
- data/lib/convenient_service/examples/rails/gemfile/rails_service.rb +3 -0
- data/lib/convenient_service/examples/rails/gemfile/services/assert_file_exists.rb +25 -0
- data/lib/convenient_service/examples/rails/gemfile/services/assert_file_not_empty.rb +25 -0
- data/lib/convenient_service/examples/rails/gemfile/services/assert_node_available.rb +26 -0
- data/lib/convenient_service/examples/rails/gemfile/services/assert_npm_package_available.rb +35 -0
- data/lib/convenient_service/examples/rails/gemfile/services/assert_valid_ruby_syntax.rb +35 -0
- data/lib/convenient_service/examples/rails/gemfile/services/format.rb +37 -0
- data/lib/convenient_service/examples/rails/gemfile/services/format_body.rb +79 -0
- data/lib/convenient_service/examples/rails/gemfile/services/format_gems_with_envs.rb +82 -0
- data/lib/convenient_service/examples/rails/gemfile/services/format_gems_without_envs.rb +70 -0
- data/lib/convenient_service/examples/rails/gemfile/services/format_header.rb +69 -0
- data/lib/convenient_service/examples/rails/gemfile/services/parse_content.rb +89 -0
- data/lib/convenient_service/examples/rails/gemfile/services/print_shell_command.rb +33 -0
- data/lib/convenient_service/examples/rails/gemfile/services/read_file_content.rb +27 -0
- data/lib/convenient_service/examples/rails/gemfile/services/run_shell.rb +35 -0
- data/lib/convenient_service/examples/rails/gemfile/services/strip_comments.rb +107 -0
- data/lib/convenient_service/examples/rails/gemfile/services.rb +17 -0
- data/lib/convenient_service/examples/rails/gemfile.rb +24 -0
- data/lib/convenient_service/examples/standard/gemfile/services/assert_file_exists.rb +30 -0
- data/lib/convenient_service/examples/standard/gemfile/services/assert_file_not_empty.rb +30 -0
- data/lib/convenient_service/examples/standard/gemfile/services/assert_node_available.rb +35 -0
- data/lib/convenient_service/examples/standard/gemfile/services/assert_npm_package_available.rb +48 -0
- data/lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb +39 -0
- data/lib/convenient_service/examples/standard/gemfile/services/format.rb +39 -0
- data/lib/convenient_service/examples/standard/gemfile/services/format_body.rb +83 -0
- data/lib/convenient_service/examples/standard/gemfile/services/format_gems_with_envs.rb +86 -0
- data/lib/convenient_service/examples/standard/gemfile/services/format_gems_without_envs.rb +74 -0
- data/lib/convenient_service/examples/standard/gemfile/services/format_header.rb +66 -0
- data/lib/convenient_service/examples/standard/gemfile/services/parse_content.rb +101 -0
- data/lib/convenient_service/examples/standard/gemfile/services/print_shell_command.rb +38 -0
- data/lib/convenient_service/examples/standard/gemfile/services/read_file_content.rb +39 -0
- data/lib/convenient_service/examples/standard/gemfile/services/run_shell.rb +37 -0
- data/lib/convenient_service/examples/standard/gemfile/services/strip_comments.rb +111 -0
- data/lib/convenient_service/examples/standard/gemfile/services.rb +17 -0
- data/lib/convenient_service/examples/standard/gemfile.rb +23 -0
- data/lib/convenient_service/logger.rb +70 -0
- data/lib/convenient_service/rspec/helpers/custom/ignoring_error.rb +29 -0
- data/lib/convenient_service/rspec/helpers/custom/stub_service/entities/result_spec.rb +119 -0
- data/lib/convenient_service/rspec/helpers/custom/stub_service/entities/stubbed_service.rb +99 -0
- data/lib/convenient_service/rspec/helpers/custom/stub_service/entities.rb +4 -0
- data/lib/convenient_service/rspec/helpers/custom/stub_service.rb +26 -0
- data/lib/convenient_service/rspec/helpers/custom/wrap_method/entities/wrapped_method.rb +80 -0
- data/lib/convenient_service/rspec/helpers/custom/wrap_method/entities.rb +3 -0
- data/lib/convenient_service/rspec/helpers/custom/wrap_method/errors.rb +25 -0
- data/lib/convenient_service/rspec/helpers/custom/wrap_method.rb +27 -0
- data/lib/convenient_service/rspec/helpers/custom.rb +5 -0
- data/lib/convenient_service/rspec/helpers/ignoring_error.rb +13 -0
- data/lib/convenient_service/rspec/helpers/stub_service.rb +29 -0
- data/lib/convenient_service/rspec/helpers/wrap_method.rb +13 -0
- data/lib/convenient_service/rspec/helpers.rb +21 -0
- data/lib/convenient_service/rspec/matchers/be_descendant_of.rb +13 -0
- data/lib/convenient_service/rspec/matchers/be_direct_descendant_of.rb +13 -0
- data/lib/convenient_service/rspec/matchers/cache_its_value.rb +13 -0
- data/lib/convenient_service/rspec/matchers/call_chain_next.rb +13 -0
- data/lib/convenient_service/rspec/matchers/custom/be_descendant_of.rb +55 -0
- data/lib/convenient_service/rspec/matchers/custom/be_direct_descendant_of.rb +55 -0
- data/lib/convenient_service/rspec/matchers/custom/cache_its_value.rb +55 -0
- data/lib/convenient_service/rspec/matchers/custom/call_chain_next.rb +150 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to.rb +255 -0
- data/lib/convenient_service/rspec/matchers/custom/extend_module.rb +40 -0
- data/lib/convenient_service/rspec/matchers/custom/have_abstract_method.rb +45 -0
- data/lib/convenient_service/rspec/matchers/custom/have_alias_method.rb +45 -0
- data/lib/convenient_service/rspec/matchers/custom/have_attr_accessor.rb +43 -0
- data/lib/convenient_service/rspec/matchers/custom/have_attr_reader.rb +47 -0
- data/lib/convenient_service/rspec/matchers/custom/have_attr_writer.rb +47 -0
- data/lib/convenient_service/rspec/matchers/custom/include_module.rb +40 -0
- data/lib/convenient_service/rspec/matchers/custom/prepend_module.rb +40 -0
- data/lib/convenient_service/rspec/matchers/custom/results/be_error.rb +153 -0
- data/lib/convenient_service/rspec/matchers/custom/results/be_failure.rb +120 -0
- data/lib/convenient_service/rspec/matchers/custom/results/be_success.rb +120 -0
- data/lib/convenient_service/rspec/matchers/custom/results.rb +5 -0
- data/lib/convenient_service/rspec/matchers/custom.rb +16 -0
- data/lib/convenient_service/rspec/matchers/delegate_to.rb +13 -0
- data/lib/convenient_service/rspec/matchers/extend_module.rb +13 -0
- data/lib/convenient_service/rspec/matchers/have_abstract_method.rb +13 -0
- data/lib/convenient_service/rspec/matchers/have_alias_method.rb +13 -0
- data/lib/convenient_service/rspec/matchers/have_attr_accessor.rb +13 -0
- data/lib/convenient_service/rspec/matchers/have_attr_reader.rb +13 -0
- data/lib/convenient_service/rspec/matchers/have_attr_writer.rb +13 -0
- data/lib/convenient_service/rspec/matchers/include_module.rb +13 -0
- data/lib/convenient_service/rspec/matchers/prepend_module.rb +13 -0
- data/lib/convenient_service/rspec/matchers/results/be_error.rb +15 -0
- data/lib/convenient_service/rspec/matchers/results/be_failure.rb +15 -0
- data/lib/convenient_service/rspec/matchers/results/be_success.rb +15 -0
- data/lib/convenient_service/rspec/matchers/results.rb +21 -0
- data/lib/convenient_service/rspec/matchers.rb +43 -0
- data/lib/convenient_service/rspec.rb +4 -0
- data/lib/convenient_service/service/plugins/aliases.rb +8 -0
- data/lib/convenient_service/service/plugins/can_recalculate_result/concern.rb +26 -0
- data/lib/convenient_service/service/plugins/can_recalculate_result.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/commands/create_result_class.rb +56 -0
- data/lib/convenient_service/service/plugins/has_result/commands.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/concern/class_methods.rb +82 -0
- data/lib/convenient_service/service/plugins/has_result/concern/instance_methods.rb +32 -0
- data/lib/convenient_service/service/plugins/has_result/concern.rb +22 -0
- data/lib/convenient_service/service/plugins/has_result/constants.rb +33 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/commands/cast_result_params.rb +33 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/commands.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/concern/instance_methods.rb +64 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/concern.rb +19 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/code/class_methods.rb +30 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/code.rb +45 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/data/class_methods.rb +28 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/data.rb +45 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/message/class_methods.rb +30 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/message.rb +41 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/status/class_methods.rb +30 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/status.rb +69 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities.rb +6 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/errors.rb +25 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_recalculate_result/concern.rb +27 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_recalculate_result.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax/concern/instance_methods.rb +28 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax/concern.rb +30 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/marks_result_status_as_checked/middleware.rb +25 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/marks_result_status_as_checked.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/raises_on_not_checked_result_status/errors.rb +31 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/raises_on_not_checked_result_status/middleware.rb +33 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/raises_on_not_checked_result_status.rb +4 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins.rb +6 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/structs/result_params.rb +17 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/structs.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result.rb +22 -0
- data/lib/convenient_service/service/plugins/has_result/entities.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/errors.rb +34 -0
- data/lib/convenient_service/service/plugins/has_result/middleware.rb +19 -0
- data/lib/convenient_service/service/plugins/has_result.rb +8 -0
- data/lib/convenient_service/service/plugins/has_result_method_steps/errors.rb +23 -0
- data/lib/convenient_service/service/plugins/has_result_method_steps/middleware.rb +37 -0
- data/lib/convenient_service/service/plugins/has_result_method_steps/services/method_step_config.rb +29 -0
- data/lib/convenient_service/service/plugins/has_result_method_steps/services/run_method_in_organizer.rb +30 -0
- data/lib/convenient_service/service/plugins/has_result_method_steps/services/run_own_method_in_organizer.rb +52 -0
- data/lib/convenient_service/service/plugins/has_result_method_steps/services.rb +5 -0
- data/lib/convenient_service/service/plugins/has_result_method_steps.rb +5 -0
- data/lib/convenient_service/service/plugins/has_result_params_validations/using_active_model_validations/concern.rb +19 -0
- data/lib/convenient_service/service/plugins/has_result_params_validations/using_active_model_validations/middleware.rb +35 -0
- data/lib/convenient_service/service/plugins/has_result_params_validations/using_active_model_validations.rb +4 -0
- data/lib/convenient_service/service/plugins/has_result_params_validations/using_dry_validation/concern.rb +22 -0
- data/lib/convenient_service/service/plugins/has_result_params_validations/using_dry_validation/middleware.rb +39 -0
- data/lib/convenient_service/service/plugins/has_result_params_validations/using_dry_validation.rb +4 -0
- data/lib/convenient_service/service/plugins/has_result_short_syntax/concern.rb +30 -0
- data/lib/convenient_service/service/plugins/has_result_short_syntax/error/commands/assert_args_count_lower_than_three.rb +25 -0
- data/lib/convenient_service/service/plugins/has_result_short_syntax/error/commands/assert_either_args_or_kwargs_are_passed.rb +26 -0
- data/lib/convenient_service/service/plugins/has_result_short_syntax/error/commands.rb +4 -0
- data/lib/convenient_service/service/plugins/has_result_short_syntax/error/errors.rb +46 -0
- data/lib/convenient_service/service/plugins/has_result_short_syntax/error/middleware.rb +27 -0
- data/lib/convenient_service/service/plugins/has_result_short_syntax/error.rb +5 -0
- data/lib/convenient_service/service/plugins/has_result_short_syntax/failure/commands/refute_kwargs_contain_data_and_extra_keys.rb +29 -0
- data/lib/convenient_service/service/plugins/has_result_short_syntax/failure/commands.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_short_syntax/failure/errors.rb +28 -0
- data/lib/convenient_service/service/plugins/has_result_short_syntax/failure/middleware.rb +19 -0
- data/lib/convenient_service/service/plugins/has_result_short_syntax/failure.rb +5 -0
- data/lib/convenient_service/service/plugins/has_result_short_syntax/success/commands/refute_kwargs_contain_data_and_extra_keys.rb +29 -0
- data/lib/convenient_service/service/plugins/has_result_short_syntax/success/commands.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_short_syntax/success/errors.rb +28 -0
- data/lib/convenient_service/service/plugins/has_result_short_syntax/success/middleware.rb +19 -0
- data/lib/convenient_service/service/plugins/has_result_short_syntax/success.rb +5 -0
- data/lib/convenient_service/service/plugins/has_result_short_syntax.rb +6 -0
- data/lib/convenient_service/service/plugins/has_result_steps/commands/create_step_class.rb +60 -0
- data/lib/convenient_service/service/plugins/has_result_steps/commands.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_steps/concern.rb +53 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method.rb +54 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_caller.rb +67 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_direction.rb +65 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_key.rb +71 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_name.rb +74 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/define_method_in_container.rb +55 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands.rb +8 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/concern/class_methods.rb +21 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/concern/instance_methods.rb +96 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/concern.rb +29 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/alias.rb +39 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/base.rb +49 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/proc.rb +42 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/raw.rb +42 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/usual.rb +39 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers.rb +7 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/directions/base.rb +33 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/directions/input.rb +31 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/directions/output.rb +31 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/directions.rb +5 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/key.rb +40 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/name.rb +40 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/values/raw.rb +48 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/values.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities.rb +7 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method/errors.rb +127 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/method.rb +20 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/service/class_methods.rb +32 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/service.rb +48 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/commands/cast_params.rb +61 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/commands/extract_params.rb +38 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/commands.rb +4 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/concern/instance_methods.rb +138 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/concern.rb +23 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/errors.rb +23 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/structs/params.rb +17 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/structs.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step.rb +20 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step_collection.rb +61 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities.rb +6 -0
- data/lib/convenient_service/service/plugins/has_result_steps/middleware.rb +26 -0
- data/lib/convenient_service/service/plugins/has_result_steps.rb +6 -0
- data/lib/convenient_service/service/plugins/raises_on_double_result/errors.rb +34 -0
- data/lib/convenient_service/service/plugins/raises_on_double_result/middleware.rb +33 -0
- data/lib/convenient_service/service/plugins/raises_on_double_result.rb +4 -0
- data/lib/convenient_service/service/plugins/wraps_result_in_db_transaction/middleware.rb +15 -0
- data/lib/convenient_service/service/plugins/wraps_result_in_db_transaction.rb +3 -0
- data/lib/convenient_service/service/plugins.rb +14 -0
- data/lib/convenient_service/service.rb +3 -0
- data/lib/convenient_service/specification.rb +21 -0
- data/lib/convenient_service/support/abstract_method/errors.rb +22 -0
- data/lib/convenient_service/support/abstract_method.rb +21 -0
- data/lib/convenient_service/support/castable/errors.rb +29 -0
- data/lib/convenient_service/support/castable.rb +44 -0
- data/lib/convenient_service/support/command.rb +25 -0
- data/lib/convenient_service/support/concern.rb +11 -0
- data/lib/convenient_service/support/copyable.rb +56 -0
- data/lib/convenient_service/support/delegate.rb +42 -0
- data/lib/convenient_service/support/finite_loop.rb +49 -0
- data/lib/convenient_service/support/middleware/stack_builder.rb +78 -0
- data/lib/convenient_service/support/middleware.rb +3 -0
- data/lib/convenient_service/support.rb +11 -0
- data/lib/convenient_service/utils/array/contain_exactly.rb +56 -0
- data/lib/convenient_service/utils/array/drop_while.rb +50 -0
- data/lib/convenient_service/utils/array/errors.rb +19 -0
- data/lib/convenient_service/utils/array/find_last.rb +38 -0
- data/lib/convenient_service/utils/array/find_yield.rb +93 -0
- data/lib/convenient_service/utils/array/keep_after.rb +41 -0
- data/lib/convenient_service/utils/array/merge.rb +77 -0
- data/lib/convenient_service/utils/array/rjust.rb +50 -0
- data/lib/convenient_service/utils/array/wrap.rb +40 -0
- data/lib/convenient_service/utils/array.rb +52 -0
- data/lib/convenient_service/utils/bool/to_bool.rb +37 -0
- data/lib/convenient_service/utils/bool.rb +15 -0
- data/lib/convenient_service/utils/hash/except.rb +46 -0
- data/lib/convenient_service/utils/hash.rb +15 -0
- data/lib/convenient_service/utils/method/defined.rb +49 -0
- data/lib/convenient_service/utils/method.rb +15 -0
- data/lib/convenient_service/utils/module/class_method_defined.rb +46 -0
- data/lib/convenient_service/utils/module/get_own_const.rb +60 -0
- data/lib/convenient_service/utils/module/get_own_instance_method.rb +81 -0
- data/lib/convenient_service/utils/module/has_own_instance_method.rb +77 -0
- data/lib/convenient_service/utils/module/instance_method_defined.rb +46 -0
- data/lib/convenient_service/utils/module.rb +40 -0
- data/lib/convenient_service/utils/object/resolve_type.rb +47 -0
- data/lib/convenient_service/utils/object.rb +19 -0
- data/lib/convenient_service/utils/proc/conjunct.rb +48 -0
- data/lib/convenient_service/utils/proc/exec_config.rb +136 -0
- data/lib/convenient_service/utils/proc.rb +20 -0
- data/lib/convenient_service/utils/string/camelize.rb +56 -0
- data/lib/convenient_service/utils/string.rb +15 -0
- data/lib/convenient_service/utils.rb +10 -0
- data/lib/convenient_service/version.rb +5 -0
- data/lib/convenient_service.rb +31 -0
- data/logo.png +0 -0
- metadata +738 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ConvenientService
|
|
4
|
+
module Dependencies
|
|
5
|
+
module Extractions
|
|
6
|
+
module ActiveSupportConcern
|
|
7
|
+
##
|
|
8
|
+
# https://github.com/marian13/rails/blob/v7.0.3.1/activesupport/lib/active_support/concern.rb
|
|
9
|
+
#
|
|
10
|
+
# A typical module looks like this:
|
|
11
|
+
#
|
|
12
|
+
# module M
|
|
13
|
+
# def self.included(base)
|
|
14
|
+
# base.extend ClassMethods
|
|
15
|
+
# base.class_eval do
|
|
16
|
+
# scope :disabled, -> { where(disabled: true) }
|
|
17
|
+
# end
|
|
18
|
+
# end
|
|
19
|
+
#
|
|
20
|
+
# module ClassMethods
|
|
21
|
+
# ...
|
|
22
|
+
# end
|
|
23
|
+
# end
|
|
24
|
+
#
|
|
25
|
+
# By using <tt>ActiveSupport::Concern</tt> the above module could instead be
|
|
26
|
+
# written as:
|
|
27
|
+
#
|
|
28
|
+
# require "active_support/concern"
|
|
29
|
+
#
|
|
30
|
+
# module M
|
|
31
|
+
# extend ActiveSupport::Concern
|
|
32
|
+
#
|
|
33
|
+
# included do
|
|
34
|
+
# scope :disabled, -> { where(disabled: true) }
|
|
35
|
+
# end
|
|
36
|
+
#
|
|
37
|
+
# class_methods do
|
|
38
|
+
# ...
|
|
39
|
+
# end
|
|
40
|
+
# end
|
|
41
|
+
#
|
|
42
|
+
# Moreover, it gracefully handles module dependencies. Given a +Foo+ module
|
|
43
|
+
# and a +Bar+ module which depends on the former, we would typically write the
|
|
44
|
+
# following:
|
|
45
|
+
#
|
|
46
|
+
# module Foo
|
|
47
|
+
# def self.included(base)
|
|
48
|
+
# base.class_eval do
|
|
49
|
+
# def self.method_injected_by_foo
|
|
50
|
+
# ...
|
|
51
|
+
# end
|
|
52
|
+
# end
|
|
53
|
+
# end
|
|
54
|
+
# end
|
|
55
|
+
#
|
|
56
|
+
# module Bar
|
|
57
|
+
# def self.included(base)
|
|
58
|
+
# base.method_injected_by_foo
|
|
59
|
+
# end
|
|
60
|
+
# end
|
|
61
|
+
#
|
|
62
|
+
# class Host
|
|
63
|
+
# include Foo # We need to include this dependency for Bar
|
|
64
|
+
# include Bar # Bar is the module that Host really needs
|
|
65
|
+
# end
|
|
66
|
+
#
|
|
67
|
+
# But why should +Host+ care about +Bar+'s dependencies, namely +Foo+? We
|
|
68
|
+
# could try to hide these from +Host+ directly including +Foo+ in +Bar+:
|
|
69
|
+
#
|
|
70
|
+
# module Bar
|
|
71
|
+
# include Foo
|
|
72
|
+
# def self.included(base)
|
|
73
|
+
# base.method_injected_by_foo
|
|
74
|
+
# end
|
|
75
|
+
# end
|
|
76
|
+
#
|
|
77
|
+
# class Host
|
|
78
|
+
# include Bar
|
|
79
|
+
# end
|
|
80
|
+
#
|
|
81
|
+
# Unfortunately this won't work, since when +Foo+ is included, its <tt>base</tt>
|
|
82
|
+
# is the +Bar+ module, not the +Host+ class. With <tt>ActiveSupport::Concern</tt>,
|
|
83
|
+
# module dependencies are properly resolved:
|
|
84
|
+
#
|
|
85
|
+
# require "active_support/concern"
|
|
86
|
+
#
|
|
87
|
+
# module Foo
|
|
88
|
+
# extend ActiveSupport::Concern
|
|
89
|
+
# included do
|
|
90
|
+
# def self.method_injected_by_foo
|
|
91
|
+
# ...
|
|
92
|
+
# end
|
|
93
|
+
# end
|
|
94
|
+
# end
|
|
95
|
+
#
|
|
96
|
+
# module Bar
|
|
97
|
+
# extend ActiveSupport::Concern
|
|
98
|
+
# include Foo
|
|
99
|
+
#
|
|
100
|
+
# included do
|
|
101
|
+
# self.method_injected_by_foo
|
|
102
|
+
# end
|
|
103
|
+
# end
|
|
104
|
+
#
|
|
105
|
+
# class Host
|
|
106
|
+
# include Bar # It works, now Bar takes care of its dependencies
|
|
107
|
+
# end
|
|
108
|
+
#
|
|
109
|
+
# === Prepending concerns
|
|
110
|
+
#
|
|
111
|
+
# Just like <tt>include</tt>, concerns also support <tt>prepend</tt> with a corresponding
|
|
112
|
+
# <tt>prepended do</tt> callback. <tt>module ClassMethods</tt> or <tt>class_methods do</tt> are
|
|
113
|
+
# prepended as well.
|
|
114
|
+
#
|
|
115
|
+
# <tt>prepend</tt> is also used for any dependencies.
|
|
116
|
+
module Concern
|
|
117
|
+
class MultipleIncludedBlocks < StandardError # :nodoc:
|
|
118
|
+
def initialize
|
|
119
|
+
super "Cannot define multiple 'included' blocks for a Concern"
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
class MultiplePrependBlocks < StandardError # :nodoc:
|
|
124
|
+
def initialize
|
|
125
|
+
super "Cannot define multiple 'prepended' blocks for a Concern"
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def self.extended(base) # :nodoc:
|
|
130
|
+
base.instance_variable_set(:@_dependencies, [])
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def append_features(base) # :nodoc:
|
|
134
|
+
if base.instance_variable_defined?(:@_dependencies)
|
|
135
|
+
base.instance_variable_get(:@_dependencies) << self
|
|
136
|
+
false
|
|
137
|
+
else
|
|
138
|
+
return false if base < self
|
|
139
|
+
@_dependencies.each { |dep| base.include(dep) }
|
|
140
|
+
super
|
|
141
|
+
|
|
142
|
+
base.class_eval(&@_included_block) if instance_variable_defined?(:@_included_block)
|
|
143
|
+
|
|
144
|
+
##
|
|
145
|
+
# NOTE: Customization compared to original `Concern` implementation.
|
|
146
|
+
# TODO: Why original `Concern` implementation uses `const_defined?(:ClassMethods)`, not `const_defined?(:ClassMethods, false)`?
|
|
147
|
+
# NOTE: Changed order to have a way to control when to include `InstanceMethods` and `ClassMethods` from `included` block.
|
|
148
|
+
#
|
|
149
|
+
base.include const_get(:InstanceMethods) if const_defined?(:InstanceMethods)
|
|
150
|
+
|
|
151
|
+
base.extend const_get(:ClassMethods) if const_defined?(:ClassMethods)
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def prepend_features(base) # :nodoc:
|
|
156
|
+
if base.instance_variable_defined?(:@_dependencies)
|
|
157
|
+
base.instance_variable_get(:@_dependencies).unshift self
|
|
158
|
+
false
|
|
159
|
+
else
|
|
160
|
+
return false if base < self
|
|
161
|
+
@_dependencies.each { |dep| base.prepend(dep) }
|
|
162
|
+
super
|
|
163
|
+
|
|
164
|
+
base.class_eval(&@_prepended_block) if instance_variable_defined?(:@_prepended_block)
|
|
165
|
+
|
|
166
|
+
##
|
|
167
|
+
# NOTE: Customization compared to original `Concern` implementation.
|
|
168
|
+
# TODO: Why original `Concern` implementation uses `const_defined?(:ClassMethods)`, not `const_defined?(:ClassMethods, false)`?
|
|
169
|
+
# NOTE: Changed order to have a way to control when to include `InstanceMethods` and `ClassMethods` from `included` block.
|
|
170
|
+
#
|
|
171
|
+
base.prepend const_get(:InstanceMethods) if const_defined?(:InstanceMethods)
|
|
172
|
+
|
|
173
|
+
base.singleton_class.prepend const_get(:ClassMethods) if const_defined?(:ClassMethods)
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# Evaluate given block in context of base class,
|
|
178
|
+
# so that you can write class macros here.
|
|
179
|
+
# When you define more than one +included+ block, it raises an exception.
|
|
180
|
+
def included(base = nil, &block)
|
|
181
|
+
if base.nil?
|
|
182
|
+
if instance_variable_defined?(:@_included_block)
|
|
183
|
+
if @_included_block.source_location != block.source_location
|
|
184
|
+
raise MultipleIncludedBlocks
|
|
185
|
+
end
|
|
186
|
+
else
|
|
187
|
+
@_included_block = block
|
|
188
|
+
end
|
|
189
|
+
else
|
|
190
|
+
super
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
# Evaluate given block in context of base class,
|
|
195
|
+
# so that you can write class macros here.
|
|
196
|
+
# When you define more than one +prepended+ block, it raises an exception.
|
|
197
|
+
def prepended(base = nil, &block)
|
|
198
|
+
if base.nil?
|
|
199
|
+
if instance_variable_defined?(:@_prepended_block)
|
|
200
|
+
if @_prepended_block.source_location != block.source_location
|
|
201
|
+
raise MultiplePrependBlocks
|
|
202
|
+
end
|
|
203
|
+
else
|
|
204
|
+
@_prepended_block = block
|
|
205
|
+
end
|
|
206
|
+
else
|
|
207
|
+
super
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
##
|
|
212
|
+
# NOTE: Customization compared to original `Concern` implementation.
|
|
213
|
+
#
|
|
214
|
+
def instance_methods(include_private = false, &instance_methods_module_definition)
|
|
215
|
+
##
|
|
216
|
+
# NOTE: This `if` is propably the reason why Rails team decided to create only `class_methods` in the original Concern implementation.
|
|
217
|
+
#
|
|
218
|
+
return super(include_private) unless instance_methods_module_definition
|
|
219
|
+
|
|
220
|
+
mod = const_defined?(:InstanceMethods, false) ?
|
|
221
|
+
const_get(:InstanceMethods) :
|
|
222
|
+
const_set(:InstanceMethods, Module.new)
|
|
223
|
+
|
|
224
|
+
mod.module_eval(&instance_methods_module_definition)
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
# Define class methods from given block.
|
|
228
|
+
# You can define private class methods as well.
|
|
229
|
+
#
|
|
230
|
+
# module Example
|
|
231
|
+
# extend ActiveSupport::Concern
|
|
232
|
+
#
|
|
233
|
+
# class_methods do
|
|
234
|
+
# def foo; puts 'foo'; end
|
|
235
|
+
#
|
|
236
|
+
# private
|
|
237
|
+
# def bar; puts 'bar'; end
|
|
238
|
+
# end
|
|
239
|
+
# end
|
|
240
|
+
#
|
|
241
|
+
# class Buzz
|
|
242
|
+
# include Example
|
|
243
|
+
# end
|
|
244
|
+
#
|
|
245
|
+
# Buzz.foo # => "foo"
|
|
246
|
+
# Buzz.bar # => private method 'bar' called for Buzz:Class(NoMethodError)
|
|
247
|
+
def class_methods(&class_methods_module_definition)
|
|
248
|
+
mod = const_defined?(:ClassMethods, false) ?
|
|
249
|
+
const_get(:ClassMethods) :
|
|
250
|
+
const_set(:ClassMethods, Module.new)
|
|
251
|
+
|
|
252
|
+
mod.module_eval(&class_methods_module_definition)
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
# @internal
|
|
5
|
+
# NOTE:
|
|
6
|
+
# Copied from `rails/rails` with some logic modification.
|
|
7
|
+
# Version: v7.0.3.1.
|
|
8
|
+
# Wrapped in a namespace `ConvenientService::Dependencies::Extractions::ActiveSupportConcern`.
|
|
9
|
+
# Added `instance_methods` that works in a similar way as `class_methods`.
|
|
10
|
+
# Also `ClassMethods` (and `InstanceMethods`) are loaded after `included` block, not as in the original implementation.
|
|
11
|
+
#
|
|
12
|
+
# - https://github.com/marian13/rails/blob/v7.0.3.1/activesupport/lib/active_support/concern.rb
|
|
13
|
+
# - https://github.com/rails/rails/blob/v7.0.3.1/activesupport/lib/active_support/concern.rb
|
|
14
|
+
# - https://github.com/rails/rails
|
|
15
|
+
#
|
|
16
|
+
require_relative "active_support_concern/concern"
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
##
|
|
2
|
+
# @internal
|
|
3
|
+
# Yet another hack how to enable the syntax highlighting for the byebug gem. Works for v10.0.0 and higher.
|
|
4
|
+
# (See https://gist.github.com/marian13/5dade20a431d7254db30e543167058ce)
|
|
5
|
+
#
|
|
6
|
+
# WARNING: Although this hack is based on the monkey patching,
|
|
7
|
+
# use this technique for other issues in your own codebases with a precaution.
|
|
8
|
+
#
|
|
9
|
+
require "byebug/runner" unless defined? Byebug::VERSION
|
|
10
|
+
|
|
11
|
+
if Gem::Version.new(Byebug::VERSION) >= Gem::Version.new("10.0.0")
|
|
12
|
+
module Byebug
|
|
13
|
+
class SourceFileFormatter
|
|
14
|
+
##
|
|
15
|
+
# This is a replacement of the internal <tt>Byebug::SourceFileFormatter.file</tt> method
|
|
16
|
+
# which adds syntax highlighting capability to it.
|
|
17
|
+
#
|
|
18
|
+
# The original implementation simply returns the file path
|
|
19
|
+
# which is passed to the <tt>Byebug::SourceFileFormatter</tt> constructor just as <tt>file</tt>.
|
|
20
|
+
# (See https://github.com/deivid-rodriguez/byebug/blob/master/lib/byebug/source_file_formatter.rb#L13)
|
|
21
|
+
#
|
|
22
|
+
# The current replacement, instead of returning the original file path,
|
|
23
|
+
# returns a copy of it, where the syntax is highlighted by the Rouge gem(A pure Ruby code highlighter).
|
|
24
|
+
# (See https://github.com/rouge-ruby/rouge)
|
|
25
|
+
#
|
|
26
|
+
# In order to create a copy, it utilizes Ruby's <tt>tempfile</tt> stdlib.
|
|
27
|
+
# (See https://ruby-doc.org/stdlib-2.7.0/libdoc/tempfile/rdoc/Tempfile.html)
|
|
28
|
+
# A tempfile is automatically deleted from the underlying OS when it is garbage-collected.
|
|
29
|
+
#
|
|
30
|
+
def file
|
|
31
|
+
@highlighted_file ||=
|
|
32
|
+
begin
|
|
33
|
+
if defined? Rouge
|
|
34
|
+
source = File.read(@file)
|
|
35
|
+
|
|
36
|
+
theme = Rouge::Themes::Monokai.new
|
|
37
|
+
formatter = Rouge::Formatters::Terminal256.new(theme)
|
|
38
|
+
lexer = Rouge::Lexers::Ruby.new
|
|
39
|
+
|
|
40
|
+
dest = formatter.format(lexer.lex(source))
|
|
41
|
+
|
|
42
|
+
# Tempfile with the highlighted syntax is assigned to the instance variable
|
|
43
|
+
# in order to prevent its premature garbage collection.
|
|
44
|
+
@tempfile_with_highlighted_syntax = Tempfile.new.tap { |t| t.write(dest) }.tap(&:close)
|
|
45
|
+
|
|
46
|
+
@tempfile_with_highlighted_syntax.path
|
|
47
|
+
else
|
|
48
|
+
warn %q{Rouge(a pure Ruby code highlighter) is not defined. Maybe you forgot to require it? (require 'rouge')}
|
|
49
|
+
|
|
50
|
+
@file
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
else
|
|
57
|
+
warn "Byebug version is lower than v10.0.0..."
|
|
58
|
+
end
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
require_relative 'logger'
|
|
2
|
+
|
|
3
|
+
module ConvenientService
|
|
4
|
+
module Dependencies
|
|
5
|
+
module Extractions
|
|
6
|
+
module RubyMiddleware
|
|
7
|
+
##
|
|
8
|
+
# https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/builder.rb
|
|
9
|
+
#
|
|
10
|
+
module Middleware
|
|
11
|
+
# This provides a DSL for building up a stack of middlewares.
|
|
12
|
+
#
|
|
13
|
+
# This code is based heavily off of `Rack::Builder` and
|
|
14
|
+
# `ActionDispatch::MiddlewareStack` in Rack and Rails, respectively.
|
|
15
|
+
#
|
|
16
|
+
# # Usage
|
|
17
|
+
#
|
|
18
|
+
# Building a middleware stack is very easy:
|
|
19
|
+
#
|
|
20
|
+
# app = Middleware::Builder.new do |b|
|
|
21
|
+
# b.use A
|
|
22
|
+
# b.use B
|
|
23
|
+
# end
|
|
24
|
+
#
|
|
25
|
+
# # Call the middleware
|
|
26
|
+
# app.call(7)
|
|
27
|
+
#
|
|
28
|
+
class Builder
|
|
29
|
+
|
|
30
|
+
# Initializes the builder. An optional block can be passed which
|
|
31
|
+
# will either yield the builder or be evaluated in the context of the instance.
|
|
32
|
+
#
|
|
33
|
+
# Example:
|
|
34
|
+
#
|
|
35
|
+
# Builder.new do |b|
|
|
36
|
+
# b.use A
|
|
37
|
+
# b.use B
|
|
38
|
+
# end
|
|
39
|
+
#
|
|
40
|
+
# Builder.new do
|
|
41
|
+
# use A
|
|
42
|
+
# use B
|
|
43
|
+
# end
|
|
44
|
+
#
|
|
45
|
+
# @param [Hash] opts Options hash
|
|
46
|
+
# @option opts [Class] :runner_class The class to wrap the middleware stack
|
|
47
|
+
# in which knows how to run them.
|
|
48
|
+
# @yield [] Evaluated in this instance which allows you to use methods
|
|
49
|
+
# like {#use} and such.
|
|
50
|
+
def initialize(opts = nil, &block)
|
|
51
|
+
opts ||= {}
|
|
52
|
+
@runner_class = opts.fetch(:runner_class, Runner)
|
|
53
|
+
@middleware_name = opts.fetch(:name, 'Middleware')
|
|
54
|
+
|
|
55
|
+
if block_given?
|
|
56
|
+
if block.arity == 1
|
|
57
|
+
yield self
|
|
58
|
+
else
|
|
59
|
+
instance_eval(&block)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Returns the name of the current middleware
|
|
65
|
+
def name
|
|
66
|
+
@middleware_name
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Returns a mergeable version of the builder. If `use` is called with
|
|
70
|
+
# the return value of this method, then the stack will merge, instead
|
|
71
|
+
# of being treated as a separate single middleware.
|
|
72
|
+
def flatten
|
|
73
|
+
lambda do |env|
|
|
74
|
+
call(env)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Adds a middleware class to the middleware stack. Any additional
|
|
79
|
+
# args and a block, if given, are saved and passed to the initializer
|
|
80
|
+
# of the middleware.
|
|
81
|
+
#
|
|
82
|
+
# @param [Class] middleware The middleware class
|
|
83
|
+
def use(middleware, *args, &block)
|
|
84
|
+
if middleware.is_a?(Builder)
|
|
85
|
+
# Merge in the other builder's stack into our own
|
|
86
|
+
stack.concat(middleware.stack)
|
|
87
|
+
else
|
|
88
|
+
stack << [middleware, args, block]
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
self
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Inserts a middleware at the given index or directly before the given middleware object.
|
|
95
|
+
def insert(index, middleware, *args, &block)
|
|
96
|
+
index = self.index(index) unless index.is_a?(Integer)
|
|
97
|
+
fail "no such middleware to insert before: #{index.inspect}" unless index
|
|
98
|
+
stack.insert(index, [middleware, args, block])
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
alias_method :insert_before, :insert
|
|
102
|
+
|
|
103
|
+
# Inserts a middleware after the given index or middleware object.
|
|
104
|
+
def insert_after(index, middleware, *args, &block)
|
|
105
|
+
index = self.index(index) unless index.is_a?(Integer)
|
|
106
|
+
fail "no such middleware to insert after: #{index.inspect}" unless index
|
|
107
|
+
insert(index + 1, middleware, *args, &block)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Inserts a middleware before each middleware object
|
|
111
|
+
def insert_before_each(middleware, *args, &block)
|
|
112
|
+
self.stack = stack.reduce([]) do |carry, item|
|
|
113
|
+
carry.push([middleware, args, block], item)
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Inserts a middleware after each middleware object
|
|
118
|
+
def insert_after_each(middleware, *args, &block)
|
|
119
|
+
self.stack = stack.reduce([]) do |carry, item|
|
|
120
|
+
carry.push(item, [middleware, args, block])
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Replaces the given middleware object or index with the new middleware.
|
|
125
|
+
def replace(index, middleware, *args, &block)
|
|
126
|
+
index = self.index index unless index.is_a? Integer
|
|
127
|
+
|
|
128
|
+
delete(index)
|
|
129
|
+
insert(index, middleware, *args, &block)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# Deletes the given middleware object or index
|
|
133
|
+
def delete(index)
|
|
134
|
+
index = self.index(index) unless index.is_a?(Integer)
|
|
135
|
+
stack.delete_at(index)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Runs the builder stack with the given environment.
|
|
139
|
+
def call(env = nil)
|
|
140
|
+
to_app.call(env)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def inspect
|
|
144
|
+
name+'[' + stack.map do |middleware|
|
|
145
|
+
name = middleware[0].is_a?(Proc) ? 'Proc' : middleware[0].name
|
|
146
|
+
"#{name}(#{middleware[1].join(', ')})"
|
|
147
|
+
end.join(', ') + ']'
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def inject_logger logger
|
|
151
|
+
insert_before_each Middleware::Logger, logger, name
|
|
152
|
+
|
|
153
|
+
self
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
protected
|
|
157
|
+
|
|
158
|
+
# Returns the numeric index for the given middleware object.
|
|
159
|
+
#
|
|
160
|
+
# @param [Object] object The item to find the index for
|
|
161
|
+
# @return [Integer]
|
|
162
|
+
def index(object)
|
|
163
|
+
stack.each_with_index do |item, i|
|
|
164
|
+
return i if item[0] == object
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
nil
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# Returns the current stack of middlewares. You probably won't
|
|
171
|
+
# need to use this directly, and it's recommended that you don't.
|
|
172
|
+
#
|
|
173
|
+
# @return [Array]
|
|
174
|
+
def stack
|
|
175
|
+
@stack ||= []
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
# you shouldn't use this method
|
|
179
|
+
# used for insert_before|after_each
|
|
180
|
+
# @return [Array]
|
|
181
|
+
attr_writer :stack
|
|
182
|
+
|
|
183
|
+
# Converts the builder stack to a runnable action sequence.
|
|
184
|
+
#
|
|
185
|
+
# @return [Object] A callable object
|
|
186
|
+
def to_app
|
|
187
|
+
@runner_class.new(stack.dup)
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'logger'
|
|
2
|
+
require 'pp'
|
|
3
|
+
|
|
4
|
+
module ConvenientService
|
|
5
|
+
module Dependencies
|
|
6
|
+
module Extractions
|
|
7
|
+
module RubyMiddleware
|
|
8
|
+
##
|
|
9
|
+
# https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/logger.rb
|
|
10
|
+
#
|
|
11
|
+
module Middleware
|
|
12
|
+
|
|
13
|
+
class Logger
|
|
14
|
+
def initialize app, logger, name = nil
|
|
15
|
+
@app = app
|
|
16
|
+
@write_to = logger
|
|
17
|
+
@middleware_name = name
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def call env
|
|
21
|
+
write(
|
|
22
|
+
way_in_message(
|
|
23
|
+
next_middleware_name, env
|
|
24
|
+
))
|
|
25
|
+
|
|
26
|
+
time = Time.now
|
|
27
|
+
|
|
28
|
+
@app.call(env).tap { |env|
|
|
29
|
+
write(
|
|
30
|
+
way_out_message(
|
|
31
|
+
next_middleware_name, (Time.now - time) * 1000.0, env
|
|
32
|
+
))
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def next_middleware_name
|
|
37
|
+
@app.class.name
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def pretty_print item
|
|
41
|
+
->(out){ PP.pp(item, out) }.('')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def way_in_message name, env
|
|
45
|
+
' %s has been called with: %s' % [name, pretty_print(env)]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def way_out_message name, time, value
|
|
49
|
+
' %s finished in %.0f ms and returned: %s' % [name, time, pretty_print(value)]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def write msg
|
|
53
|
+
@write_to.add(::Logger::INFO, msg.slice(0, 255).strip!, @middleware_name)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
module ConvenientService
|
|
2
|
+
module Dependencies
|
|
3
|
+
module Extractions
|
|
4
|
+
module RubyMiddleware
|
|
5
|
+
##
|
|
6
|
+
# https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/runner.rb
|
|
7
|
+
#
|
|
8
|
+
module Middleware
|
|
9
|
+
# This is a basic runner for middleware stacks. This runner does
|
|
10
|
+
# the default expected behavior of running the middleware stacks
|
|
11
|
+
# in order, then reversing the order.
|
|
12
|
+
class Runner
|
|
13
|
+
# A middleware which does nothing
|
|
14
|
+
EMPTY_MIDDLEWARE = ->(env) { env }
|
|
15
|
+
|
|
16
|
+
# Build a new middleware runner with the given middleware
|
|
17
|
+
# stack.
|
|
18
|
+
#
|
|
19
|
+
# Note: This class usually doesn't need to be used directly.
|
|
20
|
+
# Instead, take a look at using the {Builder} class, which is
|
|
21
|
+
# a much friendlier way to build up a middleware stack.
|
|
22
|
+
#
|
|
23
|
+
# @param [Array] stack An array of the middleware to run.
|
|
24
|
+
def initialize(stack)
|
|
25
|
+
# We need to take the stack of middleware and initialize them
|
|
26
|
+
# all so they call the proper next middleware.
|
|
27
|
+
@kickoff = build_call_chain(stack)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Run the middleware stack with the given state bag.
|
|
31
|
+
#
|
|
32
|
+
# @param [Object] env The state to pass into as the initial
|
|
33
|
+
# environment data. This is usual a hash of some sort.
|
|
34
|
+
def call(env)
|
|
35
|
+
# We just call the kickoff middleware, which is responsible
|
|
36
|
+
# for properly calling the next middleware, and so on and so
|
|
37
|
+
# forth.
|
|
38
|
+
@kickoff.call(env)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
protected
|
|
42
|
+
|
|
43
|
+
# This takes a stack of middlewares and initializes them in a way
|
|
44
|
+
# that each middleware properly calls the next middleware.
|
|
45
|
+
def build_call_chain(stack)
|
|
46
|
+
# We need to instantiate the middleware stack in reverse
|
|
47
|
+
# order so that each middleware can have a reference to
|
|
48
|
+
# the next middleware it has to call. The final middleware
|
|
49
|
+
# is always the empty middleware, which does nothing but return.
|
|
50
|
+
stack.reverse.inject(EMPTY_MIDDLEWARE) do |next_middleware, current_middleware|
|
|
51
|
+
# Unpack the actual item
|
|
52
|
+
klass, args, block = current_middleware
|
|
53
|
+
|
|
54
|
+
# Default the arguments to an empty array. Otherwise in Ruby 1.8
|
|
55
|
+
# a `nil` args will actually pass `nil` into the class. Not what
|
|
56
|
+
# we want!
|
|
57
|
+
args ||= []
|
|
58
|
+
|
|
59
|
+
if klass.is_a?(Class)
|
|
60
|
+
# If the klass actually is a class, then instantiate it with
|
|
61
|
+
# the app and any other arguments given.
|
|
62
|
+
klass.new(next_middleware, *args, &block)
|
|
63
|
+
elsif klass.respond_to?(:call)
|
|
64
|
+
# Make it a lambda which calls the item then forwards up
|
|
65
|
+
# the chain.
|
|
66
|
+
lambda do |env|
|
|
67
|
+
next_middleware.call(klass.call(env, *args))
|
|
68
|
+
end
|
|
69
|
+
else
|
|
70
|
+
fail "Invalid middleware, doesn't respond to `call`: #{klass.inspect}"
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|