ehbrs-tools 0.16.5 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs/cooking_book.rb +9 -0
  3. data/lib/ehbrs/cooking_book/build.rb +45 -0
  4. data/lib/ehbrs/cooking_book/build/base_page.rb +43 -0
  5. data/lib/ehbrs/cooking_book/build/index_page.rb +26 -0
  6. data/lib/ehbrs/cooking_book/build/recipe_page.rb +27 -0
  7. data/lib/ehbrs/cooking_book/project.rb +25 -0
  8. data/lib/ehbrs/cooking_book/recipe.rb +37 -0
  9. data/lib/ehbrs/cooking_book/recipe/ingredient.rb +21 -0
  10. data/lib/ehbrs/cooking_book/recipe/measure.rb +60 -0
  11. data/lib/ehbrs/cooking_book/recipe/part.rb +32 -0
  12. data/lib/ehbrs/patches/module/erb_template.rb +11 -0
  13. data/lib/ehbrs/patches/object/erb_template.rb +9 -0
  14. data/lib/ehbrs/patches/object/template.rb +7 -0
  15. data/lib/ehbrs/runner.rb +6 -13
  16. data/lib/ehbrs/runner/cooking_book.rb +30 -0
  17. data/lib/ehbrs/runner/cooking_book/build.rb +32 -0
  18. data/lib/ehbrs/tools/application.rb +13 -0
  19. data/lib/ehbrs/tools/version.rb +1 -1
  20. data/template/ehbrs/cooking_book/build/base_page/layout.html.erb +20 -0
  21. data/template/ehbrs/cooking_book/build/index_page/inner.html.erb +6 -0
  22. data/template/ehbrs/cooking_book/build/recipe_page/inner.html.erb +6 -0
  23. data/template/ehbrs/cooking_book/build/recipe_page/part.html.erb +27 -0
  24. data/vendor/eac_ruby_base0/Gemfile +5 -0
  25. data/vendor/eac_ruby_base0/eac_ruby_base0.gemspec +20 -0
  26. data/vendor/eac_ruby_base0/lib/eac_ruby_base0.rb +7 -0
  27. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/application.rb +69 -0
  28. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +54 -0
  29. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner/test_all.rb +27 -0
  30. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +5 -0
  31. data/vendor/eac_ruby_base0/spec/rubocop_spec.rb +7 -0
  32. data/vendor/eac_ruby_base0/spec/spec_helper.rb +100 -0
  33. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb +16 -6
  34. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +2 -99
  35. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/class_initialize.rb +29 -0
  36. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/instance_initialize.rb +53 -0
  37. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/super_args.rb +54 -0
  38. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +10 -1
  39. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/template.rb +10 -0
  40. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/template.rb +1 -8
  41. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  42. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +8 -0
  43. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +14 -4
  44. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +30 -0
  45. metadata +35 -2
@@ -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
@@ -76,111 +77,13 @@ module EacRubyUtils
76
77
  end
77
78
 
78
79
  def setup_class_initialize(klass)
79
- common_constructor = self
80
80
  klass.include(::ActiveSupport::Callbacks)
81
81
  klass.define_callbacks :initialize
82
- klass.send(:define_method, :initialize) do |*args|
83
- Initialize.new(common_constructor, args, self).run
84
- super(*SuperArgs.new(common_constructor, args, self).result)
85
- end
82
+ ::EacRubyUtils::CommonConstructor::ClassInitialize.new(self, klass).run
86
83
  end
87
84
 
88
85
  def super_args
89
86
  options[:super_args]
90
87
  end
91
-
92
- class Initialize
93
- attr_reader :common_constructor, :args, :object
94
-
95
- def initialize(common_constructor, args, object)
96
- @common_constructor = common_constructor
97
- @args = args
98
- @object = object
99
- end
100
-
101
- def run
102
- validate_args_count
103
- object.run_callbacks :initialize do
104
- object_attributes_set
105
- object_after_callback
106
- end
107
- end
108
-
109
- private
110
-
111
- def arg_value(arg_name)
112
- arg_index = common_constructor.args.index(arg_name)
113
- if arg_index < args.count
114
- args[arg_index]
115
- else
116
- common_constructor.default_values[arg_index - common_constructor.args_count_min]
117
- end
118
- end
119
-
120
- def object_after_callback
121
- return unless common_constructor.after_set_block
122
-
123
- object.instance_eval(&common_constructor.after_set_block)
124
- end
125
-
126
- def object_attributes_set
127
- common_constructor.args.each do |arg_name|
128
- object.send("#{arg_name}=", arg_value(arg_name))
129
- end
130
- end
131
-
132
- def validate_args_count
133
- return if common_constructor.args_count.include?(args.count)
134
-
135
- raise ArgumentError, "#{object.class}.initialize: wrong number of arguments" \
136
- " (given #{args.count}, expected #{common_constructor.args_count})"
137
- end
138
- end
139
-
140
- class SuperArgs
141
- attr_reader :common_constructor, :args, :object
142
-
143
- def initialize(common_constructor, args, object)
144
- @common_constructor = common_constructor
145
- @args = args
146
- @object = object
147
- end
148
-
149
- def auto_result
150
- r = []
151
- sub_args.each do |name, value|
152
- i = super_arg_index(name)
153
- r[i] = value if i
154
- end
155
- r
156
- end
157
-
158
- def result
159
- result_from_options || auto_result
160
- end
161
-
162
- def result_from_options
163
- return unless common_constructor.super_args
164
-
165
- object.instance_exec(&common_constructor.super_args)
166
- end
167
-
168
- def sub_args
169
- common_constructor.args.each_with_index.map do |name, index|
170
- [name, args[index]]
171
- end.to_h
172
- end
173
-
174
- def super_arg_index(name)
175
- super_method.parameters.each_with_index do |arg, index|
176
- return index if arg[1] == name
177
- end
178
- nil
179
- end
180
-
181
- def super_method
182
- object.class.superclass ? object.class.superclass.instance_method(:initialize) : nil
183
- end
184
- end
185
88
  end
186
89
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/common_constructor/instance_initialize'
4
+ require 'eac_ruby_utils/common_constructor/super_args'
5
+
6
+ module EacRubyUtils
7
+ class CommonConstructor
8
+ class ClassInitialize
9
+ attr_reader :common_constructor, :klass
10
+
11
+ def initialize(common_constructor, klass)
12
+ @common_constructor = common_constructor
13
+ @klass = klass
14
+ end
15
+
16
+ def run
17
+ class_initialize = self
18
+ klass.send(:define_method, :initialize) do |*args|
19
+ ::EacRubyUtils::CommonConstructor::InstanceInitialize.new(
20
+ class_initialize.common_constructor, args, self
21
+ ).run
22
+ super(*::EacRubyUtils::CommonConstructor::SuperArgs.new(
23
+ class_initialize, args, self
24
+ ).result)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ class CommonConstructor
5
+ class InstanceInitialize
6
+ attr_reader :common_constructor, :args, :object
7
+
8
+ def initialize(common_constructor, args, object)
9
+ @common_constructor = common_constructor
10
+ @args = args
11
+ @object = object
12
+ end
13
+
14
+ def run
15
+ validate_args_count
16
+ object.run_callbacks :initialize do
17
+ object_attributes_set
18
+ object_after_callback
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def arg_value(arg_name)
25
+ arg_index = common_constructor.args.index(arg_name)
26
+ if arg_index < args.count
27
+ args[arg_index]
28
+ else
29
+ common_constructor.default_values[arg_index - common_constructor.args_count_min]
30
+ end
31
+ end
32
+
33
+ def object_after_callback
34
+ return unless common_constructor.after_set_block
35
+
36
+ object.instance_eval(&common_constructor.after_set_block)
37
+ end
38
+
39
+ def object_attributes_set
40
+ common_constructor.args.each do |arg_name|
41
+ object.send("#{arg_name}=", arg_value(arg_name))
42
+ end
43
+ end
44
+
45
+ def validate_args_count
46
+ return if common_constructor.args_count.include?(args.count)
47
+
48
+ raise ArgumentError, "#{object.class}.initialize: wrong number of arguments" \
49
+ " (given #{args.count}, expected #{common_constructor.args_count})"
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/module/delegation'
4
+
5
+ module EacRubyUtils
6
+ class CommonConstructor
7
+ class SuperArgs
8
+ attr_reader :class_initialize, :args, :object
9
+ delegate :common_constructor, to: :class_initialize
10
+
11
+ def initialize(class_initialize, args, object)
12
+ @class_initialize = class_initialize
13
+ @args = args
14
+ @object = object
15
+ end
16
+
17
+ def auto_result
18
+ r = []
19
+ sub_args.each do |name, value|
20
+ i = super_arg_index(name)
21
+ r[i] = value if i
22
+ end
23
+ r
24
+ end
25
+
26
+ def result
27
+ result_from_options || auto_result
28
+ end
29
+
30
+ def result_from_options
31
+ return unless common_constructor.super_args
32
+
33
+ object.instance_exec(&common_constructor.super_args)
34
+ end
35
+
36
+ def sub_args
37
+ common_constructor.args.each_with_index.map do |name, index|
38
+ [name, args[index]]
39
+ end.to_h
40
+ end
41
+
42
+ def super_arg_index(name)
43
+ super_method.parameters.each_with_index do |arg, index|
44
+ return index if arg[1] == name
45
+ end
46
+ nil
47
+ end
48
+
49
+ def super_method
50
+ class_initialize.klass.superclass&.instance_method(:initialize)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -38,7 +38,7 @@ module EacRubyUtils
38
38
  def run_with_subcommand
39
39
  if subcommand_name
40
40
  check_valid_subcommand
41
- subcommand.run
41
+ subcommand_run
42
42
  else
43
43
  run_without_subcommand
44
44
  end
@@ -52,6 +52,15 @@ module EacRubyUtils
52
52
  )
53
53
  end
54
54
 
55
+ def subcommand_run
56
+ if !subcommand.is_a?(::EacRubyUtils::Console::DocoptRunner) &&
57
+ subcommand.respond_to?(:run_run)
58
+ subcommand.run_run
59
+ else
60
+ subcommand.run
61
+ end
62
+ end
63
+
55
64
  def target_doc
56
65
  super.gsub(SUBCOMMANDS_MACRO,
57
66
  "#{target_doc_subcommand_arg} [#{SUBCOMMAND_ARGS_ARG}...]") +
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/string/inflections'
4
+ require 'eac_ruby_utils/templates/searcher'
5
+
6
+ class Module
7
+ def template
8
+ @template ||= ::EacRubyUtils::Templates::Searcher.default.template(name.underscore)
9
+ end
10
+ end
@@ -1,15 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/core_ext/string/inflections'
4
- require 'eac_ruby_utils/templates/searcher'
3
+ require 'eac_ruby_utils/patches/module/template'
5
4
 
6
5
  class Object
7
- class << self
8
- def template
9
- @template ||= ::EacRubyUtils::Templates::Searcher.default.template(name.underscore)
10
- end
11
- end
12
-
13
6
  def template
14
7
  self.class.template
15
8
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.56.0'
4
+ VERSION = '0.57.0'
5
5
  end
@@ -14,10 +14,18 @@ module EacRubyUtils
14
14
  ::YAML.dump(sanitize(object))
15
15
  end
16
16
 
17
+ def dump_file(path, object)
18
+ ::File.write(path.to_s, dump(object))
19
+ end
20
+
17
21
  def load(string)
18
22
  ::YAML.safe_load(string, permitted_classes)
19
23
  end
20
24
 
25
+ def load_file(path)
26
+ load(::File.read(path.to_s))
27
+ end
28
+
21
29
  def permitted_classes
22
30
  DEFAULT_PERMITTED_CLASSES
23
31
  end
@@ -19,7 +19,7 @@ RSpec.describe ::EacRubyUtils::CommonConcern do
19
19
 
20
20
  module InstanceMethods # rubocop:disable RSpec/LeakyConstantDeclaration
21
21
  def my_instance_method
22
- 'instance'
22
+ 'from_module'
23
23
  end
24
24
  end
25
25
  end
@@ -31,8 +31,8 @@ RSpec.describe ::EacRubyUtils::CommonConcern do
31
31
  attr_accessor :valor
32
32
  end
33
33
 
34
- def method1
35
- 'from_stub_module'
34
+ def my_instance_method
35
+ 'from_class'
36
36
  end
37
37
  end
38
38
  end
@@ -48,7 +48,17 @@ RSpec.describe ::EacRubyUtils::CommonConcern do
48
48
  stub_class.include stub_module
49
49
  end
50
50
 
51
- it { expect(stub_class_instance.my_instance_method).to eq('instance') }
51
+ it { expect(stub_class_instance.my_instance_method).to eq('from_class') }
52
+ it { expect(stub_class_instance.class.my_class_method).to eq('class') }
53
+ it { expect(stub_class_instance.class.valor).to eq('changed') }
54
+ end
55
+
56
+ context 'when prepended' do
57
+ before do
58
+ stub_class.prepend stub_module
59
+ end
60
+
61
+ it { expect(stub_class_instance.my_instance_method).to eq('from_module') }
52
62
  it { expect(stub_class_instance.class.my_class_method).to eq('class') }
53
63
  it { expect(stub_class_instance.class.valor).to eq('changed') }
54
64
  end
@@ -92,4 +92,34 @@ RSpec.describe ::EacRubyUtils::CommonConstructor do
92
92
  end
93
93
  end
94
94
  end
95
+
96
+ context 'with class hierarchy mixed with and without common_constructor' do
97
+ let(:klass_0) do
98
+ described_class.new(:a_param).setup_class(::Class.new)
99
+ end
100
+
101
+ let(:klass_1) do
102
+ ::Class.new(klass_0) do
103
+ def initialize(a_param)
104
+ super(a_param)
105
+ end
106
+ end
107
+ end
108
+
109
+ let(:klass_2) do
110
+ ::Class.new(klass_1)
111
+ end
112
+
113
+ let(:klass_3) do
114
+ described_class.new(:a_param).setup_class(::Class.new(klass_2))
115
+ end
116
+
117
+ 4.times.each do |i|
118
+ context "wit #{i}-th class" do
119
+ let(:class_instance) { send("klass_#{i}").new(:a) }
120
+
121
+ it { expect(class_instance.a_param).to eq(:a) }
122
+ end
123
+ end
124
+ end
95
125
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ehbrs-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.5
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-26 00:00:00.000000000 Z
11
+ date: 2021-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avm-tools
@@ -116,6 +116,16 @@ files:
116
116
  - Gemfile
117
117
  - exe/ehbrs
118
118
  - lib/ehbrs.rb
119
+ - lib/ehbrs/cooking_book.rb
120
+ - lib/ehbrs/cooking_book/build.rb
121
+ - lib/ehbrs/cooking_book/build/base_page.rb
122
+ - lib/ehbrs/cooking_book/build/index_page.rb
123
+ - lib/ehbrs/cooking_book/build/recipe_page.rb
124
+ - lib/ehbrs/cooking_book/project.rb
125
+ - lib/ehbrs/cooking_book/recipe.rb
126
+ - lib/ehbrs/cooking_book/recipe/ingredient.rb
127
+ - lib/ehbrs/cooking_book/recipe/measure.rb
128
+ - lib/ehbrs/cooking_book/recipe/part.rb
119
129
  - lib/ehbrs/executables.rb
120
130
  - lib/ehbrs/fs.rb
121
131
  - lib/ehbrs/fs/compressed_package.rb
@@ -126,7 +136,12 @@ files:
126
136
  - lib/ehbrs/observers.rb
127
137
  - lib/ehbrs/observers/base.rb
128
138
  - lib/ehbrs/observers/with_persistence.rb
139
+ - lib/ehbrs/patches/module/erb_template.rb
140
+ - lib/ehbrs/patches/object/erb_template.rb
141
+ - lib/ehbrs/patches/object/template.rb
129
142
  - lib/ehbrs/runner.rb
143
+ - lib/ehbrs/runner/cooking_book.rb
144
+ - lib/ehbrs/runner/cooking_book/build.rb
130
145
  - lib/ehbrs/runner/finances.rb
131
146
  - lib/ehbrs/runner/finances/bb_browser.rb
132
147
  - lib/ehbrs/runner/fs.rb
@@ -152,6 +167,7 @@ files:
152
167
  - lib/ehbrs/self/observers/used_space.rb
153
168
  - lib/ehbrs/self/observers/with_persistence.rb
154
169
  - lib/ehbrs/tools.rb
170
+ - lib/ehbrs/tools/application.rb
155
171
  - lib/ehbrs/tools/version.rb
156
172
  - lib/ehbrs/user_dirs.rb
157
173
  - lib/ehbrs/vg.rb
@@ -202,6 +218,10 @@ files:
202
218
  - lib/ehbrs/videos/unsupported/profiles/samsung.rb
203
219
  - lib/ehbrs/videos/unsupported/search.rb
204
220
  - lib/ehbrs/videos/unsupported/track.rb
221
+ - template/ehbrs/cooking_book/build/base_page/layout.html.erb
222
+ - template/ehbrs/cooking_book/build/index_page/inner.html.erb
223
+ - template/ehbrs/cooking_book/build/recipe_page/inner.html.erb
224
+ - template/ehbrs/cooking_book/build/recipe_page/part.html.erb
205
225
  - vendor/aranha-parsers/Gemfile
206
226
  - vendor/aranha-parsers/aranha-parsers.gemspec
207
227
  - vendor/aranha-parsers/lib/aranha/parsers.rb
@@ -308,6 +328,15 @@ files:
308
328
  - vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec_files/stub_docker_image/Dockerfile
309
329
  - vendor/eac_docker/spec/rubocop_spec.rb
310
330
  - vendor/eac_docker/spec/spec_helper.rb
331
+ - vendor/eac_ruby_base0/Gemfile
332
+ - vendor/eac_ruby_base0/eac_ruby_base0.gemspec
333
+ - vendor/eac_ruby_base0/lib/eac_ruby_base0.rb
334
+ - vendor/eac_ruby_base0/lib/eac_ruby_base0/application.rb
335
+ - vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb
336
+ - vendor/eac_ruby_base0/lib/eac_ruby_base0/runner/test_all.rb
337
+ - vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb
338
+ - vendor/eac_ruby_base0/spec/rubocop_spec.rb
339
+ - vendor/eac_ruby_base0/spec/spec_helper.rb
311
340
  - vendor/eac_ruby_utils/Gemfile
312
341
  - vendor/eac_ruby_utils/MIT-LICENCE
313
342
  - vendor/eac_ruby_utils/README.rdoc
@@ -322,6 +351,9 @@ files:
322
351
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb
323
352
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb
324
353
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb
354
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/class_initialize.rb
355
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/instance_initialize.rb
356
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/super_args.rb
325
357
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/configs.rb
326
358
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.rb
327
359
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/file.rb
@@ -411,6 +443,7 @@ files:
411
443
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/patch.rb
412
444
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/require_sub.rb
413
445
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/simple_cache.rb
446
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/template.rb
414
447
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object.rb
415
448
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/asserts.rb
416
449
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb