convenient_service 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
# Usage example:
|
5
|
+
#
|
6
|
+
# result = ConvenientService::Examples::Dry::Gemfile::Services::FormatGemsWithoutEnvs.result(
|
7
|
+
# parsed_content: {
|
8
|
+
# gems: [
|
9
|
+
# {
|
10
|
+
# envs: [],
|
11
|
+
# line: %(gem "bootsnap", ">= 1.4.4", require: false)
|
12
|
+
# },
|
13
|
+
# {
|
14
|
+
# envs: [],
|
15
|
+
# line: %(gem "pg")
|
16
|
+
# },
|
17
|
+
# {
|
18
|
+
# envs: [],
|
19
|
+
# line: %(gem "rails", "~> 6.1.3", ">= 6.1.3.2")
|
20
|
+
# },
|
21
|
+
# {
|
22
|
+
# envs: [],
|
23
|
+
# line: %(gem "webpacker", "~> 5.0")
|
24
|
+
# },
|
25
|
+
# {
|
26
|
+
# envs: [],
|
27
|
+
# line: %(gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby])
|
28
|
+
# }
|
29
|
+
# ]
|
30
|
+
# }
|
31
|
+
# )
|
32
|
+
#
|
33
|
+
# NOTE: Check the corresponding spec file to see more examples.
|
34
|
+
#
|
35
|
+
module ConvenientService
|
36
|
+
module Examples
|
37
|
+
module Dry
|
38
|
+
module Gemfile
|
39
|
+
module Services
|
40
|
+
class FormatGemsWithoutEnvs
|
41
|
+
EMPTY_LINE = ""
|
42
|
+
ENTER = "\n"
|
43
|
+
|
44
|
+
include DryService::Config
|
45
|
+
|
46
|
+
option :parsed_content
|
47
|
+
|
48
|
+
contract do
|
49
|
+
schema do
|
50
|
+
required(:parsed_content).hash do
|
51
|
+
optional(:gems).array(:hash) do
|
52
|
+
##
|
53
|
+
# NOTE: required(:envs).array(:symbol) raises `Dry::Container::KeyError: key not found: "{:type?=>Symbol}"`.
|
54
|
+
#
|
55
|
+
required(:envs).array(type?: ::Symbol)
|
56
|
+
required(:line).value(:string)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def result
|
63
|
+
success(formatted_content: format_content)
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def format_content
|
69
|
+
return "" if gems_without_envs.none?
|
70
|
+
|
71
|
+
gems_without_envs
|
72
|
+
.map { |gem| gem[:line] }
|
73
|
+
.reduce(EMPTY_LINE.dup) { |content, line| content << line << ENTER }
|
74
|
+
end
|
75
|
+
|
76
|
+
def gems_without_envs
|
77
|
+
@gems_without_envs ||= parsed_content[:gems].to_a.select { |gem| gem[:envs].none? }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
# Usage example:
|
5
|
+
#
|
6
|
+
# result = ConvenientService::Examples::Dry::Gemfile::Services::FormatHeader.result(
|
7
|
+
# parsed_content: {
|
8
|
+
# ruby: [
|
9
|
+
# %(ruby "3.0.1")
|
10
|
+
# ],
|
11
|
+
# source: [
|
12
|
+
# %(source "https://rubygems.org")
|
13
|
+
# ],
|
14
|
+
# git_source: [
|
15
|
+
# %(git_source(:github) { |repo| "https://github.com/\#{repo}.git" })
|
16
|
+
# ]
|
17
|
+
# },
|
18
|
+
# skip_frozen_string_literal: true
|
19
|
+
# )
|
20
|
+
#
|
21
|
+
# NOTE: Check the corresponding spec file to see more examples.
|
22
|
+
#
|
23
|
+
module ConvenientService
|
24
|
+
module Examples
|
25
|
+
module Dry
|
26
|
+
module Gemfile
|
27
|
+
module Services
|
28
|
+
class FormatHeader
|
29
|
+
FROZEN_STRING_LITERAL = "# frozen_string_literal: true"
|
30
|
+
EMPTY_LINE = ""
|
31
|
+
ENTER = "\n"
|
32
|
+
|
33
|
+
include DryService::Config
|
34
|
+
|
35
|
+
option :parsed_content
|
36
|
+
option :skip_frozen_string_literal, default: -> { false }
|
37
|
+
|
38
|
+
contract do
|
39
|
+
schema do
|
40
|
+
required(:parsed_content).hash do
|
41
|
+
optional(:ruby).array(:string)
|
42
|
+
optional(:source).array(:string)
|
43
|
+
optional(:git_source).array(:string)
|
44
|
+
end
|
45
|
+
|
46
|
+
optional(:skip_frozen_string_literal).value(:bool?)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def result
|
51
|
+
success(formatted_content: format_content)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def format_content
|
57
|
+
content = EMPTY_LINE.dup
|
58
|
+
|
59
|
+
content << FROZEN_STRING_LITERAL << ENTER << ENTER unless skip_frozen_string_literal
|
60
|
+
|
61
|
+
parsed_content.slice(:source, :git_source, :ruby).each do |_group, lines|
|
62
|
+
content << lines.join(ENTER) << ENTER << ENTER
|
63
|
+
end
|
64
|
+
|
65
|
+
content.chomp!
|
66
|
+
|
67
|
+
content
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
# Usage example:
|
5
|
+
#
|
6
|
+
# result = ConvenientService::Examples::Dry::Gemfile::Services::ParseContent.result(
|
7
|
+
# content: <<~'RUBY'
|
8
|
+
# ruby "3.0.1"
|
9
|
+
# source "https://rubygems.org"
|
10
|
+
|
11
|
+
# git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
12
|
+
|
13
|
+
# gem "bootsnap", ">= 1.4.4", require: false
|
14
|
+
|
15
|
+
# group :development do
|
16
|
+
# gem "listen", "~> 3.3"
|
17
|
+
# end
|
18
|
+
|
19
|
+
# group :development, :test do
|
20
|
+
# gem "rspec-rails"
|
21
|
+
# end
|
22
|
+
# RUBY
|
23
|
+
# )
|
24
|
+
#
|
25
|
+
# NOTE: Check the corresponding spec file to see more examples.
|
26
|
+
#
|
27
|
+
module ConvenientService
|
28
|
+
module Examples
|
29
|
+
module Dry
|
30
|
+
module Gemfile
|
31
|
+
module Services
|
32
|
+
class ParseContent
|
33
|
+
RUBY_REGEX = /\A\s*ruby/
|
34
|
+
SOURCE_REGEX = /\A\s*source/
|
35
|
+
GIT_SOURCE_REGEX = /\A\s*git_source/
|
36
|
+
GROUP_REGEX = /\A\s*group/
|
37
|
+
GEM_REGEX = /\A\s*gem/
|
38
|
+
BLOCK_END_REGEX = /\A\s*end/
|
39
|
+
ENV_SCAN_REGEX = /:(\w+)/
|
40
|
+
|
41
|
+
include DryService::Config
|
42
|
+
|
43
|
+
option :content
|
44
|
+
|
45
|
+
contract do
|
46
|
+
schema do
|
47
|
+
required(:content).value(:string)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
step Services::AssertValidRubySyntax, in: :content
|
52
|
+
step :result, in: :content, out: :parsed_content
|
53
|
+
|
54
|
+
def result
|
55
|
+
success(data: {parsed_content: parse_content})
|
56
|
+
end
|
57
|
+
|
58
|
+
def parse_content
|
59
|
+
hash = ::Hash.new { |h, k| h[k] = [] }
|
60
|
+
|
61
|
+
::StringIO.open(content) do |io|
|
62
|
+
envs = []
|
63
|
+
|
64
|
+
until io.eof?
|
65
|
+
line = io.readline.rstrip
|
66
|
+
|
67
|
+
case line
|
68
|
+
when RUBY_REGEX
|
69
|
+
hash[:ruby] << line
|
70
|
+
when SOURCE_REGEX
|
71
|
+
hash[:source] << line
|
72
|
+
when GIT_SOURCE_REGEX
|
73
|
+
hash[:git_source] << line
|
74
|
+
when GROUP_REGEX
|
75
|
+
envs = line.scan(ENV_SCAN_REGEX).map(&:first).map(&:to_sym)
|
76
|
+
when GEM_REGEX
|
77
|
+
hash[:gems] << {envs: envs, line: line.lstrip}
|
78
|
+
when BLOCK_END_REGEX
|
79
|
+
envs = []
|
80
|
+
else
|
81
|
+
hash[:rest] << line
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
hash
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
# Usage example:
|
5
|
+
#
|
6
|
+
# ConvenientService::Examples::Dry::Gemfile::Services::PrintShellCommand.result(text: "ls -a")
|
7
|
+
#
|
8
|
+
module ConvenientService
|
9
|
+
module Examples
|
10
|
+
module Dry
|
11
|
+
module Gemfile
|
12
|
+
module Services
|
13
|
+
class PrintShellCommand
|
14
|
+
include DryService::Config
|
15
|
+
|
16
|
+
option :text
|
17
|
+
option :out, default: -> { $stdout }
|
18
|
+
|
19
|
+
contract do
|
20
|
+
schema do
|
21
|
+
required(:text).value(:string)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def result
|
26
|
+
out.puts
|
27
|
+
|
28
|
+
out.puts ::Paint["$ #{text}", :blue, :bold]
|
29
|
+
|
30
|
+
success
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Examples
|
5
|
+
module Dry
|
6
|
+
module Gemfile
|
7
|
+
module Services
|
8
|
+
class ReadFileContent
|
9
|
+
include DryService::Config
|
10
|
+
|
11
|
+
option :path
|
12
|
+
|
13
|
+
contract do
|
14
|
+
schema do
|
15
|
+
required(:path).value(:string)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
step Services::AssertFileExists, in: :path
|
20
|
+
step Services::AssertFileNotEmpty, in: :path
|
21
|
+
step :result, in: :path, out: :content
|
22
|
+
|
23
|
+
def result
|
24
|
+
success(data: {content: ::File.read(path)})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Examples
|
5
|
+
module Dry
|
6
|
+
module Gemfile
|
7
|
+
module Services
|
8
|
+
class RunShell
|
9
|
+
include DryService::Config
|
10
|
+
|
11
|
+
option :command
|
12
|
+
option :debug, default: -> { false }
|
13
|
+
|
14
|
+
contract do
|
15
|
+
schema do
|
16
|
+
required(:command).value(:string)
|
17
|
+
optional(:debug).value(:bool)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def result
|
22
|
+
Services::PrintShellCommand.result(text: command) if debug
|
23
|
+
|
24
|
+
##
|
25
|
+
# NOTE: When the command exit code is 0, `system` return true, and false otherwise.
|
26
|
+
# - https://ruby-doc.org/core-3.1.2/Kernel.html#method-i-system
|
27
|
+
# - https://stackoverflow.com/a/37329716/12201472
|
28
|
+
#
|
29
|
+
if system(command)
|
30
|
+
success
|
31
|
+
else
|
32
|
+
error(message: "#{command} returned non-zero exit code")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
# Usage:
|
5
|
+
#
|
6
|
+
# ConvenientService::Examples::Dry::Gemfile::Services::StripComments.result(content: "abc")
|
7
|
+
#
|
8
|
+
module ConvenientService
|
9
|
+
module Examples
|
10
|
+
module Dry
|
11
|
+
module Gemfile
|
12
|
+
module Services
|
13
|
+
class StripComments
|
14
|
+
include DryService::Config
|
15
|
+
|
16
|
+
option :content
|
17
|
+
|
18
|
+
contract do
|
19
|
+
schema do
|
20
|
+
required(:content).value(:string)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
alias_method :content_with_comments, :content
|
25
|
+
|
26
|
+
step Services::AssertNpmPackageAvailable, in: {name: -> { "strip-comments" }}
|
27
|
+
step Services::RunShell, in: {command: -> { "node -e '#{js_script}' #{file_with_comments.path} #{file_without_comments.path}" }}
|
28
|
+
step :result, in: :file_without_comments, out: :content_without_comments
|
29
|
+
|
30
|
+
def result
|
31
|
+
success(data: {content_without_comments: file_without_comments.read})
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
##
|
37
|
+
# NOTE: When you have no time to do something well, delegate that task to someone who already works with it all the time.
|
38
|
+
# That is why `strip-comments` npm package is used to remove comments.
|
39
|
+
#
|
40
|
+
def js_script
|
41
|
+
##
|
42
|
+
# NOTE: `main` function is created in order to have an ability to use early returns.
|
43
|
+
#
|
44
|
+
# IMPORTANT: Use only double quotes inside this JS script, since it is later consumed by `node -e` option wrapped by single quoutes.
|
45
|
+
#
|
46
|
+
# TODO: Consider to use WeakRef if memory is a concern.
|
47
|
+
# https://ruby-doc.org/stdlib-2.5.1/libdoc/weakref/rdoc/WeakRef.html
|
48
|
+
#
|
49
|
+
# TODO: Jest tests for JS script.
|
50
|
+
#
|
51
|
+
@js_script ||= <<~JAVASCRIPT.gsub(/\n\s*/, " ")
|
52
|
+
const main = () => {
|
53
|
+
const process = require("process");
|
54
|
+
const fs = require("fs");
|
55
|
+
const strip = require("strip-comments");
|
56
|
+
|
57
|
+
const fileWithCommentsPath = process.argv[1];
|
58
|
+
const fileWithoutCommentsPath = process.argv[2];
|
59
|
+
const language = process.argv[3] || "ruby";
|
60
|
+
|
61
|
+
if (!fileWithCommentsPath) {
|
62
|
+
console.log("Error: Input file path is NOT passed.");
|
63
|
+
|
64
|
+
process.exit(1);
|
65
|
+
}
|
66
|
+
|
67
|
+
if (!fileWithoutCommentsPath) {
|
68
|
+
console.log("Error: Output file path is NOT passed.");
|
69
|
+
|
70
|
+
process.exit(1);
|
71
|
+
}
|
72
|
+
|
73
|
+
if (!["ruby", "javascript"].includes(language)) {
|
74
|
+
console.log("Error: Language " + language + " is NOT supported.");
|
75
|
+
|
76
|
+
process.exit(1);
|
77
|
+
}
|
78
|
+
|
79
|
+
const fileWithCommentsContent = fs.readFileSync(fileWithCommentsPath, { encoding: "utf8" });
|
80
|
+
const fileWithoutCommentsContent = strip(fileWithCommentsContent, { language });
|
81
|
+
|
82
|
+
fs.writeFileSync(fileWithoutCommentsPath, fileWithoutCommentsContent, { encoding: "utf8" });
|
83
|
+
|
84
|
+
process.exit(0);
|
85
|
+
};
|
86
|
+
|
87
|
+
main();
|
88
|
+
JAVASCRIPT
|
89
|
+
end
|
90
|
+
|
91
|
+
def file_with_comments
|
92
|
+
##
|
93
|
+
# NOTE: Tempfile is used to avoid issues with escaping of quotes inside JS script.
|
94
|
+
#
|
95
|
+
@file_with_comments ||= ::Tempfile.new.tap { |tempfile| tempfile.write(content_with_comments) }.tap(&:close)
|
96
|
+
end
|
97
|
+
|
98
|
+
def file_without_comments
|
99
|
+
##
|
100
|
+
# NOTE: JS script tries to fill content of the file without comments.
|
101
|
+
#
|
102
|
+
@file_without_comments ||= ::Tempfile.new
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "services/run_shell"
|
4
|
+
require_relative "services/assert_file_exists"
|
5
|
+
require_relative "services/assert_file_not_empty"
|
6
|
+
require_relative "services/assert_node_available"
|
7
|
+
require_relative "services/assert_npm_package_available"
|
8
|
+
require_relative "services/assert_valid_ruby_syntax"
|
9
|
+
require_relative "services/read_file_content"
|
10
|
+
require_relative "services/strip_comments"
|
11
|
+
require_relative "services/parse_content"
|
12
|
+
require_relative "services/print_shell_command"
|
13
|
+
require_relative "services/format_header"
|
14
|
+
require_relative "services/format_gems_without_envs"
|
15
|
+
require_relative "services/format_gems_with_envs"
|
16
|
+
require_relative "services/format_body"
|
17
|
+
require_relative "services/format"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "gemfile/dry_service"
|
4
|
+
require_relative "gemfile/services"
|
5
|
+
|
6
|
+
##
|
7
|
+
# Usage example:
|
8
|
+
#
|
9
|
+
# result = ConvenientService::Examples::Dry::Gemfile.format(path: "Gemfile")
|
10
|
+
# result = ConvenientService::Examples::Dry::Gemfile.format(path: "spec/cli/gemfile/format/fixtures/Gemfile")
|
11
|
+
#
|
12
|
+
module ConvenientService
|
13
|
+
module Examples
|
14
|
+
module Dry
|
15
|
+
module Gemfile
|
16
|
+
class << self
|
17
|
+
def format
|
18
|
+
Services::Format[path: path]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
# Usage example:
|
5
|
+
#
|
6
|
+
# result = ConvenientService::Examples::Rails::Gemfile.format(path: "Gemfile")
|
7
|
+
# result = ConvenientService::Examples::Rails::Gemfile.format(path: "spec/cli/gemfile/format/fixtures/Gemfile")
|
8
|
+
#
|
9
|
+
module ConvenientService
|
10
|
+
module Examples
|
11
|
+
module Rails
|
12
|
+
module Gemfile
|
13
|
+
class RailsService
|
14
|
+
module Config
|
15
|
+
def self.included(service_class)
|
16
|
+
service_class.class_exec do
|
17
|
+
include Configs::Standard
|
18
|
+
|
19
|
+
##
|
20
|
+
# NOTE: `AssignsAttributesInConstructor::UsingActiveModelAttributeAssignment` plugin.
|
21
|
+
#
|
22
|
+
concerns do
|
23
|
+
use Plugins::Common::AssignsAttributesInConstructor::UsingActiveModelAttributeAssignment::Concern
|
24
|
+
end
|
25
|
+
|
26
|
+
middlewares :initialize do
|
27
|
+
use Plugins::Common::AssignsAttributesInConstructor::UsingActiveModelAttributeAssignment::Middleware
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# NOTE: `HasAttributes::UsingActiveModelAttributes` plugin.
|
32
|
+
#
|
33
|
+
concerns do
|
34
|
+
use Plugins::Common::HasAttributes::UsingActiveModelAttributes::Concern
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# NOTE: `HasResultParamsValidations::UsingActiveModelValidations` plugin.
|
39
|
+
#
|
40
|
+
concerns do
|
41
|
+
use Plugins::Service::HasResultParamsValidations::UsingActiveModelValidations::Concern
|
42
|
+
end
|
43
|
+
|
44
|
+
middlewares :result do
|
45
|
+
use Plugins::Service::HasResultParamsValidations::UsingActiveModelValidations::Middleware
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Examples
|
5
|
+
module Rails
|
6
|
+
module Gemfile
|
7
|
+
module Services
|
8
|
+
class AssertFileExists
|
9
|
+
include RailsService::Config
|
10
|
+
|
11
|
+
attribute :path, :string
|
12
|
+
|
13
|
+
validates :path, presence: true
|
14
|
+
|
15
|
+
def result
|
16
|
+
return error("File with path `#{path}` does NOT exist") unless ::File.exist?(path)
|
17
|
+
|
18
|
+
success
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Examples
|
5
|
+
module Rails
|
6
|
+
module Gemfile
|
7
|
+
module Services
|
8
|
+
class AssertFileNotEmpty
|
9
|
+
include RailsService::Config
|
10
|
+
|
11
|
+
attribute :path, :string
|
12
|
+
|
13
|
+
validates :path, presence: true
|
14
|
+
|
15
|
+
def result
|
16
|
+
return error(message: "File with path `#{path}` is empty") if ::File.zero?(path)
|
17
|
+
|
18
|
+
success
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
# Usage example:
|
5
|
+
#
|
6
|
+
# ConvenientService::Examples::Rails::Gemfile::Services::AssertNodeAvailable.result
|
7
|
+
#
|
8
|
+
module ConvenientService
|
9
|
+
module Examples
|
10
|
+
module Rails
|
11
|
+
module Gemfile
|
12
|
+
module Services
|
13
|
+
class AssertNodeAvailable
|
14
|
+
include RailsService::Config
|
15
|
+
|
16
|
+
##
|
17
|
+
# NOTE: `> /dev/null 2>&1` is used to hide output.
|
18
|
+
# https://unix.stackexchange.com/a/119650/394253
|
19
|
+
#
|
20
|
+
step Services::RunShell, in: {command: -> { "which node > /dev/null 2>&1" }}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
# Usage example:
|
5
|
+
#
|
6
|
+
# ConvenientService::Examples::Rails::Gemfile::Services::AssertNpmPackageAvailable.result(name: "lodash")
|
7
|
+
#
|
8
|
+
module ConvenientService
|
9
|
+
module Examples
|
10
|
+
module Rails
|
11
|
+
module Gemfile
|
12
|
+
module Services
|
13
|
+
class AssertNpmPackageAvailable
|
14
|
+
include RailsService::Config
|
15
|
+
|
16
|
+
attribute :name, :string
|
17
|
+
|
18
|
+
validates :name, presence: true
|
19
|
+
|
20
|
+
step Services::AssertNodeAvailable
|
21
|
+
|
22
|
+
##
|
23
|
+
# NOTE: `> /dev/null 2>&1` is used to hide output.
|
24
|
+
# https://unix.stackexchange.com/a/119650/394253
|
25
|
+
#
|
26
|
+
# NOTE: For `npm list` and its options docs, see
|
27
|
+
# https://docs.npmjs.com/cli/v7/commands/npm-ls
|
28
|
+
#
|
29
|
+
step Services::RunShell, in: {command: -> { "npm list #{name} --depth=0 > /dev/null 2>&1" }}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|