avm-tools 0.75.1 → 0.79.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/files/formatter.rb +8 -4
  3. data/lib/avm/git/auto_commit_path.rb +2 -4
  4. data/lib/avm/git/auto_commit_path/ruby.rb +20 -0
  5. data/lib/avm/patches/class/i18n.rb +31 -0
  6. data/lib/avm/patches/object/i18n.rb +2 -10
  7. data/lib/avm/projects/stereotypes/ruby_gem/update.rb +4 -1
  8. data/lib/avm/projects/stereotypes/ruby_gem/version_bump.rb +1 -2
  9. data/lib/avm/tools/runner/eac_redmine_base0/project_rename.rb +7 -16
  10. data/lib/avm/tools/runner/files/format.rb +3 -2
  11. data/lib/avm/tools/runner/git/auto_commit.rb +11 -0
  12. data/lib/avm/tools/runner/git/subrepo/clone.rb +84 -0
  13. data/lib/avm/tools/version.rb +1 -1
  14. data/template/avm/eac_redmine_base0/deploy/config/install.sh.template +12 -0
  15. data/vendor/eac_cli/eac_cli.gemspec +1 -1
  16. data/vendor/eac_cli/lib/eac_cli/definition.rb +49 -22
  17. data/vendor/eac_cli/lib/eac_cli/definition/alternative.rb +83 -0
  18. data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +17 -1
  19. data/vendor/eac_cli/lib/eac_cli/{parser/options_collection.rb → definition/help_formatter.rb} +20 -49
  20. data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +21 -4
  21. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +18 -40
  22. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb +50 -0
  23. data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +1 -0
  24. data/vendor/eac_cli/lib/eac_cli/parser.rb +21 -3
  25. data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +88 -0
  26. data/vendor/eac_cli/lib/eac_cli/parser/alternative/argv.rb +17 -0
  27. data/vendor/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb +24 -0
  28. data/vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb +58 -0
  29. data/vendor/eac_cli/lib/eac_cli/parser/alternative/positionals.rb +30 -0
  30. data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +4 -0
  31. data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +2 -1
  32. data/vendor/eac_cli/lib/eac_cli/runner.rb +6 -2
  33. data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +1 -1
  34. data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +5 -1
  35. data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +96 -0
  36. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  37. data/vendor/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb +14 -0
  38. data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +35 -0
  39. data/vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb +140 -0
  40. data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +57 -40
  41. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb +53 -0
  42. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +57 -0
  43. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/application.rb +32 -1
  44. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +1 -1
  45. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
  46. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb +60 -0
  47. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +53 -0
  48. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +4 -69
  49. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/entry_reader.rb +81 -0
  50. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/password_entry_reader.rb +18 -0
  51. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +7 -2
  52. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb +27 -0
  53. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator.rb +4 -0
  54. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/current.rb +9 -0
  55. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/stopped.rb +14 -0
  56. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/abstract_methods.rb +10 -0
  57. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +17 -0
  58. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  59. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +3 -2
  60. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb +28 -0
  61. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +66 -8
  62. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/current_spec.rb +26 -0
  63. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/stopped_spec.rb +32 -0
  64. metadata +31 -5
  65. data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +0 -21
  66. data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +0 -49
@@ -0,0 +1,140 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/docopt/runner_extension'
4
+
5
+ RSpec.describe ::EacCli::Parser::Alternative do
6
+ let(:instance) { described_class.new(alternative, argv) }
7
+ let(:actual_parsed) { instance.parsed.to_h.symbolize_keys }
8
+
9
+ context 'without subcommands' do
10
+ let(:alternative) do
11
+ r = ::EacCli::Definition::Alternative.new
12
+ r.bool_opt '-b', '--opt1', 'A boolean option'
13
+ r.arg_opt '-a', '--opt2', 'A argument option'
14
+ r.bool_opt '-c', '--opt3', 'A required boolean option', required: true
15
+ r.pos_arg :pos1
16
+ r.pos_arg :pos2, optional: true, repeat: true
17
+ r
18
+ end
19
+
20
+ context 'with all values' do
21
+ let(:argv) { %w[--opt1 --opt2 OPT2 --opt3 POS1 POS2_1 POS2_2] }
22
+ let(:parsed_expected) do
23
+ {
24
+ opt1: true, opt2: 'OPT2', opt3: true, pos1: 'POS1', pos2: %w[POS2_1 POS2_2]
25
+ }
26
+ end
27
+
28
+ it { expect(instance.error).to be_blank }
29
+ it { expect(actual_parsed).to eq(parsed_expected) }
30
+ end
31
+
32
+ context 'with only required values' do
33
+ let(:argv) { %w[--opt3 POS1] }
34
+ let(:parsed_expected) { { opt1: false, opt2: nil, opt3: true, pos1: 'POS1', pos2: [] } }
35
+
36
+ it { expect(instance.error).to be_blank }
37
+ it { expect(actual_parsed).to eq(parsed_expected) }
38
+ end
39
+
40
+ context 'with double dash' do
41
+ let(:argv) { %w[--opt3 POS1 -- --opt1 --] }
42
+ let(:parsed_expected) do
43
+ { opt1: false, opt2: nil, opt3: true, pos1: 'POS1', pos2: %w[--opt1 --] }
44
+ end
45
+
46
+ it { expect(instance.error).to be_blank }
47
+ it { expect(actual_parsed).to eq(parsed_expected) }
48
+ end
49
+
50
+ context 'without required positional' do
51
+ let(:argv) { %w[--opt1 --opt3] }
52
+ let(:parsed_expected) { { opt1: true, opt2: nil, opt3: true, pos1: nil, pos2: [] } }
53
+
54
+ it { expect(instance.error).to be_present }
55
+ it { expect(actual_parsed).to eq(parsed_expected) }
56
+ end
57
+
58
+ context 'without required option' do
59
+ let(:argv) { %w[--opt1 POS1] }
60
+ let(:parsed_expected) { { opt1: true, opt2: nil, opt3: false, pos1: 'POS1', pos2: [] } }
61
+
62
+ it { expect(instance.error).to be_present }
63
+ it { expect(actual_parsed).to eq(parsed_expected) }
64
+ end
65
+
66
+ context 'without any required option or positional' do
67
+ let(:argv) { %w[] }
68
+ let(:parsed_expected) { { opt1: false, opt2: nil, opt3: false, pos1: nil, pos2: [] } }
69
+
70
+ it { expect(instance.error).to be_present }
71
+ it { expect(actual_parsed).to eq(parsed_expected) }
72
+ end
73
+
74
+ context 'with excedent positional' do
75
+ let(:alternative) do
76
+ r = ::EacCli::Definition::Alternative.new
77
+ r.pos_arg :pos1
78
+ r
79
+ end
80
+
81
+ let(:argv) { %w[POS1 POS2] }
82
+ let(:parsed_expected) { { pos1: 'POS1' } }
83
+
84
+ it { expect(instance.error).to be_present }
85
+ it { expect(actual_parsed).to eq(parsed_expected) }
86
+ end
87
+ end
88
+
89
+ context 'with subcommands' do
90
+ let(:alternative) do
91
+ r = ::EacCli::Definition::Alternative.new
92
+ r.bool_opt '-b', '--opt1', 'A boolean option'
93
+ r.arg_opt '-a', '--opt2', 'A argument option'
94
+ r.subcommands
95
+ r
96
+ end
97
+
98
+ context 'with all values' do
99
+ let(:argv) { %w[--opt1 --opt2 OPT2 CMD CMD_ARG_1 --CMD_ARG_2] }
100
+ let(:parsed_expected) do
101
+ {
102
+ opt1: true, opt2: 'OPT2',
103
+ ::EacCli::Definition::Alternative::SUBCOMMAND_NAME_ARG => 'CMD',
104
+ ::EacCli::Definition::Alternative::SUBCOMMAND_ARGS_ARG => %w[CMD_ARG_1 --CMD_ARG_2]
105
+ }
106
+ end
107
+
108
+ it { expect(instance.error).to be_blank }
109
+ it { expect(actual_parsed).to eq(parsed_expected) }
110
+ end
111
+
112
+ context 'with only required values' do
113
+ let(:argv) { %w[CMD] }
114
+ let(:parsed_expected) do
115
+ {
116
+ opt1: false, opt2: nil,
117
+ ::EacCli::Definition::Alternative::SUBCOMMAND_NAME_ARG => 'CMD',
118
+ ::EacCli::Definition::Alternative::SUBCOMMAND_ARGS_ARG => []
119
+ }
120
+ end
121
+
122
+ it { expect(instance.error).to be_blank }
123
+ it { expect(actual_parsed).to eq(parsed_expected) }
124
+ end
125
+
126
+ context 'without required values' do
127
+ let(:argv) { %w[--opt1] }
128
+ let(:parsed_expected) do
129
+ {
130
+ opt1: true, opt2: nil,
131
+ ::EacCli::Definition::Alternative::SUBCOMMAND_NAME_ARG => nil,
132
+ ::EacCli::Definition::Alternative::SUBCOMMAND_ARGS_ARG => []
133
+ }
134
+ end
135
+
136
+ it { expect(instance.error).to be_present }
137
+ it { expect(actual_parsed).to eq(parsed_expected) }
138
+ end
139
+ end
140
+ end
@@ -4,67 +4,84 @@ require 'eac_ruby_utils/console/docopt_runner'
4
4
  require 'eac_cli/runner'
5
5
 
6
6
  RSpec.describe ::EacCli::Runner do
7
- let(:stub_runner) do
8
- r = Class.new(::EacRubyUtils::Console::DocoptRunner) do
7
+ let(:runner_class) do
8
+ the_module = described_class
9
+ ::Class.new do
10
+ include the_module
11
+
12
+ runner_definition do
13
+ arg_opt '-o', '--opt1', 'A arg option.'
14
+ bool_opt '-o', '--opt2', 'A boolean option'
15
+ pos_arg :pos1
16
+ pos_arg :pos2, repeat: true, optional: true
17
+ alt do
18
+ bool_opt '-a', '--opt3', 'A boolean option in a alternative.', required: true
19
+ end
20
+ end
21
+
9
22
  def run; end
10
23
  end
11
- r.include described_class
12
- r.runner_definition do
13
- desc 'A stub runner.'
14
- arg_opt '-o', '--opt1', 'A argument option'
15
- pos_arg 'pos1'
16
- end
17
- r
18
24
  end
19
25
 
20
- let(:instance) { stub_runner.new(argv: %w[-o aaa bbb]) }
26
+ let(:instance) { runner_class.create(argv) }
27
+ let(:parsed_actual) { instance.parsed.to_h.symbolize_keys }
28
+
29
+ context 'when all args are supplied' do
30
+ let(:argv) { %w[--opt1 aaa --opt2 bbb ccc ddd] }
31
+ let(:parsed_expected) { { opt1: 'aaa', opt2: true, pos1: 'bbb', pos2: %w[ccc ddd] } }
32
+
33
+ it { expect(parsed_actual).to eq(parsed_expected) }
34
+ it { expect(instance.parsed.opt1).to eq('aaa') }
35
+ it { expect(instance.parsed.opt2?).to eq(true) }
36
+ it { expect(instance.parsed.pos1).to eq('bbb') }
37
+ it { expect(instance.parsed.pos2).to eq(%w[ccc ddd]) }
38
+ end
39
+
40
+ context 'when only required args are supplied' do
41
+ let(:argv) { %w[bbb] }
42
+ let(:parsed_expected) { { opt1: nil, opt2: false, pos1: 'bbb', pos2: [] } }
21
43
 
22
- before { instance.run }
44
+ it { expect(parsed_actual).to eq(parsed_expected) }
45
+ it { expect(instance.parsed.opt1).to be_nil }
46
+ it { expect(instance.parsed.opt2?).to eq(false) }
47
+ it { expect(instance.parsed.pos1).to eq('bbb') }
48
+ it { expect(instance.parsed.pos2).to eq([]) }
49
+ end
23
50
 
24
- it { expect(instance.options.fetch('--opt1')).to eq('aaa') }
25
- it { expect(instance.options.fetch('<pos1>')).to eq('bbb') }
51
+ context 'when required args are not supplied' do
52
+ let(:argv) { %w[] }
26
53
 
27
- context 'without docopt runner' do
54
+ it do
55
+ expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
56
+ end
57
+ end
58
+
59
+ context 'when alternative args are supplied' do
60
+ let(:argv) { %w[--opt3] }
61
+ let(:parsed_expected) { { opt3: true } }
62
+
63
+ it { expect(parsed_actual).to eq(parsed_expected) }
64
+ it { expect(instance.parsed.opt3?).to eq(true) }
65
+ end
66
+
67
+ context 'when extra args are not supplied' do
28
68
  let(:runner_class) do
29
69
  the_module = described_class
30
70
  ::Class.new do
31
71
  include the_module
32
72
 
33
73
  runner_definition do
34
- arg_opt '-o', '--opt1', 'A arg option.'
35
- bool_opt '-o', '--opt2', 'A boolean option'
36
74
  pos_arg :pos1
37
- pos_arg :pos2, repeat: true, optional: true
38
75
  end
39
76
 
40
77
  def run; end
41
78
  end
42
79
  end
43
80
 
44
- context 'when all args are supplied' do
45
- let(:instance) { runner_class.create(%w[--opt1 aaa --opt2 bbb ccc ddd]) }
46
-
47
- it { expect(instance.parsed.opt1).to eq('aaa') }
48
- it { expect(instance.parsed.opt2?).to eq(true) }
49
- it { expect(instance.parsed.pos1).to eq('bbb') }
50
- it { expect(instance.parsed.pos2).to eq(%w[ccc ddd]) }
51
- end
81
+ let(:argv) { %w[aaa bbb] }
52
82
 
53
- context 'when only required args are supplied' do
54
- let(:instance) { runner_class.create(%w[bbb]) }
55
-
56
- it { expect(instance.parsed.opt1).to be_nil }
57
- it { expect(instance.parsed.opt2?).to eq(false) }
58
- it { expect(instance.parsed.pos1).to eq('bbb') }
59
- it { expect(instance.parsed.pos2).to eq([]) }
60
- end
61
-
62
- context 'when required args are not supplied' do
63
- let(:instance) { runner_class.create(%w[]) }
64
-
65
- it do
66
- expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
67
- end
83
+ it do
84
+ expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
68
85
  end
69
86
  end
70
87
  end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner_with/output_file'
4
+ require 'eac_ruby_utils/fs/temp'
5
+
6
+ RSpec.describe ::EacCli::RunnerWith::OutputFile do
7
+ let(:runner) do
8
+ the_module = described_class
9
+ Class.new do
10
+ include the_module
11
+
12
+ runner_definition do
13
+ desc 'A stub root runner.'
14
+ pos_arg :input_text
15
+ end
16
+
17
+ def run
18
+ run_output
19
+ end
20
+
21
+ def output_content
22
+ parsed.input_text
23
+ end
24
+ end
25
+ end
26
+
27
+ let(:stub_text) { 'STUB_TEXT' }
28
+ let(:instance) { runner.create(argv: runner_argv) }
29
+
30
+ context 'without --output-file option' do
31
+ let(:runner_argv) { [stub_text] }
32
+
33
+ it do
34
+ expect { instance.run }.to output(stub_text).to_stdout_from_any_process
35
+ end
36
+ end
37
+
38
+ context 'with --output-file option' do
39
+ let(:output_file) { ::EacRubyUtils::Fs::Temp.file }
40
+ let(:runner_argv) { ['--output-file', output_file.to_path, stub_text] }
41
+
42
+ before do
43
+ instance.run
44
+ end
45
+
46
+ after do
47
+ output_file.remove
48
+ end
49
+
50
+ it { expect(output_file).to exist }
51
+ it { expect(output_file.read).to eq(stub_text) }
52
+ end
53
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner'
4
+ require 'eac_cli/runner_with/subcommands'
5
+
6
+ RSpec.describe ::EacCli::RunnerWith::Subcommands do
7
+ let(:parent_runner) do
8
+ the_module = described_class
9
+ the_child = child_runner
10
+ Class.new do
11
+ include ::EacCli::Runner
12
+ include the_module
13
+ const_set('ChildCmd', the_child)
14
+
15
+ runner_definition do
16
+ desc 'A stub root runner.'
17
+ arg_opt '-r', '--root-var', 'A root variable.'
18
+ subcommands
19
+ end
20
+
21
+ delegate :root_var, to: :parsed
22
+ end
23
+ end
24
+
25
+ let(:child_runner) do
26
+ ::Class.new do
27
+ include ::EacCli::Runner
28
+
29
+ runner_definition do
30
+ bool_opt '-c', '--child-opt', 'A boolean option.'
31
+ pos_arg :child_var
32
+ end
33
+
34
+ def run; end
35
+ end
36
+ end
37
+
38
+ let(:instance) { parent_runner.create(argv: parent_argv) }
39
+
40
+ context 'when subcommand is supplied' do
41
+ let(:parent_argv) { %w[--root-var 123 child-cmd --child-opt 456] }
42
+
43
+ it { expect(instance.parsed.root_var).to eq('123') }
44
+ it { expect(instance.parsed.subcommand).to eq('child-cmd') }
45
+ it { expect(instance.parsed.subcommand_args).to eq(%w[--child-opt 456]) }
46
+ it { expect(instance.subcommand_runner.parsed.child_opt).to eq(true) }
47
+ it { expect(instance.subcommand_runner.parsed.child_var).to eq('456') }
48
+ end
49
+
50
+ context 'when subcommand is not supplied' do
51
+ let(:instance) { parent_runner.create(%w[456]) }
52
+
53
+ it do
54
+ expect { instance.run }.to raise_error(::EacCli::Parser::Error)
55
+ end
56
+ end
57
+ end
@@ -1,12 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/filesystem_cache'
4
5
 
5
6
  module EacRubyBase0
6
7
  class Application
7
8
  enable_simple_cache
8
- common_constructor :gemspec_dir do
9
+ enable_listable
10
+ lists.add_symbol :option, :name, :home_dir
11
+
12
+ common_constructor :gemspec_dir, :options, default: [{}] do
9
13
  self.gemspec_dir = gemspec_dir.to_pathname
14
+ self.options = options.symbolize_keys.assert_valid_keys(self.class.lists.option.values).freeze
10
15
  end
11
16
 
12
17
  delegate :version, to: :self_gem
@@ -15,6 +20,32 @@ module EacRubyBase0
15
20
  vendor_gems + [self_gem]
16
21
  end
17
22
 
23
+ { cache: '.cache', config: '.config', data: '.local/share' }.each do |item, subpath|
24
+ xdg_env_method_name = "#{item}_xdg_env"
25
+
26
+ define_method xdg_env_method_name do
27
+ ENV["XDG_#{item.upcase}_HOME"].if_present(&:to_pathname)
28
+ end
29
+
30
+ define_method "#{item}_dir" do
31
+ (send(xdg_env_method_name) || home_dir.join(subpath)).join(name)
32
+ end
33
+ end
34
+
35
+ def fs_cache
36
+ @fs_cache ||= ::EacRubyUtils::FilesystemCache.new(
37
+ cache_dir.join(::EacRubyUtils::FilesystemCache.name.parameterize)
38
+ )
39
+ end
40
+
41
+ def home_dir
42
+ @home_dir ||= (options[OPTION_HOME_DIR] || ENV.fetch('HOME')).to_pathname
43
+ end
44
+
45
+ def name
46
+ options[OPTION_NAME] || self_gem.name
47
+ end
48
+
18
49
  def vendor_dir
19
50
  gemspec_dir.join('vendor')
20
51
  end
@@ -13,7 +13,7 @@ module EacRubyBase0
13
13
  bool_opt '-I', '--no-input', 'Fail if a input is requested.'
14
14
  subcommands
15
15
  alt do
16
- bool_opt '-V', '--version', 'Show version.'
16
+ bool_opt '-V', '--version', 'Show version.', usage: true, required: true
17
17
  end
18
18
  end
19
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyBase0
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.1'
5
5
  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