upgrow 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/test_unit/input/input_generator.rb +22 -0
- data/lib/generators/test_unit/input/templates/input_test.rb.tt +8 -0
- data/lib/generators/test_unit/install/install_generator.rb +48 -0
- data/lib/generators/test_unit/record/record_generator.rb +22 -0
- data/lib/generators/test_unit/record/templates/record_test.rb.tt +8 -0
- data/lib/generators/test_unit/repository/repository_generator.rb +23 -0
- data/lib/generators/test_unit/repository/templates/repository_test.rb.tt +8 -0
- data/lib/generators/upgrow.rb +54 -0
- data/lib/generators/upgrow/action/USAGE +13 -0
- data/lib/generators/upgrow/action/action_generator.rb +24 -0
- data/lib/generators/upgrow/action/templates/action.rb.tt +9 -0
- data/lib/generators/upgrow/input/USAGE +10 -0
- data/lib/generators/upgrow/input/input_generator.rb +26 -0
- data/lib/generators/upgrow/input/templates/input.rb.tt +6 -0
- data/lib/generators/upgrow/install/USAGE +25 -0
- data/lib/generators/upgrow/install/install_generator.rb +56 -0
- data/lib/generators/upgrow/install/templates/app/actions/application_action.rb.tt +4 -0
- data/lib/generators/upgrow/install/templates/app/inputs/application_input.rb.tt +4 -0
- data/lib/generators/upgrow/install/templates/app/models/application_model.rb.tt +4 -0
- data/lib/generators/upgrow/install/templates/app/repositories/application_repository.rb.tt +4 -0
- data/lib/generators/upgrow/model/USAGE +10 -0
- data/lib/generators/upgrow/model/model_generator.rb +24 -0
- data/lib/generators/upgrow/model/templates/model.rb.tt +6 -0
- data/lib/generators/upgrow/record/record_generator.rb +34 -0
- data/lib/generators/upgrow/record/templates/record.rb.tt +6 -0
- data/lib/generators/upgrow/repository/USAGE +10 -0
- data/lib/generators/upgrow/repository/repository_generator.rb +27 -0
- data/lib/generators/upgrow/repository/templates/repository.rb.tt +6 -0
- data/lib/upgrow.rb +3 -0
- data/lib/upgrow/active_record_conversion.rb +2 -3
- data/lib/upgrow/active_record_queries.rb +1 -2
- data/lib/upgrow/active_record_schema.rb +1 -3
- data/lib/upgrow/basic_model.rb +11 -0
- data/lib/upgrow/model.rb +2 -1
- data/lib/upgrow/naming.rb +40 -0
- data/lib/upgrow/railtie.rb +9 -0
- data/lib/upgrow/record.rb +121 -0
- data/test/dummy/app/records/application_record.rb +2 -0
- data/test/dummy/app/records/article_record.rb +2 -3
- data/test/dummy/app/records/comment_record.rb +2 -3
- data/test/dummy/app/records/user_record.rb +2 -4
- data/test/dummy/app/repositories/article_repository.rb +3 -3
- data/test/test_unit/generators/input_generator_test.rb +56 -0
- data/test/test_unit/generators/install_generator_test.rb +138 -0
- data/test/test_unit/generators/record_generator_test.rb +56 -0
- data/test/test_unit/generators/repository_generator_test.rb +57 -0
- data/test/upgrow/active_record_conversion_test.rb +2 -2
- data/test/upgrow/active_record_schema_test.rb +1 -1
- data/test/upgrow/basic_model_test.rb +85 -0
- data/test/upgrow/generators/action_generator_test.rb +59 -0
- data/test/upgrow/generators/helper_test.rb +86 -0
- data/test/upgrow/generators/input_generator_test.rb +65 -0
- data/test/upgrow/generators/install_generator_test.rb +158 -0
- data/test/upgrow/generators/model_generator_test.rb +39 -0
- data/test/upgrow/generators/record_generator_test.rb +65 -0
- data/test/upgrow/generators/repository_generator_test.rb +50 -0
- data/test/upgrow/naming_test.rb +22 -0
- data/test/upgrow/record_test.rb +176 -0
- metadata +60 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b23ff76f5c5a26695d3b695084c7196938b758c924c433a9abf17f1918aa7c3
|
4
|
+
data.tar.gz: 6799c1a519cddbfa59f16817d4589a6b935c6a581fd7a9b34a58a1ded5399c92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c239023970e3d67967420c64bcf836b6c7ae6e56034e04a676148aafb78e99f364a3ab821f11bcc1392e59ce7627f0d5c4c183e734a3631be74d6f5e0f46a8b
|
7
|
+
data.tar.gz: 75eb566265b8904dfffd8edb2069ebe4cc676a4e9150d7b0cc507a7c607d6049e4becd66c285a50ad8786336acbe3d7f05d386e9363dade2893a13c40ef6d544
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'generators/upgrow'
|
4
|
+
|
5
|
+
module TestUnit
|
6
|
+
module Generators
|
7
|
+
class InputGenerator < Rails::Generators::NamedBase
|
8
|
+
include Upgrow::Generators::Helper
|
9
|
+
|
10
|
+
def create_test_file
|
11
|
+
template('input_test.rb',
|
12
|
+
File.join('test/inputs', class_path, "#{file_name}_input_test.rb"))
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def file_name
|
18
|
+
super.delete_suffix('_input')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'generators/upgrow'
|
4
|
+
|
5
|
+
module TestUnit
|
6
|
+
module Generators
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
8
|
+
include Upgrow::Generators::Helper
|
9
|
+
|
10
|
+
def move_existing_models
|
11
|
+
pattern = File.expand_path('test/models/**/*_test.rb', destination_root)
|
12
|
+
files = Dir.glob(pattern)
|
13
|
+
|
14
|
+
return if files.empty?
|
15
|
+
|
16
|
+
unless yes?('Would you like to convert existing model tests into '\
|
17
|
+
'Record tests?', :blue)
|
18
|
+
say(
|
19
|
+
'Please convert your model tests into Record tests manually by '\
|
20
|
+
'moving them to the test/records directory and adding the '\
|
21
|
+
'RecordTest suffix to their class names.',
|
22
|
+
:yellow
|
23
|
+
)
|
24
|
+
return
|
25
|
+
end
|
26
|
+
|
27
|
+
files.each do |original|
|
28
|
+
target = relative_to_original_destination_root(original)
|
29
|
+
.sub(%r{\Atest/models/}, 'test/records/')
|
30
|
+
.sub(/^(.+(?<!_record))_test\.rb\z/, '\1_record_test.rb')
|
31
|
+
|
32
|
+
move_file(original, target)
|
33
|
+
|
34
|
+
inject_into_file(
|
35
|
+
target, 'Record',
|
36
|
+
before: /(?<!Record)Test < /,
|
37
|
+
force: true,
|
38
|
+
verbose: false
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_test_directories
|
44
|
+
directory('test')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'generators/upgrow'
|
4
|
+
|
5
|
+
module TestUnit
|
6
|
+
module Generators
|
7
|
+
class RecordGenerator < Rails::Generators::NamedBase
|
8
|
+
include Upgrow::Generators::Helper
|
9
|
+
|
10
|
+
def create_test_file
|
11
|
+
template('record_test.rb',
|
12
|
+
File.join('test/records', class_path, "#{file_name}_record_test.rb"))
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def file_name
|
18
|
+
super.delete_suffix('_record')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'generators/upgrow'
|
4
|
+
|
5
|
+
module TestUnit
|
6
|
+
module Generators
|
7
|
+
class RepositoryGenerator < Rails::Generators::NamedBase
|
8
|
+
include Upgrow::Generators::Helper
|
9
|
+
|
10
|
+
def create_test_file
|
11
|
+
template('repository_test.rb',
|
12
|
+
File.join('test/repositories', class_path,
|
13
|
+
"#{file_name}_repository_test.rb"))
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def file_name
|
19
|
+
super.delete_suffix('_repository')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Upgrow
|
4
|
+
module Generators
|
5
|
+
module Helper
|
6
|
+
module ClassMethods
|
7
|
+
def base_root
|
8
|
+
__dir__
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.included(base)
|
13
|
+
base.extend(ClassMethods)
|
14
|
+
end
|
15
|
+
|
16
|
+
def move_file(origin, destination)
|
17
|
+
origin = File.expand_path(origin, destination_root)
|
18
|
+
destination = File.expand_path(destination, destination_root)
|
19
|
+
|
20
|
+
say_status(
|
21
|
+
:move,
|
22
|
+
"#{relative_to_original_destination_root(origin)} -> " +
|
23
|
+
relative_to_original_destination_root(destination)
|
24
|
+
)
|
25
|
+
|
26
|
+
FileUtils.mkdir_p(File.dirname(destination))
|
27
|
+
FileUtils.mv(origin, destination)
|
28
|
+
end
|
29
|
+
|
30
|
+
def class_name
|
31
|
+
file_name.camelize
|
32
|
+
end
|
33
|
+
|
34
|
+
def module_namespacing(&block)
|
35
|
+
super do
|
36
|
+
content = capture(&block)
|
37
|
+
concat(namespace_content(class_path, content))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def namespace_content(namespaces, content)
|
42
|
+
namespace = namespaces.shift
|
43
|
+
|
44
|
+
content = namespace_content(namespaces, content) if namespaces.any?
|
45
|
+
|
46
|
+
if namespace
|
47
|
+
"module #{namespace.camelize}\n#{indent(content).chomp}\nend\n"
|
48
|
+
else
|
49
|
+
content
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Description:
|
2
|
+
|
3
|
+
Creates a new Action class with the given name under `app/actions`.
|
4
|
+
|
5
|
+
Since Actions are not expected to be unit tested, this generator does not
|
6
|
+
invoke the test framework generator. Action behaviour is supposed to be
|
7
|
+
tested with integration or system tests.
|
8
|
+
|
9
|
+
Example:
|
10
|
+
|
11
|
+
`bin/rails g upgrow:action articles/create`
|
12
|
+
|
13
|
+
create app/actions/articles/create_action.rb
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'generators/upgrow'
|
4
|
+
|
5
|
+
module Upgrow
|
6
|
+
module Generators
|
7
|
+
class ActionGenerator < Rails::Generators::NamedBase
|
8
|
+
include Helper
|
9
|
+
|
10
|
+
def create_action_file
|
11
|
+
template(
|
12
|
+
'action.rb',
|
13
|
+
File.join('app/actions', class_path, "#{file_name}_action.rb")
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def file_name
|
20
|
+
super.delete_suffix('_action')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'generators/upgrow'
|
4
|
+
|
5
|
+
module Upgrow
|
6
|
+
module Generators
|
7
|
+
class InputGenerator < Rails::Generators::NamedBase
|
8
|
+
include Helper
|
9
|
+
|
10
|
+
def create_input_file
|
11
|
+
template(
|
12
|
+
'input.rb',
|
13
|
+
File.join('app/inputs', class_path, "#{file_name}_input.rb")
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
hook_for :test_framework
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def file_name
|
22
|
+
super.delete_suffix('_input')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Description:
|
2
|
+
|
3
|
+
Creates the additional directories and files for development using the
|
4
|
+
Upgrow architecture. This generator will create the base classes for your
|
5
|
+
Actions, Inputs, Repositories, and Models. It will also ask if you would
|
6
|
+
like to convert your existing Ruby files under `app/models` into Upgrow
|
7
|
+
Records automatically. If you say yes, it will move those files to
|
8
|
+
`app/records` and change their class names to include the `Record` suffix.
|
9
|
+
In case an `ApplicationRecord` exists, the generator will assume this to be
|
10
|
+
the base class for all Records, and it will include the `Upgrow::Record`
|
11
|
+
module in it.
|
12
|
+
|
13
|
+
Example:
|
14
|
+
|
15
|
+
`bin/rails generate upgrow:install`
|
16
|
+
|
17
|
+
Would you like to convert all models into Records? yes
|
18
|
+
move app/models/application_record.rb -> app/records/application_record.rb
|
19
|
+
move app/models/article.rb -> app/records/article_record.rb
|
20
|
+
exist app
|
21
|
+
create app/actions/application_action.rb
|
22
|
+
create app/inputs/application_input.rb
|
23
|
+
create app/models/application_model.rb
|
24
|
+
create app/repositories/application_repository.rb
|
25
|
+
invoke test_unit
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'generators/upgrow'
|
4
|
+
|
5
|
+
module Upgrow
|
6
|
+
module Generators
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
8
|
+
include Helper
|
9
|
+
|
10
|
+
def move_existing_models
|
11
|
+
pattern = File.expand_path('app/models/**/*.rb', destination_root)
|
12
|
+
files = Dir.glob(pattern)
|
13
|
+
|
14
|
+
return if files.empty?
|
15
|
+
|
16
|
+
unless yes?('Would you like to convert all models into Records?', :blue)
|
17
|
+
say(
|
18
|
+
'Please convert your existing models into Records manually. You '\
|
19
|
+
'may move them to the app/records folder, add the Record suffix '\
|
20
|
+
'to their class names, and include Upgrow::Record.',
|
21
|
+
:yellow
|
22
|
+
)
|
23
|
+
return
|
24
|
+
end
|
25
|
+
|
26
|
+
files.each do |original|
|
27
|
+
target = relative_to_original_destination_root(original)
|
28
|
+
.sub(%r{\Aapp/models/}, 'app/records/')
|
29
|
+
.sub(/^(.+(?<!_record))\.rb\z/, '\1_record.rb')
|
30
|
+
|
31
|
+
move_file(original, target)
|
32
|
+
|
33
|
+
inject_into_file(
|
34
|
+
target, 'Record',
|
35
|
+
after: /class (?!\w+Record\s)\w+/,
|
36
|
+
force: true,
|
37
|
+
verbose: false
|
38
|
+
)
|
39
|
+
|
40
|
+
inject_into_class(
|
41
|
+
target,
|
42
|
+
'ApplicationRecord',
|
43
|
+
" include Upgrow::Record\n",
|
44
|
+
verbose: false
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_app_files
|
50
|
+
directory('app')
|
51
|
+
end
|
52
|
+
|
53
|
+
hook_for :test_framework
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'generators/upgrow'
|
4
|
+
|
5
|
+
module Upgrow
|
6
|
+
module Generators
|
7
|
+
class ModelGenerator < Rails::Generators::NamedBase
|
8
|
+
include Helper
|
9
|
+
|
10
|
+
def create_model_file
|
11
|
+
template(
|
12
|
+
'model.rb',
|
13
|
+
File.join('app/models', class_path, "#{file_name}.rb")
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
hook_for :repository, default: :upgrow, as: :repository
|
18
|
+
|
19
|
+
hook_for :record, default: :upgrow, as: :record
|
20
|
+
|
21
|
+
hook_for :test_framework
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|