bullet_train-super_scaffolding 1.7.11 → 1.7.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16465881966c5cc7bfb8056943d036dea6ee5e2284a4000a2f6182c41c1eb22d
4
- data.tar.gz: aa40db2f84412ec08860dd6387f096c5e53622526ab17700bb66be85e8f0dd6b
3
+ metadata.gz: 6dd84e957ddefde70d191dc5cdfccd98934850f7ce7287ea636f79f3d40ee891
4
+ data.tar.gz: 61ff5d0bf0bf30ed71431b14fb80d05c2a4a934893962b9e34fb9441b53f915c
5
5
  SHA512:
6
- metadata.gz: 4c78f397e90c8c4175ab3b5c02fbd841ab8a6f1f6c6f2929bdf4d850f88822ac6ce50f0359b51a88ee2ffde1f2a445b3084d1d23433122fd454e65e361795e43
7
- data.tar.gz: 033dd98dd593f934b77f39214f35876da85ae9a9716c7e11d4b7ca93e2ba169d5e217e63326551f941a77a69277cf7a8598d140babd2c60d001186791a48f2e6
6
+ metadata.gz: 7f4d743ff8195358b9b4fdd3f41089baf03ec8d24a36c12cf6b3109bfc638c54bf2b0e0ac0340cca3eddee4286d1f529807abaeffd38196cd938eeff08d9b2a3
7
+ data.tar.gz: abc0ba2ad876758d0909b2b12651986d42026e410bb958cf72eed327e540c7d44ab2a5379245f9bc26addb844f5e4a60ae4eaef10a5ff52345bdbafa5713372a
@@ -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
- transformer.add_has_many_through_associations(has_many_through_transformer)
86
- inverse_transformer.add_has_many_through_associations(inverse_has_many_through_transformer)
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
 
@@ -1,5 +1,5 @@
1
1
  module BulletTrain
2
2
  module SuperScaffolding
3
- VERSION = "1.7.11"
3
+ VERSION = "1.7.12"
4
4
  end
5
5
  end
@@ -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
- has_many_through_string = has_many_through_transformer.transform_string("has_many :completely_concrete_tangible_things, through: :$HAS_MANY_ASSOCIATION")
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.11
4
+ version: 1.7.12
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-05 00:00:00.000000000 Z
11
+ date: 2024-06-13 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