bullet_train-super_scaffolding 1.7.10 → 1.7.11
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/crud_scaffolder.rb +2 -0
- data/lib/bullet_train/super_scaffolding/scaffolders/join_model_scaffolder.rb +2 -0
- data/lib/bullet_train/super_scaffolding/version.rb +1 -1
- data/lib/scaffolding/attribute.rb +7 -0
- data/lib/scaffolding/script.rb +34 -1
- data/lib/scaffolding/transformer.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16465881966c5cc7bfb8056943d036dea6ee5e2284a4000a2f6182c41c1eb22d
|
4
|
+
data.tar.gz: aa40db2f84412ec08860dd6387f096c5e53622526ab17700bb66be85e8f0dd6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c78f397e90c8c4175ab3b5c02fbd841ab8a6f1f6c6f2929bdf4d850f88822ac6ce50f0359b51a88ee2ffde1f2a445b3084d1d23433122fd454e65e361795e43
|
7
|
+
data.tar.gz: 033dd98dd593f934b77f39214f35876da85ae9a9716c7e11d4b7ca93e2ba169d5e217e63326551f941a77a69277cf7a8598d140babd2c60d001186791a48f2e6
|
@@ -30,6 +30,8 @@ module BulletTrain
|
|
30
30
|
end
|
31
31
|
|
32
32
|
child = argv[0]
|
33
|
+
check_class_name_for_namespace_conflict(child)
|
34
|
+
|
33
35
|
primary_parent = argv[1].split("class_name=").last.split(",").first.split("}").first
|
34
36
|
secondary_parent = argv[2].split("class_name=").last.split(",").first.split("}").first
|
35
37
|
|
@@ -51,6 +51,13 @@ class Scaffolding::Attribute
|
|
51
51
|
options[:required] || is_first_attribute?
|
52
52
|
end
|
53
53
|
|
54
|
+
def association_class_name
|
55
|
+
if options[:class_name].present?
|
56
|
+
return options[:class_name].underscore.split("/").last
|
57
|
+
end
|
58
|
+
name.split("_id").first
|
59
|
+
end
|
60
|
+
|
54
61
|
def is_association?
|
55
62
|
is_belongs_to? || is_has_many?
|
56
63
|
end
|
data/lib/scaffolding/script.rb
CHANGED
@@ -49,6 +49,39 @@ def get_untracked_files
|
|
49
49
|
`git ls-files --other --exclude-standard`.split("\n")
|
50
50
|
end
|
51
51
|
|
52
|
+
# class_name is a potentially namespaced class like
|
53
|
+
# "Tasks::Widget" or "Task::Widget". Here we ensure that
|
54
|
+
# the namespace doesn't clobber an existing model. If it does
|
55
|
+
# we suggest that the namespace could be pluralized.
|
56
|
+
def check_class_name_for_namespace_conflict(class_name)
|
57
|
+
if class_name.include?("::")
|
58
|
+
parts = class_name.split("::") # ["Task", "Widget"]
|
59
|
+
# We drop the last segment because that's tne new model we're trying to create
|
60
|
+
parts.pop # ["Task"]
|
61
|
+
possible_conflicted_class_name = ""
|
62
|
+
parts.each do |part|
|
63
|
+
possible_conflicted_class_name += "::#{part}"
|
64
|
+
begin
|
65
|
+
klass = possible_conflicted_class_name.constantize
|
66
|
+
is_active_record_class = klass&.ancestors&.include?(ActiveRecord::Base)
|
67
|
+
is_aactive_hash_class = klass&.ancestors&.include?(ActiveHash::Base)
|
68
|
+
if klass && (is_active_record_class || is_aactive_hash_class)
|
69
|
+
problematic_namespace = possible_conflicted_class_name[2..]
|
70
|
+
puts "It looks like the namespace you gave for this model conflicts with an existing class: #{klass.name}".red
|
71
|
+
puts "You should use a namespace that doesn't clobber an existing class.".red
|
72
|
+
puts ""
|
73
|
+
puts "We reccomend using the pluralized version of the existing class.".red
|
74
|
+
puts ""
|
75
|
+
puts "For instance instead of #{problematic_namespace} use #{problematic_namespace.pluralize}".red
|
76
|
+
exit
|
77
|
+
end
|
78
|
+
rescue NameError
|
79
|
+
# this is good actually, it means we don't already have a class that will be clobbered
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
52
85
|
def check_required_options_for_attributes(scaffolding_type, attributes, child, parent = nil)
|
53
86
|
tableized_parent = nil
|
54
87
|
|
@@ -169,7 +202,7 @@ def check_required_options_for_attributes(scaffolding_type, attributes, child, p
|
|
169
202
|
is_active_record_class = class_name_constant&.ancestors&.include?(ActiveRecord::Base)
|
170
203
|
unless File.exist?(file_name) && is_active_record_class
|
171
204
|
puts ""
|
172
|
-
puts "Attributes that end with `_id` or `_ids` trigger awesome, powerful magic in Super Scaffolding. However, because no `#{attribute_options[:class_name]}` class was found defined in
|
205
|
+
puts "Attributes that end with `_id` or `_ids` trigger awesome, powerful magic in Super Scaffolding. However, because no `#{attribute_options[:class_name]}` class was found defined in your app, you'll need to specify a `class_name` that exists to let us know what model class is on the other side of the association, like so:".red
|
173
206
|
puts ""
|
174
207
|
puts " bin/super-scaffold #{scaffolding_type} #{child}#{" " + parent if parent.present?} #{name}:#{type}{class_name=#{name.gsub(/_ids?$/, "").classify}}".red
|
175
208
|
puts ""
|
@@ -758,7 +758,7 @@ class Scaffolding::Transformer
|
|
758
758
|
end
|
759
759
|
|
760
760
|
if attribute.is_association?
|
761
|
-
short = attribute.
|
761
|
+
short = attribute.association_class_name
|
762
762
|
case attribute.type
|
763
763
|
when "buttons", "options"
|
764
764
|
field_attributes["\n options"] = "@tangible_thing.#{valid_values}.map { |#{short}| [#{short}.id, #{short}.#{attribute.options[:label]}] }"
|
@@ -1362,12 +1362,12 @@ class Scaffolding::Transformer
|
|
1362
1362
|
|
1363
1363
|
# update the factory generated by `rails g`.
|
1364
1364
|
content = if transform_string(":absolutely_abstract_creative_concept") == transform_string(":scaffolding_absolutely_abstract_creative_concept")
|
1365
|
-
transform_string("association :absolutely_abstract_creative_concept")
|
1365
|
+
transform_string(" association :absolutely_abstract_creative_concept")
|
1366
1366
|
else
|
1367
|
-
transform_string("association :absolutely_abstract_creative_concept, factory: :scaffolding_absolutely_abstract_creative_concept")
|
1367
|
+
transform_string(" association :absolutely_abstract_creative_concept, factory: :scaffolding_absolutely_abstract_creative_concept")
|
1368
1368
|
end
|
1369
1369
|
|
1370
|
-
scaffold_replace_line_in_file("./test/factories/scaffolding/completely_concrete/tangible_things.rb", content, "absolutely_abstract_creative_concept { nil }")
|
1370
|
+
scaffold_replace_line_in_file("./test/factories/scaffolding/completely_concrete/tangible_things.rb", content, " absolutely_abstract_creative_concept { nil }")
|
1371
1371
|
|
1372
1372
|
add_has_many_association
|
1373
1373
|
|
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.11
|
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-05
|
11
|
+
date: 2024-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: standard
|