bullet_train-super_scaffolding 1.3.12 → 1.3.13
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 +4 -4
 - data/lib/bullet_train/super_scaffolding/version.rb +1 -1
 - data/lib/scaffolding/transformer.rb +53 -8
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: c5750822ea3890089ff110d3632abb49b78254db7f43980caa77eea770991828
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: dfb19446a59d8665205ec89fbeacf49d12c5f695ac30e878c3776da8fca86aea
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: d0fd7cd95ad4b491f8d23daa2c6fd9b901f70b2745aebd56a64c6555e31ce33667117a98cacad94239e860077495b148fa090ff71e40280f3cb322423b14ecb4
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 2dc5dbf921246e3e5f972f64cf271178f2c5d2a0854d39b59dbd7b66dcbbc77f5e84b27d01fb3767ff2ce42a97951824ad06542c4f48d46ff3985c0c455c04d9
         
     | 
| 
         @@ -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 
     | 
    
         
            -
                         
     | 
| 
      
 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 
     | 
    
         
            -
                       
     | 
| 
      
 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 =  
     | 
| 
       1129 
     | 
    
         
            -
                         
     | 
| 
       1130 
     | 
    
         
            -
             
     | 
| 
       1131 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     |