bullet_train-super_scaffolding 1.3.11 → 1.3.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c18ddfb99ec853190950e2e80f6f3f00658fd565c2b3a092bc6d001bfc2da535
4
- data.tar.gz: 00274d04c09b7c9866bd73099d832e94a44bf033929da3a7e1ad5779647cae3b
3
+ metadata.gz: c5750822ea3890089ff110d3632abb49b78254db7f43980caa77eea770991828
4
+ data.tar.gz: dfb19446a59d8665205ec89fbeacf49d12c5f695ac30e878c3776da8fca86aea
5
5
  SHA512:
6
- metadata.gz: a823e9d63e599106ec58ff0290cc79e37e1c55e65149724105c81497e0d30190823be8280a11cc787b61cf574ba2664697d1fd93f14d19f77f302b82564fda59
7
- data.tar.gz: abdd3895111e87a081a2d3d9dd8cc887386c8a6c7f4784a9c7b8319036025806b99694a448cbd72787728ed139b78ad26f8e80bf81aca110cfb88a7be22d2d23
6
+ metadata.gz: d0fd7cd95ad4b491f8d23daa2c6fd9b901f70b2745aebd56a64c6555e31ce33667117a98cacad94239e860077495b148fa090ff71e40280f3cb322423b14ecb4
7
+ data.tar.gz: 2dc5dbf921246e3e5f972f64cf271178f2c5d2a0854d39b59dbd7b66dcbbc77f5e84b27d01fb3767ff2ce42a97951824ad06542c4f48d46ff3985c0c455c04d9
@@ -1,5 +1,5 @@
1
1
  module BulletTrain
2
2
  module SuperScaffolding
3
- VERSION = "1.3.11"
3
+ VERSION = "1.3.13"
4
4
  end
5
5
  end
@@ -722,7 +722,7 @@ class Scaffolding::Transformer
722
722
  when "number_field"
723
723
  "number"
724
724
  when "file_field"
725
- "file"
725
+ "file#{"s" if is_multiple}"
726
726
  when "password_field"
727
727
  "text"
728
728
  else
@@ -1065,6 +1065,9 @@ class Scaffolding::Transformer
1065
1065
  ].each do |file|
1066
1066
  if is_ids || is_multiple
1067
1067
  scaffold_add_line_to_file(file, "#{name}: [],", RUBY_NEW_ARRAYS_HOOK, prepend: true)
1068
+ if type == "file_field"
1069
+ scaffold_add_line_to_file(file, "#{name}_removal: [],", RUBY_NEW_ARRAYS_HOOK, prepend: true)
1070
+ end
1068
1071
  else
1069
1072
  scaffold_add_line_to_file(file, ":#{name},", RUBY_NEW_FIELDS_HOOK, prepend: true)
1070
1073
  if type == "file_field"
@@ -1113,7 +1116,11 @@ class Scaffolding::Transformer
1113
1116
  when "date_and_time_field"
1114
1117
  "assert_equal_or_nil DateTime.parse(tangible_thing_data['#{name}']), tangible_thing.#{name}"
1115
1118
  when "file_field"
1116
- "assert_equal tangible_thing_data['#{name}'], rails_blob_path(@tangible_thing.#{name}) unless controller.action_name == 'create'"
1119
+ if is_multiple
1120
+ "assert_equal tangible_thing_data['#{name}'], @tangible_thing.#{name}.map{|file| rails_blob_path(file)} unless controller.action_name == 'create'"
1121
+ else
1122
+ "assert_equal tangible_thing_data['#{name}'], rails_blob_path(@tangible_thing.#{name}) unless controller.action_name == 'create'"
1123
+ end
1117
1124
  else
1118
1125
  "assert_equal_or_nil tangible_thing_data['#{name}'], tangible_thing.#{name}"
1119
1126
  end
@@ -1122,13 +1129,30 @@ class Scaffolding::Transformer
1122
1129
 
1123
1130
  # File fields are handled in a specific way when using the jsonapi-serializer.
1124
1131
  if type == "file_field"
1125
- scaffold_add_line_to_file("./app/views/api/v1/scaffolding/completely_concrete/tangible_things/_tangible_thing.json.jbuilder", "json.#{name} url_for(tangible_thing.#{name}) if tangible_thing.#{name}.attached?", RUBY_FILES_HOOK, prepend: true, suppress_could_not_find: true)
1132
+ jbuilder_content = if is_multiple
1133
+ <<~RUBY
1134
+ json.#{name} do
1135
+ json.array! tangible_thing.#{name}.map { |file| url_for(file) }
1136
+ end if tangible_thing.#{name}.attached?
1137
+ RUBY
1138
+ else
1139
+ "json.#{name} url_for(tangible_thing.#{name}) if tangible_thing.#{name}.attached?"
1140
+ end
1141
+
1142
+ scaffold_add_line_to_file("./app/views/api/v1/scaffolding/completely_concrete/tangible_things/_tangible_thing.json.jbuilder", jbuilder_content, RUBY_FILES_HOOK, prepend: true, suppress_could_not_find: true)
1126
1143
  # We also want to make sure we attach the dummy file in the API test on setup
1127
1144
  file_name = "./test/controllers/api/v1/scaffolding/completely_concrete/tangible_things_controller_test.rb"
1128
- content = <<~RUBY
1129
- @#{child.underscore}.#{name} = Rack::Test::UploadedFile.new("test/support/foo.txt")
1130
- @another_#{child.underscore}.#{name} = Rack::Test::UploadedFile.new("test/support/foo.txt")
1131
- RUBY
1145
+ content = if is_multiple
1146
+ <<~RUBY
1147
+ @#{child.underscore}.#{name} = [Rack::Test::UploadedFile.new("test/support/foo.txt")]
1148
+ @another_#{child.underscore}.#{name} = [Rack::Test::UploadedFile.new("test/support/foo.txt")]
1149
+ RUBY
1150
+ else
1151
+ <<~RUBY
1152
+ @#{child.underscore}.#{name} = Rack::Test::UploadedFile.new("test/support/foo.txt")
1153
+ @another_#{child.underscore}.#{name} = Rack::Test::UploadedFile.new("test/support/foo.txt")
1154
+ RUBY
1155
+ end
1132
1156
  scaffold_add_line_to_file(file_name, content, RUBY_FILES_HOOK, prepend: true)
1133
1157
  end
1134
1158
 
@@ -1297,7 +1321,27 @@ class Scaffolding::Transformer
1297
1321
 
1298
1322
  case type
1299
1323
  when "file_field"
1300
- remove_file_methods =
1324
+ remove_file_methods = if is_multiple
1325
+ <<~RUBY
1326
+ def #{name}_removal?
1327
+ #{name}_removal&.any?
1328
+ end
1329
+
1330
+ def remove_#{name}
1331
+ #{name}_attachments.where(id: #{name}_removal).map(&:purge)
1332
+ end
1333
+
1334
+ def #{name}=(attachables)
1335
+ attachables = Array(attachables).compact_blank
1336
+
1337
+ if attachables.any?
1338
+ attachment_changes["#{name}"] =
1339
+ ActiveStorage::Attached::Changes::CreateMany.new("#{name}", self, #{name}.blobs + attachables)
1340
+ end
1341
+ end
1342
+
1343
+ RUBY
1344
+ else
1301
1345
  <<~RUBY
1302
1346
  def #{name}_removal?
1303
1347
  #{name}_removal.present?
@@ -1307,6 +1351,7 @@ class Scaffolding::Transformer
1307
1351
  #{name}.purge
1308
1352
  end
1309
1353
  RUBY
1354
+ end
1310
1355
 
1311
1356
  # Generating a model with an `attachment(s)` data type (i.e. - `rails g ModelName file:attachment`)
1312
1357
  # adds `has_one_attached` or `has_many_attached` to our model, just not directly above the
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.3.11
4
+ version: 1.3.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: 2023-08-22 00:00:00.000000000 Z
11
+ date: 2023-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: standard