ehbrs-tools 0.16.1 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ehbrs/cooking_book.rb +9 -0
- data/lib/ehbrs/cooking_book/build.rb +45 -0
- data/lib/ehbrs/cooking_book/build/base_page.rb +43 -0
- data/lib/ehbrs/cooking_book/build/index_page.rb +26 -0
- data/lib/ehbrs/cooking_book/build/recipe_page.rb +27 -0
- data/lib/ehbrs/cooking_book/project.rb +25 -0
- data/lib/ehbrs/cooking_book/recipe.rb +37 -0
- data/lib/ehbrs/cooking_book/recipe/ingredient.rb +21 -0
- data/lib/ehbrs/cooking_book/recipe/measure.rb +60 -0
- data/lib/ehbrs/cooking_book/recipe/part.rb +32 -0
- data/lib/ehbrs/patches/module/erb_template.rb +11 -0
- data/lib/ehbrs/patches/object/erb_template.rb +9 -0
- data/lib/ehbrs/patches/object/template.rb +7 -0
- data/lib/ehbrs/runner.rb +6 -13
- data/lib/ehbrs/runner/cooking_book.rb +30 -0
- data/lib/ehbrs/runner/cooking_book/build.rb +32 -0
- data/lib/ehbrs/runner/videos/probe.rb +3 -3
- data/lib/ehbrs/tools/application.rb +13 -0
- data/lib/ehbrs/tools/version.rb +1 -1
- data/lib/ehbrs/videos/file.rb +4 -8
- data/lib/ehbrs/videos/track.rb +5 -13
- data/lib/ehbrs/videos/unsupported/checks/codec_extra_unlisted.rb +3 -1
- data/lib/ehbrs/videos/unsupported/checks/codec_extra_unsupported.rb +3 -1
- data/lib/ehbrs/videos/unsupported/checks/codec_unlisted.rb +4 -2
- data/lib/ehbrs/videos/unsupported/checks/codec_unsupported.rb +3 -1
- data/lib/ehbrs/videos/unsupported/checks/invalid_extension.rb +2 -0
- data/lib/ehbrs/videos/unsupported/fix_profile.rb +0 -13
- data/lib/ehbrs/videos/unsupported/fixes/supported_codec.rb +10 -10
- data/lib/ehbrs/videos/unsupported/profiles/base.rb +17 -3
- data/lib/ehbrs/videos/unsupported/profiles/philco.rb +5 -4
- data/template/ehbrs/cooking_book/build/base_page/layout.html.erb +20 -0
- data/template/ehbrs/cooking_book/build/index_page/inner.html.erb +6 -0
- data/template/ehbrs/cooking_book/build/recipe_page/inner.html.erb +6 -0
- data/template/ehbrs/cooking_book/build/recipe_page/part.html.erb +27 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/spec/source_target_fixtures_example.rb +10 -2
- data/vendor/aranha-parsers/lib/aranha/parsers/version.rb +1 -1
- data/vendor/eac_cli/eac_cli.gemspec +1 -1
- data/vendor/eac_cli/lib/eac_cli/definition.rb +34 -39
- data/vendor/eac_cli/lib/eac_cli/definition/alternative.rb +83 -0
- data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +18 -40
- data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb +50 -0
- data/vendor/eac_cli/lib/eac_cli/parser.rb +23 -3
- data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +92 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/argv.rb +17 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb +24 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb +58 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/positionals.rb +30 -0
- data/vendor/eac_cli/lib/eac_cli/runner.rb +12 -4
- data/vendor/eac_cli/lib/eac_cli/runner/exit.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +18 -1
- data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +5 -1
- data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +6 -1
- data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
- data/vendor/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb +14 -0
- data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +10 -0
- data/vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb +140 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +17 -5
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb +42 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb +53 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +29 -1
- data/vendor/eac_docker/lib/eac_docker/container.rb +24 -0
- data/vendor/eac_docker/lib/eac_docker/images/coded.rb +39 -0
- data/vendor/eac_docker/lib/eac_docker/images/templatized.rb +26 -0
- data/vendor/eac_docker/lib/eac_docker/registry.rb +17 -0
- data/vendor/eac_docker/lib/eac_docker/version.rb +1 -1
- data/vendor/eac_docker/spec/lib/eac_docker/images/coded_spec.rb +12 -0
- data/vendor/eac_docker/spec/lib/eac_docker/images/coded_spec_files/image1/Dockerfile +1 -0
- data/vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec.rb +17 -0
- data/vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec_files/stub_docker_image/Dockerfile +1 -0
- data/vendor/eac_ruby_base0/Gemfile +5 -0
- data/vendor/eac_ruby_base0/eac_ruby_base0.gemspec +20 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0.rb +7 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/application.rb +69 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +54 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner/test_all.rb +27 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +5 -0
- data/vendor/eac_ruby_base0/spec/rubocop_spec.rb +7 -0
- data/vendor/eac_ruby_base0/spec/spec_helper.rb +100 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb +60 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +2 -50
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb +52 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb +41 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +6 -50
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/class_initialize.rb +29 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/instance_initialize.rb +53 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/super_args.rb +54 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +10 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +4 -6
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/concat.rb +33 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/envvars.rb +24 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb +0 -21
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/abstract_methods.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/template.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/template.rb +1 -8
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/basename_sub.rb +2 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +7 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +11 -2
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb +28 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +40 -17
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +96 -8
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +12 -1
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +1 -1
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +30 -2
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/convert_job.rb +91 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/stream.rb +51 -0
- metadata +89 -13
- data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +0 -68
- data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +0 -38
- data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +0 -77
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +0 -31
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +0 -21
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/runner_with/help'
|
4
|
+
require 'eac_cli/runner_with/subcommands'
|
5
|
+
require 'eac_ruby_utils/core_ext'
|
6
|
+
|
7
|
+
module EacRubyBase0
|
8
|
+
module Runner
|
9
|
+
require_sub __FILE__
|
10
|
+
enable_console_speaker
|
11
|
+
common_concern do
|
12
|
+
include ::EacCli::RunnerWith::Help
|
13
|
+
include ::EacCli::RunnerWith::Subcommands
|
14
|
+
runner_definition do
|
15
|
+
bool_opt '-q', '--quiet', 'Quiet mode.'
|
16
|
+
bool_opt '-I', '--no-input', 'Fail if a input is requested.'
|
17
|
+
subcommands
|
18
|
+
alt do
|
19
|
+
bool_opt '-V', '--version', 'Show version.', usage: true, required: true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def run
|
25
|
+
on_speaker_node do |node|
|
26
|
+
node.stderr = ::StringIO.new if parsed.quiet?
|
27
|
+
node.stdin = FailIfRequestInput.new if parsed.no_input?
|
28
|
+
if parsed.version?
|
29
|
+
show_version
|
30
|
+
else
|
31
|
+
run_with_subcommand
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def application_version
|
37
|
+
runner_context.call(:application).version.to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
def show_version
|
41
|
+
out("#{application_version}\n")
|
42
|
+
end
|
43
|
+
|
44
|
+
class FailIfRequestInput
|
45
|
+
enable_console_speaker
|
46
|
+
|
47
|
+
%w[gets noecho].each do |method|
|
48
|
+
define_method(method) do
|
49
|
+
raise "Input method requested (\"#{method}\") and option --no-input is set"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/default_runner'
|
4
|
+
require 'eac_ruby_utils/console/docopt_runner'
|
5
|
+
require 'eac_ruby_utils/core_ext'
|
6
|
+
require 'eac_ruby_gems_utils/tests/multiple'
|
7
|
+
|
8
|
+
module EacRubyBase0
|
9
|
+
module Runner
|
10
|
+
class TestAll < ::EacRubyUtils::Console::DocoptRunner
|
11
|
+
require_sub __FILE__
|
12
|
+
include ::EacCli::DefaultRunner
|
13
|
+
|
14
|
+
runner_definition do
|
15
|
+
desc 'Test core and local gems.'
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
fatal_error 'Some test did not pass' unless tests.ok?
|
20
|
+
end
|
21
|
+
|
22
|
+
def tests_uncached
|
23
|
+
::EacRubyGemsUtils::Tests::Multiple.new(context(:application).all_gems)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
6
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
7
|
+
# files.
|
8
|
+
#
|
9
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
10
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
11
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
12
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
13
|
+
# a separate helper file that requires the additional dependencies and performs
|
14
|
+
# the additional setup, and require it from the spec files that actually need
|
15
|
+
# it.
|
16
|
+
#
|
17
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
18
|
+
RSpec.configure do |config|
|
19
|
+
# rspec-expectations config goes here. You can use an alternate
|
20
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
21
|
+
# assertions if you prefer.
|
22
|
+
config.expect_with :rspec do |expectations|
|
23
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
24
|
+
# and `failure_message` of custom matchers include text for helper methods
|
25
|
+
# defined using `chain`, e.g.:
|
26
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
27
|
+
# # => "be bigger than 2 and smaller than 4"
|
28
|
+
# ...rather than:
|
29
|
+
# # => "be bigger than 2"
|
30
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
31
|
+
end
|
32
|
+
|
33
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
34
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
35
|
+
config.mock_with :rspec do |mocks|
|
36
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
37
|
+
# a real object. This is generally recommended, and will default to
|
38
|
+
# `true` in RSpec 4.
|
39
|
+
mocks.verify_partial_doubles = true
|
40
|
+
end
|
41
|
+
|
42
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
43
|
+
# have no way to turn it off -- the option exists only for backwards
|
44
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
45
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
46
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
47
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
48
|
+
|
49
|
+
# The settings below are suggested to provide a good initial experience
|
50
|
+
# with RSpec, but feel free to customize to your heart's content.
|
51
|
+
# # This allows you to limit a spec run to individual examples or groups
|
52
|
+
# # you care about by tagging them with `:focus` metadata. When nothing
|
53
|
+
# # is tagged with `:focus`, all examples get run. RSpec also provides
|
54
|
+
# # aliases for `it`, `describe`, and `context` that include `:focus`
|
55
|
+
# # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
56
|
+
# config.filter_run_when_matching :focus
|
57
|
+
#
|
58
|
+
# # Allows RSpec to persist some state between runs in order to support
|
59
|
+
# # the `--only-failures` and `--next-failure` CLI options. We recommend
|
60
|
+
# # you configure your source control system to ignore this file.
|
61
|
+
# config.example_status_persistence_file_path = "spec/examples.txt"
|
62
|
+
#
|
63
|
+
# # Limits the available syntax to the non-monkey patched syntax that is
|
64
|
+
# # recommended. For more details, see:
|
65
|
+
# # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
66
|
+
# # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
67
|
+
# # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
68
|
+
# config.disable_monkey_patching!
|
69
|
+
#
|
70
|
+
# # This setting enables warnings. It's recommended, but in some cases may
|
71
|
+
# # be too noisy due to issues in dependencies.
|
72
|
+
# config.warnings = true
|
73
|
+
#
|
74
|
+
# # Many RSpec users commonly either run the entire suite or an individual
|
75
|
+
# # file, and it's useful to allow more verbose output when running an
|
76
|
+
# # individual spec file.
|
77
|
+
# if config.files_to_run.one?
|
78
|
+
# # Use the documentation formatter for detailed output,
|
79
|
+
# # unless a formatter has already been configured
|
80
|
+
# # (e.g. via a command-line flag).
|
81
|
+
# config.default_formatter = "doc"
|
82
|
+
# end
|
83
|
+
#
|
84
|
+
# # Print the 10 slowest examples and example groups at the
|
85
|
+
# # end of the spec run, to help surface which specs are running
|
86
|
+
# # particularly slow.
|
87
|
+
# config.profile_examples = 10
|
88
|
+
#
|
89
|
+
# # Run specs in random order to surface order dependencies. If you find an
|
90
|
+
# # order dependency and want to debug it, you can fix the order by providing
|
91
|
+
# # the seed, which is printed after each run.
|
92
|
+
# # --seed 1234
|
93
|
+
# config.order = :random
|
94
|
+
#
|
95
|
+
# # Seed global randomization in this process using the `--seed` CLI option.
|
96
|
+
# # Setting this allows you to use `--seed` to deterministically reproduce
|
97
|
+
# # test failures related to randomization by passing the same `--seed` value
|
98
|
+
# # as the one that triggered the failure.
|
99
|
+
# Kernel.srand config.seed
|
100
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/patches/module/common_concern'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
# Support to abstract methods.
|
7
|
+
#
|
8
|
+
# Usage:
|
9
|
+
#
|
10
|
+
# require 'eac_ruby_utils/abstract_methods'
|
11
|
+
#
|
12
|
+
# class BaseClass
|
13
|
+
# include EacRubyUtils::AbstractMethods
|
14
|
+
#
|
15
|
+
# abstract_methods :mymethod
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# BaseClass.new.mymethod # raise "Abstract method: mymethod"
|
19
|
+
#
|
20
|
+
# class SubClass
|
21
|
+
# def mymethod
|
22
|
+
# "Implemented"
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# SubClass.new.mymethod # return "Implemented"
|
27
|
+
module AbstractMethods
|
28
|
+
common_concern
|
29
|
+
|
30
|
+
module ClassMethods
|
31
|
+
def abstract_methods(*methods_names)
|
32
|
+
methods_names.each do |method_name|
|
33
|
+
define_method method_name do
|
34
|
+
raise_abstract_method(method_name)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module InstanceMethods
|
41
|
+
def respond_to_missing?(method_name, include_private = false)
|
42
|
+
super || abstract_method?(method_name)
|
43
|
+
end
|
44
|
+
|
45
|
+
def method_missing(method_name, *arguments, &block)
|
46
|
+
raise_abstract_method(method_name) if abstract_method?(method_name)
|
47
|
+
|
48
|
+
super
|
49
|
+
end
|
50
|
+
|
51
|
+
def abstract_method?(method_name)
|
52
|
+
self.class.abstract_methods.include?(method_name.to_sym)
|
53
|
+
end
|
54
|
+
|
55
|
+
def raise_abstract_method(method_name)
|
56
|
+
raise ::NoMethodError, "Abstract method \"#{method_name}\" hit in \"#{self}\""
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'eac_ruby_utils/simple_cache'
|
5
|
-
require 'eac_ruby_utils/patches/object/if_present'
|
3
|
+
require 'eac_ruby_utils/common_concern/module_setup'
|
6
4
|
|
7
5
|
module EacRubyUtils
|
8
6
|
class CommonConcern
|
@@ -16,53 +14,7 @@ module EacRubyUtils
|
|
16
14
|
end
|
17
15
|
|
18
16
|
def setup(a_module)
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
class Setup
|
23
|
-
include ::EacRubyUtils::SimpleCache
|
24
|
-
attr_reader :a_module, :common_concern
|
25
|
-
|
26
|
-
def initialize(common_concern, a_module)
|
27
|
-
@common_concern = common_concern
|
28
|
-
@a_module = a_module
|
29
|
-
end
|
30
|
-
|
31
|
-
def run
|
32
|
-
setup = self
|
33
|
-
a_module.extend(::ActiveSupport::Concern)
|
34
|
-
a_module.included do
|
35
|
-
%w[class_methods instance_methods after_callback].each do |suffix|
|
36
|
-
setup.send("setup_#{suffix}", self)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def setup_class_methods(base)
|
42
|
-
class_methods_module.if_present { |v| base.extend v }
|
43
|
-
end
|
44
|
-
|
45
|
-
def setup_instance_methods(base)
|
46
|
-
instance_methods_module.if_present { |v| base.include v }
|
47
|
-
end
|
48
|
-
|
49
|
-
def setup_after_callback(base)
|
50
|
-
common_concern.after_callback.if_present do |v|
|
51
|
-
base.instance_eval(&v)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def class_methods_module_uncached
|
56
|
-
a_module.const_get(CLASS_METHODS_MODULE_NAME)
|
57
|
-
rescue NameError
|
58
|
-
nil
|
59
|
-
end
|
60
|
-
|
61
|
-
def instance_methods_module_uncached
|
62
|
-
a_module.const_get(INSTANCE_METHODS_MODULE_NAME)
|
63
|
-
rescue NameError
|
64
|
-
nil
|
65
|
-
end
|
17
|
+
::EacRubyUtils::CommonConcern::ModuleSetup.new(self, a_module).run
|
66
18
|
end
|
67
19
|
end
|
68
20
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
require 'eac_ruby_utils/simple_cache'
|
5
|
+
require 'eac_ruby_utils/patches/object/if_present'
|
6
|
+
|
7
|
+
module EacRubyUtils
|
8
|
+
class CommonConcern
|
9
|
+
class ClassSetup
|
10
|
+
include ::EacRubyUtils::SimpleCache
|
11
|
+
attr_reader :a_class, :module_setup, :include_method
|
12
|
+
|
13
|
+
def initialize(module_setup, a_class, include_method)
|
14
|
+
@module_setup = module_setup
|
15
|
+
@a_class = a_class
|
16
|
+
@include_method = include_method
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
%w[class_methods instance_methods after_callback].each do |suffix|
|
21
|
+
send("setup_#{suffix}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup_class_methods
|
26
|
+
class_methods_module.if_present { |v| a_class.extend v }
|
27
|
+
end
|
28
|
+
|
29
|
+
def setup_instance_methods
|
30
|
+
instance_methods_module.if_present { |v| a_class.send(include_method, v) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup_after_callback
|
34
|
+
module_setup.common_concern.after_callback.if_present do |v|
|
35
|
+
a_class.instance_eval(&v)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def class_methods_module_uncached
|
40
|
+
module_setup.a_module.const_get(CLASS_METHODS_MODULE_NAME)
|
41
|
+
rescue NameError
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def instance_methods_module_uncached
|
46
|
+
module_setup.a_module.const_get(INSTANCE_METHODS_MODULE_NAME)
|
47
|
+
rescue NameError
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
require 'eac_ruby_utils/common_concern/class_setup'
|
5
|
+
require 'eac_ruby_utils/simple_cache'
|
6
|
+
require 'eac_ruby_utils/patches/object/if_present'
|
7
|
+
|
8
|
+
module EacRubyUtils
|
9
|
+
class CommonConcern
|
10
|
+
class ModuleSetup
|
11
|
+
include ::EacRubyUtils::SimpleCache
|
12
|
+
attr_reader :a_module, :common_concern
|
13
|
+
|
14
|
+
def initialize(common_concern, a_module)
|
15
|
+
@common_concern = common_concern
|
16
|
+
@a_module = a_module
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
a_module.extend(::ActiveSupport::Concern)
|
21
|
+
include_or_prepend(:included, :include)
|
22
|
+
include_or_prepend(:prepended, :prepend)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def include_or_prepend(module_method, class_setup_method)
|
28
|
+
setup = self
|
29
|
+
a_module.send(module_method, *a_module_method_args(module_method)) do
|
30
|
+
::EacRubyUtils::CommonConcern::ClassSetup.new(setup, self, class_setup_method).run
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def a_module_method_args(module_method)
|
35
|
+
method_arity = a_module.method(module_method).arity
|
36
|
+
method_arity = -method_arity - 1 if method_arity.negative?
|
37
|
+
method_arity.times.map { |_n| a_module }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'active_support/callbacks'
|
4
4
|
require 'eac_ruby_utils/arguments_consumer'
|
5
|
+
require 'eac_ruby_utils/common_constructor/class_initialize'
|
5
6
|
require 'ostruct'
|
6
7
|
|
7
8
|
module EacRubyUtils
|
@@ -61,6 +62,8 @@ module EacRubyUtils
|
|
61
62
|
setup_class_attr_readers(klass)
|
62
63
|
setup_class_attr_writers(klass)
|
63
64
|
setup_class_initialize(klass)
|
65
|
+
|
66
|
+
klass
|
64
67
|
end
|
65
68
|
|
66
69
|
def setup_class_attr_readers(klass)
|
@@ -74,60 +77,13 @@ module EacRubyUtils
|
|
74
77
|
end
|
75
78
|
|
76
79
|
def setup_class_initialize(klass)
|
77
|
-
common_constructor = self
|
78
80
|
klass.include(::ActiveSupport::Callbacks)
|
79
81
|
klass.define_callbacks :initialize
|
80
|
-
|
81
|
-
Initialize.new(common_constructor, args, self).run
|
82
|
-
end
|
82
|
+
::EacRubyUtils::CommonConstructor::ClassInitialize.new(self, klass).run
|
83
83
|
end
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
def initialize(common_constructor, args, object)
|
89
|
-
@common_constructor = common_constructor
|
90
|
-
@args = args
|
91
|
-
@object = object
|
92
|
-
end
|
93
|
-
|
94
|
-
def run
|
95
|
-
validate_args_count
|
96
|
-
object.run_callbacks :initialize do
|
97
|
-
object_attributes_set
|
98
|
-
object_after_callback
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
private
|
103
|
-
|
104
|
-
def arg_value(arg_name)
|
105
|
-
arg_index = common_constructor.args.index(arg_name)
|
106
|
-
if arg_index < args.count
|
107
|
-
args[arg_index]
|
108
|
-
else
|
109
|
-
common_constructor.default_values[arg_index - common_constructor.args_count_min]
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def object_after_callback
|
114
|
-
return unless common_constructor.after_set_block
|
115
|
-
|
116
|
-
object.instance_eval(&common_constructor.after_set_block)
|
117
|
-
end
|
118
|
-
|
119
|
-
def object_attributes_set
|
120
|
-
common_constructor.args.each do |arg_name|
|
121
|
-
object.send("#{arg_name}=", arg_value(arg_name))
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def validate_args_count
|
126
|
-
return if common_constructor.args_count.include?(args.count)
|
127
|
-
|
128
|
-
raise ArgumentError, "#{object.class}.initialize: wrong number of arguments" \
|
129
|
-
" (given #{args.count}, expected #{common_constructor.args_count})"
|
130
|
-
end
|
85
|
+
def super_args
|
86
|
+
options[:super_args]
|
131
87
|
end
|
132
88
|
end
|
133
89
|
end
|