bullet_train-super_scaffolding 1.7.11 → 1.7.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bullet_train/super_scaffolding/scaffolders/join_model_scaffolder.rb +5 -2
- data/lib/bullet_train/super_scaffolding/version.rb +1 -1
- data/lib/bullet_train/super_scaffolding.rb +3 -1
- data/lib/generators/super_scaffold/action_models/performs_export/USAGE +27 -0
- data/lib/generators/super_scaffold/action_models/performs_export/performs_export_generator.rb +36 -0
- data/lib/generators/super_scaffold/action_models/performs_import/USAGE +26 -0
- data/lib/generators/super_scaffold/action_models/performs_import/performs_import_generator.rb +36 -0
- data/lib/scaffolding/attribute.rb +14 -0
- data/lib/scaffolding/transformer.rb +22 -12
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4c13cc4e497a156b72d2d5e973881284fe77d9e17120da2be13e4dbce4e3008
|
4
|
+
data.tar.gz: 9c9de1fa4ecc66e23ac6503c4d8f3bcdb63d870318bba3e94cf0c43e57ac0fa2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c858173ffe0a653f74496519c5baaf778a1a9b198cef3d504581ae09966495f99fbfab34f66159a5b13ffa22c06a302a33278ba87eec9148383958630a5cd685
|
7
|
+
data.tar.gz: f529b7e68025af0a511b6684c31b620982234fa0d547e7e8626102bd8038e31ba5521203915143b2ea86c98f39ff3246771c8a9191c920e2b2578d39dcbd43ba
|
@@ -82,8 +82,11 @@ module BulletTrain
|
|
82
82
|
transformer.suppress_could_not_find = false
|
83
83
|
|
84
84
|
# Add the `has_many ... through:` association in both directions.
|
85
|
-
|
86
|
-
|
85
|
+
# We pass the "opposing" attribute so that both the association name and the
|
86
|
+
# class name get wired up correctly in cases where they don't match. For instance
|
87
|
+
# if you want an `assigned_to_membership` relationship to the `memberships` table.
|
88
|
+
transformer.add_has_many_through_associations(has_many_through_transformer, attributes[1])
|
89
|
+
inverse_transformer.add_has_many_through_associations(inverse_has_many_through_transformer, attributes[0])
|
87
90
|
|
88
91
|
additional_steps = (transformer.additional_steps + has_many_through_transformer.additional_steps + inverse_transformer.additional_steps + inverse_has_many_through_transformer.additional_steps).uniq
|
89
92
|
|
@@ -20,7 +20,9 @@ module BulletTrain
|
|
20
20
|
"oauth-provider" => "BulletTrain::SuperScaffolding::Scaffolders::OauthProviderScaffolder",
|
21
21
|
"action-models:targets-many" => "BulletTrain::ActionModels::Scaffolders::TargetsManyScaffolder",
|
22
22
|
"action-models:targets-one" => "BulletTrain::ActionModels::Scaffolders::TargetsOneScaffolder",
|
23
|
-
"action-models:targets-one-parent" => "BulletTrain::ActionModels::Scaffolders::TargetsOneParentScaffolder"
|
23
|
+
"action-models:targets-one-parent" => "BulletTrain::ActionModels::Scaffolders::TargetsOneParentScaffolder",
|
24
|
+
"action-models:performs-export" => "BulletTrain::ActionModels::Scaffolders::PerformsExportScaffolder",
|
25
|
+
"action-models:performs-import" => "BulletTrain::ActionModels::Scaffolders::PerformsImportScaffolder"
|
24
26
|
}
|
25
27
|
|
26
28
|
class Runner
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Description:
|
2
|
+
Generate an action to export a list of model records.
|
3
|
+
|
4
|
+
Example:
|
5
|
+
E.g. Generate an Export action that exports many Posts from a Team.
|
6
|
+
rails generate super_scaffold:action_models:performs_export Export Post Team
|
7
|
+
|
8
|
+
This will create:
|
9
|
+
app/avo/resources/posts_export_action.rb
|
10
|
+
app/controllers/account/posts/
|
11
|
+
app/controllers/avo/posts_export_actions_controller.rb
|
12
|
+
app/models/posts.rb
|
13
|
+
app/models/posts/
|
14
|
+
app/views/account/posts/export_actions/
|
15
|
+
config/locales/en/posts/
|
16
|
+
db/migrate/20240612185709_create_posts_export_actions.rb
|
17
|
+
test/factories/posts/
|
18
|
+
test/models/posts/
|
19
|
+
And update:
|
20
|
+
app/models/team.rb
|
21
|
+
app/views/account/posts/_index.html.erb
|
22
|
+
config/models/roles.yml
|
23
|
+
config/routes.rb
|
24
|
+
config/routes/api/v1.rb
|
25
|
+
|
26
|
+
🏆 Protip: Commit your other changes before running Super Scaffolding so it's easy to undo if you (or we) make any mistakes.
|
27
|
+
If you do that, you can reset to your last commit state by using `git checkout .` and `git clean -d -f`.
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative "../../super_scaffold_base"
|
2
|
+
require "scaffolding/routes_file_manipulator"
|
3
|
+
|
4
|
+
module ActionModels
|
5
|
+
class PerformsExportGenerator < Rails::Generators::Base
|
6
|
+
include SuperScaffoldBase
|
7
|
+
|
8
|
+
source_root File.expand_path("templates", __dir__)
|
9
|
+
|
10
|
+
namespace "super_scaffold:action_models:performs_export"
|
11
|
+
|
12
|
+
argument :action_model
|
13
|
+
argument :target_model
|
14
|
+
argument :parent_model
|
15
|
+
|
16
|
+
class_option :skip_migration_generation, type: :boolean, default: false, desc: "Don't generate the model migration"
|
17
|
+
class_option :skip_form, type: :boolean, default: false, desc: "Don't alter the new/edit form"
|
18
|
+
class_option :skip_show, type: :boolean, default: false, desc: "Don't alter the show view"
|
19
|
+
class_option :skip_table, type: :boolean, default: false, desc: "Only add to the new/edit form and show view."
|
20
|
+
class_option :skip_locales, type: :boolean, default: false, desc: "Don't alter locale files"
|
21
|
+
class_option :skip_api, type: :boolean, default: false, desc: "Don't alter the api payloads"
|
22
|
+
class_option :skip_model, type: :boolean, default: false, desc: "Don't alter the model file"
|
23
|
+
|
24
|
+
def generate
|
25
|
+
if defined?(BulletTrain::ActionModels)
|
26
|
+
# We add the name of the specific super_scaffolding command that we want to
|
27
|
+
# invoke to the beginning of the argument string.
|
28
|
+
ARGV.unshift "action-models:performs-export"
|
29
|
+
BulletTrain::SuperScaffolding::Runner.new.run
|
30
|
+
else
|
31
|
+
puts "You must have Action Models installed if you want to use this generator.".red
|
32
|
+
puts "Please refer to the documentation for more information: https://bullettrain.co/docs/action-models"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Description:
|
2
|
+
Generate an action that imports a list of records to its parent.
|
3
|
+
|
4
|
+
Example:
|
5
|
+
E.g. Generate a CSV Importer that creates many Posts on a Team.
|
6
|
+
rails generate super_scaffold:action_models:performs_import CsvImport Post Team
|
7
|
+
|
8
|
+
This will create:
|
9
|
+
app/avo/resources/posts_import_action.rb
|
10
|
+
app/controllers/account/posts/import_actions_controller.rb
|
11
|
+
app/controllers/avo/posts_import_actions_controller.rb
|
12
|
+
app/models/posts/import_action.rb
|
13
|
+
app/views/account/posts/import_actions/
|
14
|
+
config/locales/en/posts/import_actions.en.yml
|
15
|
+
db/migrate/20240612185843_create_posts_import_actions.rb
|
16
|
+
test/factories/posts/import_actions.rb
|
17
|
+
test/models/posts/import_action_test.rb
|
18
|
+
And update:
|
19
|
+
app/models/team.rb
|
20
|
+
app/views/account/posts/_index.html.erb
|
21
|
+
config/models/roles.yml
|
22
|
+
config/routes.rb
|
23
|
+
config/routes/api/v1.rb
|
24
|
+
|
25
|
+
🏆 Protip: Commit your other changes before running Super Scaffolding so it's easy to undo if you (or we) make any mistakes.
|
26
|
+
If you do that, you can reset to your last commit state by using `git checkout .` and `git clean -d -f`.
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative "../../super_scaffold_base"
|
2
|
+
require "scaffolding/routes_file_manipulator"
|
3
|
+
|
4
|
+
module ActionModels
|
5
|
+
class PerformsImportGenerator < Rails::Generators::Base
|
6
|
+
include SuperScaffoldBase
|
7
|
+
|
8
|
+
source_root File.expand_path("templates", __dir__)
|
9
|
+
|
10
|
+
namespace "super_scaffold:action_models:performs_import"
|
11
|
+
|
12
|
+
argument :action_model
|
13
|
+
argument :model_to_process
|
14
|
+
argument :target_parent_model
|
15
|
+
|
16
|
+
class_option :skip_migration_generation, type: :boolean, default: false, desc: "Don't generate the model migration"
|
17
|
+
class_option :skip_form, type: :boolean, default: false, desc: "Don't alter the new/edit form"
|
18
|
+
class_option :skip_show, type: :boolean, default: false, desc: "Don't alter the show view"
|
19
|
+
class_option :skip_table, type: :boolean, default: false, desc: "Only add to the new/edit form and show view."
|
20
|
+
class_option :skip_locales, type: :boolean, default: false, desc: "Don't alter locale files"
|
21
|
+
class_option :skip_api, type: :boolean, default: false, desc: "Don't alter the api payloads"
|
22
|
+
class_option :skip_model, type: :boolean, default: false, desc: "Don't alter the model file"
|
23
|
+
|
24
|
+
def generate
|
25
|
+
if defined?(BulletTrain::ActionModels)
|
26
|
+
# We add the name of the specific super_scaffolding command that we want to
|
27
|
+
# invoke to the beginning of the argument string.
|
28
|
+
ARGV.unshift "action-models:performs-import"
|
29
|
+
BulletTrain::SuperScaffolding::Runner.new.run
|
30
|
+
else
|
31
|
+
puts "You must have Action Models installed if you want to use this generator.".red
|
32
|
+
puts "Please refer to the documentation for more information: https://bullettrain.co/docs/action-models"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -58,6 +58,20 @@ class Scaffolding::Attribute
|
|
58
58
|
name.split("_id").first
|
59
59
|
end
|
60
60
|
|
61
|
+
def plural_association_name
|
62
|
+
association_class_name.tableize
|
63
|
+
end
|
64
|
+
|
65
|
+
def class_name_matches?
|
66
|
+
# if namespaces are involved, just don't...
|
67
|
+
# TODO: I'm not entirely sure that extracting this conditional was the right thing to do.
|
68
|
+
# Are there scenarios where we want to assume a match even when namespaces are involved?
|
69
|
+
if options[:class_name].include?("::")
|
70
|
+
return false
|
71
|
+
end
|
72
|
+
name_without_id.tableize == options[:class_name].tableize.tr("/", "_")
|
73
|
+
end
|
74
|
+
|
61
75
|
def is_association?
|
62
76
|
is_belongs_to? || is_has_many?
|
63
77
|
end
|
@@ -603,10 +603,27 @@ class Scaffolding::Transformer
|
|
603
603
|
has_many_string.split(",").first.split(":").last
|
604
604
|
end
|
605
605
|
|
606
|
-
def add_has_many_through_associations(has_many_through_transformer)
|
606
|
+
def add_has_many_through_associations(has_many_through_transformer, attribute_definition)
|
607
|
+
attribute = Scaffolding::Attribute.new(attribute_definition, :crud_field, 0)
|
607
608
|
has_many_association = add_has_many_association
|
608
|
-
|
609
|
+
has_many_through_parts = [
|
610
|
+
"has_many :completely_concrete_tangible_things",
|
611
|
+
"through: :$HAS_MANY_ASSOCIATION"
|
612
|
+
]
|
613
|
+
|
614
|
+
unless attribute.class_name_matches?
|
615
|
+
has_many_through_parts << "class_name: \"Scaffolding::CompletelyConcrete::TangibleThing\""
|
616
|
+
end
|
617
|
+
has_many_through_string = has_many_through_transformer.transform_string(has_many_through_parts.join(", "))
|
609
618
|
has_many_through_string.gsub!("$HAS_MANY_ASSOCIATION", has_many_association)
|
619
|
+
unless attribute.class_name_matches?
|
620
|
+
# This handles the case where you're generating a join model where you want association names
|
621
|
+
# to be different than the class name, so it'll transform something like this:
|
622
|
+
# has_many :memberships, through: :assignments, class_name: "Membership"
|
623
|
+
# into something like this:
|
624
|
+
# has_many :assigned_to_memberships, through: :assignments, class_name: "Membership"
|
625
|
+
has_many_through_string.gsub!("has_many :#{attribute.plural_association_name}", "has_many :#{attribute.name_without_id.tableize}")
|
626
|
+
end
|
610
627
|
add_line_to_file(transform_string("./app/models/scaffolding/absolutely_abstract/creative_concept.rb"), has_many_through_string, HAS_MANY_HOOK, prepend: true)
|
611
628
|
end
|
612
629
|
|
@@ -1142,15 +1159,8 @@ class Scaffolding::Transformer
|
|
1142
1159
|
|
1143
1160
|
end
|
1144
1161
|
|
1145
|
-
class_name_matches = attribute.name_without_id.tableize == attribute.options[:class_name].tableize.tr("/", "_")
|
1146
|
-
|
1147
|
-
# but also, if namespaces are involved, just don't...
|
1148
|
-
if attribute.options[:class_name].include?("::")
|
1149
|
-
class_name_matches = false
|
1150
|
-
end
|
1151
|
-
|
1152
1162
|
# unless the table name matches the association name.
|
1153
|
-
unless class_name_matches
|
1163
|
+
unless attribute.class_name_matches?
|
1154
1164
|
if migration_file_name
|
1155
1165
|
# There are two forms this association creation can take.
|
1156
1166
|
replace_in_file(migration_file_name, "foreign_key: true", "foreign_key: {to_table: \"#{attribute.options[:class_name].tableize.tr("/", "_")}\"}", /t\.references :#{attribute.name_without_id}/)
|
@@ -1167,7 +1177,7 @@ class Scaffolding::Transformer
|
|
1167
1177
|
# if the `belongs_to` is already there from `rails g model`..
|
1168
1178
|
scaffold_replace_line_in_file(
|
1169
1179
|
"./app/models/scaffolding/completely_concrete/tangible_thing.rb",
|
1170
|
-
class_name_matches ?
|
1180
|
+
attribute.class_name_matches? ?
|
1171
1181
|
"belongs_to :#{attribute.name_without_id}#{optional_line}" :
|
1172
1182
|
"belongs_to :#{attribute.name_without_id}, class_name: \"#{attribute.options[:class_name]}\"#{optional_line}",
|
1173
1183
|
"belongs_to :#{attribute.name_without_id}"
|
@@ -1177,7 +1187,7 @@ class Scaffolding::Transformer
|
|
1177
1187
|
# however, this won't do anything if the association is already there.
|
1178
1188
|
scaffold_add_line_to_file(
|
1179
1189
|
"./app/models/scaffolding/completely_concrete/tangible_thing.rb",
|
1180
|
-
class_name_matches ?
|
1190
|
+
attribute.class_name_matches? ?
|
1181
1191
|
"belongs_to :#{attribute.name_without_id}#{optional_line}" :
|
1182
1192
|
"belongs_to :#{attribute.name_without_id}, class_name: \"#{attribute.options[:class_name]}\"#{optional_line}",
|
1183
1193
|
BELONGS_TO_HOOK,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullet_train-super_scaffolding
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Culver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: standard
|
@@ -164,6 +164,10 @@ files:
|
|
164
164
|
- lib/bullet_train/super_scaffolding/version.rb
|
165
165
|
- lib/bullet_train/terminal_commands.rb
|
166
166
|
- lib/generators/super_scaffold/USAGE
|
167
|
+
- lib/generators/super_scaffold/action_models/performs_export/USAGE
|
168
|
+
- lib/generators/super_scaffold/action_models/performs_export/performs_export_generator.rb
|
169
|
+
- lib/generators/super_scaffold/action_models/performs_import/USAGE
|
170
|
+
- lib/generators/super_scaffold/action_models/performs_import/performs_import_generator.rb
|
167
171
|
- lib/generators/super_scaffold/action_models/targets_many/USAGE
|
168
172
|
- lib/generators/super_scaffold/action_models/targets_many/targets_many_generator.rb
|
169
173
|
- lib/generators/super_scaffold/action_models/targets_one/USAGE
|