bullet_train-super_scaffolding 1.0.42 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (21) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/account/scaffolding/absolutely_abstract/creative_concepts/collaborators_controller.rb +1 -1
  3. data/app/controllers/account/scaffolding/absolutely_abstract/creative_concepts_controller.rb +1 -1
  4. data/app/controllers/account/scaffolding/completely_concrete/tangible_things_controller.rb +4 -34
  5. data/app/controllers/api/v1/scaffolding/completely_concrete/tangible_things_controller.rb +78 -0
  6. data/app/views/{account → api/v1}/scaffolding/completely_concrete/tangible_things/_tangible_thing.json.jbuilder +1 -1
  7. data/app/views/api/v1/scaffolding/completely_concrete/tangible_things/index.json.jbuilder +5 -0
  8. data/app/views/api/v1/scaffolding/completely_concrete/tangible_things/show.json.jbuilder +1 -0
  9. data/config/routes.rb +32 -1
  10. data/lib/bullet_train/super_scaffolding/engine.rb +0 -7
  11. data/lib/bullet_train/super_scaffolding/version.rb +1 -1
  12. data/lib/scaffolding/file_manipulator.rb +6 -1
  13. data/lib/scaffolding/oauth_providers.rb +5 -0
  14. data/lib/scaffolding/transformer.rb +56 -83
  15. metadata +6 -9
  16. data/app/controllers/api/v1/scaffolding/absolutely_abstract/creative_concepts_endpoint.rb +0 -103
  17. data/app/controllers/api/v1/scaffolding/completely_concrete/tangible_things_endpoint.rb +0 -136
  18. data/app/serializers/api/v1/scaffolding/absolutely_abstract/creative_concept_serializer.rb +0 -14
  19. data/app/serializers/api/v1/scaffolding/completely_concrete/tangible_thing_serializer.rb +0 -37
  20. data/app/views/account/scaffolding/completely_concrete/tangible_things/index.json.jbuilder +0 -1
  21. data/app/views/account/scaffolding/completely_concrete/tangible_things/show.json.jbuilder +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20c44af78ae7911fc2ef90a78db8d76d7f52f8535b6931a3c1719a84ee8b1104
4
- data.tar.gz: 12cabbb8f6530d809d17d9fe9ff3c742e5ac705e296b982df33c55763afb7518
3
+ metadata.gz: 50a466be7f9a4dfe155fc7cf7dfab2b1bda99677dd90f4f263ad3a4e8cf62689
4
+ data.tar.gz: 195aebbb30ba1ad1ae2251edaa4f8a0867fea4d0b00eacbcaaf8e17fa9005a53
5
5
  SHA512:
6
- metadata.gz: 89ffc20c1fae91cde0bd62b490d1d86aba8ed8ec3dd2f30445c260bab4e326bc9c026a0331d199e6a7942610a5ef5d926ffca38ce0e39bc68129155ec003c8e7
7
- data.tar.gz: 1f0ff6f2b787dc6c5aa8d60fbfdacaf70a1f892494ae9e103fd8879ea25113374364cbbd69c172e26e9102e947dd10963f1eb1fef5ec7e8007a0f83e9991dbf8
6
+ metadata.gz: 1375e436763d2afa346376453aa9b751225d8dd3861d426764f63b7248a1957e87be059e8bf3f98e1139c187226dee02d85c1e1ccd9c0a4977cfc9875e5d2306
7
+ data.tar.gz: c15501096af6bf2d5090c441c4eaaf886ee5c11436f3ee822cabdf6bebab9f88d3e3ba1734258e4455d0823714fb7ce00e280db5a7f2454c7bb32b88f6223c3f
@@ -61,7 +61,7 @@ class Account::Scaffolding::AbsolutelyAbstract::CreativeConcepts::CollaboratorsC
61
61
 
62
62
  private
63
63
 
64
- # Never trust parameters from the scary internet, only allow the white list through.
64
+ # Only allow a list of trusted parameters through.
65
65
  def collaborator_params
66
66
  role_ids = params.dig(:scaffolding_absolutely_abstract_creative_concepts_collaborator, :role_ids)
67
67
  role_ids = [role_ids] unless role_ids.is_a?(Array)
@@ -68,7 +68,7 @@ class Account::Scaffolding::AbsolutelyAbstract::CreativeConceptsController < Acc
68
68
 
69
69
  private
70
70
 
71
- # Never trust parameters from the scary internet, only allow the white list through.
71
+ # Only allow a list of trusted parameters through.
72
72
  def creative_concept_params
73
73
  params.require(:scaffolding_absolutely_abstract_creative_concept).permit(
74
74
  :name,
@@ -4,13 +4,13 @@ class Account::Scaffolding::CompletelyConcrete::TangibleThingsController < Accou
4
4
  # GET /account/scaffolding/absolutely_abstract/creative_concepts/:absolutely_abstract_creative_concept_id/completely_concrete/tangible_things
5
5
  # GET /account/scaffolding/absolutely_abstract/creative_concepts/:absolutely_abstract_creative_concept_id/completely_concrete/tangible_things.json
6
6
  def index
7
- # if you only want these objects shown on their parent's show page, uncomment this:
8
- # redirect_to [:account, @absolutely_abstract_creative_concept]
7
+ delegate_json_to_api
9
8
  end
10
9
 
11
10
  # GET /account/scaffolding/completely_concrete/tangible_things/:id
12
11
  # GET /account/scaffolding/completely_concrete/tangible_things/:id.json
13
12
  def show
13
+ delegate_json_to_api
14
14
  end
15
15
 
16
16
  # GET /account/scaffolding/absolutely_abstract/creative_concepts/:absolutely_abstract_creative_concept_id/completely_concrete/tangible_things/new
@@ -61,37 +61,9 @@ class Account::Scaffolding::CompletelyConcrete::TangibleThingsController < Accou
61
61
 
62
62
  private
63
63
 
64
- # Never trust parameters from the scary internet, only allow the white list through.
65
- def tangible_thing_params
66
- strong_params = params.require(:scaffolding_completely_concrete_tangible_thing).permit(
67
- # 🚅 skip this section when scaffolding.
68
- :text_field_value,
69
- :action_text_value,
70
- :boolean_button_value,
71
- :button_value,
72
- :color_picker_value,
73
- :cloudinary_image_value,
74
- :date_field_value,
75
- :date_and_time_field_value,
76
- :date_and_time_field_value_time_zone,
77
- :email_field_value,
78
- :file_field_value,
79
- :file_field_value_removal,
80
- :option_value,
81
- :password_field_value,
82
- :phone_field_value,
83
- :super_select_value,
84
- :text_area_value,
85
- # 🚅 stop any skipping we're doing now.
86
- # 🚅 super scaffolding will insert new fields above this line.
87
- # 🚅 skip this section when scaffolding.
88
- multiple_button_values: [],
89
- multiple_option_values: [],
90
- multiple_super_select_values: []
91
- # 🚅 stop any skipping we're doing now.
92
- # 🚅 super scaffolding will insert new arrays above this line.
93
- )
64
+ include strong_parameters_from_api
94
65
 
66
+ def process_params(strong_params)
95
67
  # 🚅 skip this section when scaffolding.
96
68
  assign_boolean(strong_params, :boolean_button_value)
97
69
  assign_date_and_time(strong_params, :date_and_time_field_value)
@@ -100,7 +72,5 @@ class Account::Scaffolding::CompletelyConcrete::TangibleThingsController < Accou
100
72
  assign_select_options(strong_params, :multiple_super_select_values)
101
73
  # 🚅 stop any skipping we're doing now.
102
74
  # 🚅 super scaffolding will insert processing for new fields above this line.
103
-
104
- strong_params
105
75
  end
106
76
  end
@@ -0,0 +1,78 @@
1
+ class Api::V1::Scaffolding::CompletelyConcrete::TangibleThingsController < Api::V1::ApplicationController
2
+ account_load_and_authorize_resource :tangible_thing, through: :absolutely_abstract_creative_concept, through_association: :completely_concrete_tangible_things
3
+
4
+ # GET /api/v1/scaffolding/absolutely_abstract/creative_concepts/:absolutely_abstract_creative_concept_id/completely_concrete/tangible_things
5
+ def index
6
+ end
7
+
8
+ # GET /api/v1/scaffolding/completely_concrete/tangible_things/:id
9
+ def show
10
+ end
11
+
12
+ # POST /api/v1/scaffolding/absolutely_abstract/creative_concepts/:absolutely_abstract_creative_concept_id/completely_concrete/tangible_things
13
+ def create
14
+ if @tangible_thing.save
15
+ render :show, status: :created, location: [:api, :v1, @tangible_thing]
16
+ else
17
+ render json: @tangible_thing.errors, status: :unprocessable_entity
18
+ end
19
+ end
20
+
21
+ # PATCH/PUT /api/v1/scaffolding/completely_concrete/tangible_things/:id
22
+ def update
23
+ if @tangible_thing.update(tangible_thing_params)
24
+ render :show
25
+ else
26
+ render json: @tangible_thing.errors, status: :unprocessable_entity
27
+ end
28
+ end
29
+
30
+ # DELETE /api/v1/scaffolding/completely_concrete/tangible_things/:id
31
+ def destroy
32
+ @tangible_thing.destroy
33
+ end
34
+
35
+ private
36
+
37
+ module StrongParameters
38
+ # Only allow a list of trusted parameters through.
39
+ def tangible_thing_params
40
+ strong_params = params.require(:scaffolding_completely_concrete_tangible_thing).permit(
41
+ *permitted_fields,
42
+ # 🚅 skip this section when scaffolding.
43
+ :text_field_value,
44
+ :action_text_value,
45
+ :boolean_button_value,
46
+ :button_value,
47
+ :color_picker_value,
48
+ :cloudinary_image_value,
49
+ :date_field_value,
50
+ :date_and_time_field_value,
51
+ :date_and_time_field_value_time_zone,
52
+ :email_field_value,
53
+ :file_field_value,
54
+ :file_field_value_removal,
55
+ :option_value,
56
+ :password_field_value,
57
+ :phone_field_value,
58
+ :super_select_value,
59
+ :text_area_value,
60
+ # 🚅 stop any skipping we're doing now.
61
+ # 🚅 super scaffolding will insert new fields above this line.
62
+ *permitted_arrays,
63
+ # 🚅 skip this section when scaffolding.
64
+ multiple_button_values: [],
65
+ multiple_option_values: [],
66
+ multiple_super_select_values: []
67
+ # 🚅 stop any skipping we're doing now.
68
+ # 🚅 super scaffolding will insert new arrays above this line.
69
+ )
70
+
71
+ process_params(strong_params)
72
+
73
+ strong_params
74
+ end
75
+ end
76
+
77
+ include StrongParameters
78
+ end
@@ -7,6 +7,7 @@ json.extract! tangible_thing,
7
7
  :color_picker_value,
8
8
  :cloudinary_image_value,
9
9
  :date_field_value,
10
+ :date_and_time_field_value,
10
11
  :email_field_value,
11
12
  :password_field_value,
12
13
  :phone_field_value,
@@ -19,4 +20,3 @@ json.extract! tangible_thing,
19
20
  # 🚅 super scaffolding will insert new fields above this line.
20
21
  :created_at,
21
22
  :updated_at
22
- json.url account_scaffolding_completely_concrete_tangible_thing_url(tangible_thing, format: :json)
@@ -0,0 +1,5 @@
1
+ json.data do
2
+ json.array! @tangible_things, partial: "api/v1/scaffolding/completely_concrete/tangible_things/tangible_thing", as: :tangible_thing
3
+ end
4
+
5
+ render_pagination(json)
@@ -0,0 +1 @@
1
+ json.partial! "api/v1/scaffolding/completely_concrete/tangible_things/tangible_thing", tangible_thing: @tangible_thing
data/config/routes.rb CHANGED
@@ -1,5 +1,36 @@
1
1
  Rails.application.routes.draw do
2
- collection_actions = [:index, :new, :create]
2
+ # See `config/routes.rb` for details.
3
+ collection_actions = [:index, :new, :create] # standard:disable Lint/UselessAssignment
4
+ extending = {only: []}
5
+
6
+ namespace :api do
7
+ namespace :v1 do
8
+ shallow do
9
+ resources :teams, extending do
10
+ unless scaffolding_things_disabled?
11
+ namespace :scaffolding do
12
+ namespace :absolutely_abstract do
13
+ resources :creative_concepts do
14
+ scope module: "creative_concepts" do
15
+ resources :collaborators, only: collection_actions
16
+ end
17
+
18
+ namespace :creative_concepts do
19
+ resources :collaborators, except: collection_actions
20
+ end
21
+ end
22
+ end
23
+ resources :absolutely_abstract_creative_concepts, path: "absolutely_abstract/creative_concepts" do
24
+ namespace :completely_concrete do
25
+ resources :tangible_things
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
3
34
 
4
35
  namespace :account do
5
36
  shallow do
@@ -10,13 +10,6 @@ module BulletTrain
10
10
  BulletTrain::SuperScaffolding.template_paths << File.expand_path("../../../..", __FILE__)
11
11
  end
12
12
 
13
- initializer "bullet_train.super_scaffolding.templates.register_api_endpoints" do |app|
14
- if defined?(BulletTrain::Api)
15
- BulletTrain::Api.endpoints << "Api::V1::Scaffolding::AbsolutelyAbstract::CreativeConceptsEndpoint"
16
- BulletTrain::Api.endpoints << "Api::V1::Scaffolding::CompletelyConcrete::TangibleThingsEndpoint"
17
- end
18
- end
19
-
20
13
  initializer "bullet_train.super_scaffolding.register" do |app|
21
14
  # Older versions of Bullet Train have a `BulletTrain` module, but it doesn't have `linked_gems`.
22
15
  if BulletTrain.respond_to?(:linked_gems)
@@ -1,5 +1,5 @@
1
1
  module BulletTrain
2
2
  module SuperScaffolding
3
- VERSION = "1.0.42"
3
+ VERSION = "1.1.1"
4
4
  end
5
5
  end
@@ -15,6 +15,11 @@ module Scaffolding::FileManipulator
15
15
  lines[(within + 1)..(Scaffolding::BlockManipulator.find_block_end(starting_from: within, lines: lines) + 1)]
16
16
  end
17
17
 
18
+ # TODO I was running into an error in a downstream application where it couldn't find silence_logs? We should implement it in this package.
19
+ def self.silence_logs?
20
+ ENV["SILENCE_LOGS"].present?
21
+ end
22
+
18
23
  def self.replace_line_in_file(file, content, in_place_of, options = {})
19
24
  begin
20
25
  target_file_content = File.read(file)
@@ -66,7 +71,7 @@ module Scaffolding::FileManipulator
66
71
  end
67
72
 
68
73
  def self.write(file_name, lines, strip: true)
69
- puts "Updating '#{file_name}'." unless ENV["SILENCE_LOGS"].present?
74
+ puts "Updating '#{file_name}'." unless silence_logs?
70
75
  if strip
71
76
  File.open(file_name, "w+") do |file|
72
77
  file.puts(lines.join.strip + "\n")
@@ -10,6 +10,11 @@ def legacy_resolve_template_path(file)
10
10
  end.compact.first || raise("Couldn't find the Super Scaffolding template for `#{file}` in any of the following locations:\n\n#{BulletTrain::SuperScaffolding.template_paths.join("\n")}")
11
11
  end
12
12
 
13
+ # TODO I was running into an error in a downstream application where it couldn't find silence_logs? We should implement it in this package.
14
+ def silence_logs?
15
+ ENV["SILENCE_LOGS"].present?
16
+ end
17
+
13
18
  def legacy_replace_in_file(file, before, after)
14
19
  puts "Replacing in '#{file}'." unless silence_logs?
15
20
  target_file_content = File.read(file)
@@ -45,7 +45,6 @@ class Scaffolding::Transformer
45
45
  RUBY_ADDITIONAL_NEW_FIELDS_HOOK = "# 🚅 super scaffolding will also insert new fields above this line."
46
46
  RUBY_EVEN_MORE_NEW_FIELDS_HOOK = "# 🚅 super scaffolding will additionally insert new fields above this line."
47
47
  RUBY_FILES_HOOK = "# 🚅 super scaffolding will insert file-related logic above this line."
48
- ENDPOINTS_HOOK = "# 🚅 super scaffolding will mount new endpoints above this line."
49
48
  ERB_NEW_FIELDS_HOOK = "<%#{RUBY_NEW_FIELDS_HOOK} %>"
50
49
  CONCERNS_HOOK = "# 🚅 add concerns above."
51
50
  ATTR_ACCESSORS_HOOK = "# 🚅 add attribute accessors above."
@@ -231,10 +230,18 @@ class Scaffolding::Transformer
231
230
  transformed_file_content.join
232
231
  end
233
232
 
234
- def scaffold_file(file)
233
+ # TODO I was running into an error in a downstream application where it couldn't find silence_logs? We should implement it in this package.
234
+ def silence_logs?
235
+ ENV["SILENCE_LOGS"].present?
236
+ end
237
+
238
+ def scaffold_file(file, overrides: false)
235
239
  transformed_file_content = get_transformed_file_content(file)
236
240
  transformed_file_name = transform_string(file)
237
241
 
242
+ # Remove `_overrides` from the file name if we're sourcing from a local override folder.
243
+ transformed_file_name.gsub!("_overrides", "") if overrides
244
+
238
245
  transformed_directory_name = File.dirname(transformed_file_name)
239
246
  unless File.directory?(transformed_directory_name)
240
247
  FileUtils.mkdir_p(transformed_directory_name)
@@ -266,6 +273,22 @@ class Scaffolding::Transformer
266
273
  scaffold_file(file)
267
274
  end
268
275
  end
276
+
277
+ # Allow local developers to override just certain files of a directory.
278
+ override_path = begin
279
+ resolve_template_path(directory + "_overrides")
280
+ rescue RuntimeError
281
+ nil
282
+ end
283
+
284
+ if override_path
285
+ Dir.foreach(override_path) do |file|
286
+ file = "#{directory}_overrides/#{file}"
287
+ unless File.directory?(resolve_template_path(file))
288
+ scaffold_file(file, overrides: true)
289
+ end
290
+ end
291
+ end
269
292
  end
270
293
 
271
294
  def add_line_to_file(file, content, hook, options = {})
@@ -691,6 +714,8 @@ class Scaffolding::Transformer
691
714
  "'another.email@test.com'"
692
715
  when "phone_field"
693
716
  "'+19053871234'"
717
+ when "color_picker"
718
+ "'#47E37F'"
694
719
  end
695
720
 
696
721
  # don't do table columns for certain types of fields and attribute partials
@@ -968,7 +993,8 @@ class Scaffolding::Transformer
968
993
 
969
994
  # add attributes to strong params.
970
995
  [
971
- "./app/controllers/account/scaffolding/completely_concrete/tangible_things_controller.rb"
996
+ "./app/controllers/account/scaffolding/completely_concrete/tangible_things_controller.rb",
997
+ "./app/controllers/api/v1/scaffolding/completely_concrete/tangible_things_controller.rb"
972
998
  ].each do |file|
973
999
  if is_ids || is_multiple
974
1000
  scaffold_add_line_to_file(file, "#{name}: [],", RUBY_NEW_ARRAYS_HOOK, prepend: true)
@@ -1002,38 +1028,6 @@ class Scaffolding::Transformer
1002
1028
  scaffold_add_line_to_file("./app/controllers/account/scaffolding/completely_concrete/tangible_things_controller.rb", special_processing, RUBY_NEW_FIELDS_PROCESSING_HOOK, prepend: true) if special_processing
1003
1029
  end
1004
1030
 
1005
- #
1006
- # API ENDPOINT
1007
- #
1008
-
1009
- unless cli_options["skip-api"]
1010
-
1011
- # add attributes to endpoint.
1012
- if name.match?(/_ids$/)
1013
- scaffold_add_line_to_file("./app/controllers/api/v1/scaffolding/completely_concrete/tangible_things_endpoint.rb", "optional :#{name}, type: Array, desc: Api.heading(:#{name})", RUBY_NEW_ARRAYS_HOOK, prepend: true)
1014
- else
1015
- api_type = case type
1016
- when "date_field"
1017
- "Date"
1018
- when "date_and_time_field"
1019
- "DateTime"
1020
- when "buttons"
1021
- if boolean_buttons
1022
- "Boolean"
1023
- else
1024
- "String"
1025
- end
1026
- when "file_field"
1027
- "File"
1028
- else
1029
- "String"
1030
- end
1031
-
1032
- scaffold_add_line_to_file("./app/controllers/api/v1/scaffolding/completely_concrete/tangible_things_endpoint.rb", "optional :#{name}, type: #{api_type}, desc: Api.heading(:#{name})", RUBY_NEW_FIELDS_HOOK, prepend: true)
1033
- end
1034
-
1035
- end
1036
-
1037
1031
  #
1038
1032
  # API SERIALIZER
1039
1033
  #
@@ -1042,8 +1036,7 @@ class Scaffolding::Transformer
1042
1036
 
1043
1037
  # TODO The serializers can't handle these `has_rich_text` attributes.
1044
1038
  unless type == "trix_editor"
1045
- scaffold_add_line_to_file("./app/views/account/scaffolding/completely_concrete/tangible_things/_tangible_thing.json.jbuilder", ":#{name},", RUBY_NEW_FIELDS_HOOK, prepend: true, suppress_could_not_find: true)
1046
- scaffold_add_line_to_file("./app/serializers/api/v1/scaffolding/completely_concrete/tangible_thing_serializer.rb", ":#{name},", RUBY_NEW_FIELDS_HOOK, prepend: true) unless type == "file_field"
1039
+ scaffold_add_line_to_file("./app/views/api/v1/scaffolding/completely_concrete/tangible_things/_tangible_thing.json.jbuilder", ":#{name},", RUBY_NEW_FIELDS_HOOK, prepend: true, suppress_could_not_find: true)
1047
1040
 
1048
1041
  assertion = case type
1049
1042
  when "date_field"
@@ -1051,52 +1044,27 @@ class Scaffolding::Transformer
1051
1044
  when "date_and_time_field"
1052
1045
  "assert_equal_or_nil DateTime.parse(tangible_thing_data['#{name}']), tangible_thing.#{name}"
1053
1046
  when "file_field"
1054
- # TODO: If we want to use Cloudinary to handle our files, we should make sure we're getting a URL.
1055
- "assert tangible_thing_data['#{name}'].match?('foo.txt') unless response.status == 201"
1047
+ # TODO Get this working again.
1048
+ "# assert tangible_thing_data['#{name}'].match?('foo.txt') unless response.status == 201"
1056
1049
  else
1057
1050
  "assert_equal_or_nil tangible_thing_data['#{name}'], tangible_thing.#{name}"
1058
1051
  end
1059
- scaffold_add_line_to_file("./test/controllers/api/v1/scaffolding/completely_concrete/tangible_things_endpoint_test.rb", assertion, RUBY_NEW_FIELDS_HOOK, prepend: true)
1052
+ scaffold_add_line_to_file("./test/controllers/api/v1/scaffolding/completely_concrete/tangible_things_controller_test.rb", assertion, RUBY_NEW_FIELDS_HOOK, prepend: true)
1060
1053
  end
1061
1054
 
1062
1055
  # File fields are handled in a specific way when using the jsonapi-serializer.
1063
1056
  if type == "file_field"
1064
- file_name = "./app/serializers/api/v1/scaffolding/completely_concrete/tangible_thing_serializer.rb"
1065
- content = <<~RUBY
1066
- attribute :#{name} do |object|
1067
- rails_blob_path(object.#{name}, disposition: "attachment", only_path: true) if object.#{name}.attached?
1068
- end
1069
-
1070
- RUBY
1071
- hook = RUBY_FILES_HOOK
1072
- scaffold_add_line_to_file(file_name, content, hook, prepend: true)
1073
-
1074
- # We also want to make sure we attach the dummy file in the endpoint test on setup
1075
- file_name = "./test/controllers/api/v1/scaffolding/completely_concrete/tangible_things_endpoint_test.rb"
1076
- content = "@#{child.underscore}.#{name} = Rack::Test::UploadedFile.new(\"test/support/foo.txt\")"
1077
- scaffold_add_line_to_file(file_name, content, hook, prepend: true)
1057
+ # TODO Get this working again.
1058
+ # We also want to make sure we attach the dummy file in the API test on setup
1059
+ file_name = "./test/controllers/api/v1/scaffolding/completely_concrete/tangible_things_controller_test.rb"
1060
+ content = "# @#{child.underscore}.#{name} = Rack::Test::UploadedFile.new(\"test/support/foo.txt\")"
1061
+ scaffold_add_line_to_file(file_name, content, RUBY_FILES_HOOK, prepend: true)
1078
1062
  end
1079
1063
 
1080
- # scaffold_add_line_to_file("./test/controllers/api/v1/scaffolding/completely_concrete/tangible_things_controller_test.rb", "assert_equal tangible_thing_attributes['#{name.gsub('_', '-')}'], tangible_thing.#{name}", RUBY_NEW_FIELDS_HOOK, prepend: true)
1081
-
1082
1064
  if attribute_assignment
1083
1065
  unless attribute_options[:readonly]
1084
- scaffold_add_line_to_file("./test/controllers/api/v1/scaffolding/completely_concrete/tangible_things_endpoint_test.rb", "#{name}: #{attribute_assignment},", RUBY_ADDITIONAL_NEW_FIELDS_HOOK, prepend: true)
1085
- scaffold_add_line_to_file("./test/controllers/api/v1/scaffolding/completely_concrete/tangible_things_endpoint_test.rb", "assert_equal @tangible_thing.#{name}, #{attribute_assignment}", RUBY_EVEN_MORE_NEW_FIELDS_HOOK, prepend: true)
1086
- end
1087
- end
1088
-
1089
- # We need to update our new Tangible Thing's
1090
- # jbuilder files if it's scoped under "account".
1091
- # TODO: Should we run this if `namespace.present?` instead?
1092
- if namespace == "account"
1093
- target_string = "#{transform_string("scaffolding/completely_concrete/tangible_things")}/#{transform_string("tangible_thing")}"
1094
- replacement_string = "#{namespace}/#{target_string}"
1095
- [
1096
- "app/views/account/completely_concrete/tangible_things/index.json.jbuilder",
1097
- "app/views/account/completely_concrete/tangible_things/show.json.jbuilder"
1098
- ].each do |path|
1099
- scaffold_replace_line_in_file(path, replacement_string, target_string)
1066
+ scaffold_add_line_to_file("./test/controllers/api/v1/scaffolding/completely_concrete/tangible_things_controller_test.rb", "#{name}: #{attribute_assignment},", RUBY_ADDITIONAL_NEW_FIELDS_HOOK, prepend: true)
1067
+ scaffold_add_line_to_file("./test/controllers/api/v1/scaffolding/completely_concrete/tangible_things_controller_test.rb", "assert_equal @tangible_thing.#{name}, #{attribute_assignment}", RUBY_EVEN_MORE_NEW_FIELDS_HOOK, prepend: true)
1100
1068
  end
1101
1069
  end
1102
1070
  end
@@ -1283,10 +1251,10 @@ class Scaffolding::Transformer
1283
1251
  [
1284
1252
  "./app/controllers/account/scaffolding/completely_concrete/tangible_things_controller.rb",
1285
1253
  "./app/views/account/scaffolding/completely_concrete/tangible_things",
1254
+ "./app/views/api/v1/scaffolding/completely_concrete/tangible_things",
1286
1255
  ("./config/locales/en/scaffolding/completely_concrete/tangible_things.en.yml" unless cli_options["skip-locales"]),
1287
- ("./app/controllers/api/v1/scaffolding/completely_concrete/tangible_things_endpoint.rb" unless cli_options["skip-api"]),
1288
- ("./test/controllers/api/v1/scaffolding/completely_concrete/tangible_things_endpoint_test.rb" unless cli_options["skip-api"]),
1289
- ("./app/serializers/api/v1/scaffolding/completely_concrete/tangible_thing_serializer.rb" unless cli_options["skip-api"])
1256
+ ("./app/controllers/api/v1/scaffolding/completely_concrete/tangible_things_controller.rb" unless cli_options["skip-api"]),
1257
+ ("./test/controllers/api/v1/scaffolding/completely_concrete/tangible_things_controller_test.rb" unless cli_options["skip-api"])
1290
1258
  # "./app/filters/scaffolding/completely_concrete/tangible_things_filter.rb"
1291
1259
  ].compact
1292
1260
  end
@@ -1299,13 +1267,6 @@ class Scaffolding::Transformer
1299
1267
  end
1300
1268
  end
1301
1269
 
1302
- unless cli_options["skip-api"]
1303
-
1304
- # add endpoint to the api.
1305
- scaffold_add_line_to_file("./app/controllers/api/v1/root.rb", "mount Api::V1::Scaffolding::CompletelyConcrete::TangibleThingsEndpoint", ENDPOINTS_HOOK, prepend: true)
1306
-
1307
- end
1308
-
1309
1270
  unless cli_options["skip-model"]
1310
1271
  # find the database migration that defines this relationship.
1311
1272
  migration_file_name = `grep "create_table :#{class_names_transformer.table_name} do |t|" db/migrate/*`.split(":").first
@@ -1343,7 +1304,7 @@ class Scaffolding::Transformer
1343
1304
  end
1344
1305
 
1345
1306
  unless cli_options["skip-api"]
1346
- scaffold_replace_line_in_file("./test/controllers/api/v1/scaffolding/completely_concrete/tangible_things_endpoint_test.rb", build_factory_setup.join("\n"), "# 🚅 super scaffolding will insert factory setup in place of this line.")
1307
+ scaffold_replace_line_in_file("./test/controllers/api/v1/scaffolding/completely_concrete/tangible_things_controller_test.rb", build_factory_setup.join("\n"), "# 🚅 super scaffolding will insert factory setup in place of this line.")
1347
1308
  end
1348
1309
 
1349
1310
  # add children to the show page of their parent.
@@ -1442,6 +1403,18 @@ class Scaffolding::Transformer
1442
1403
  end
1443
1404
 
1444
1405
  Scaffolding::FileManipulator.write("config/routes.rb", routes_manipulator.lines)
1406
+
1407
+ unless cli_options["skip-api"]
1408
+ begin
1409
+ api_routes_manipulator = Scaffolding::RoutesFileManipulator.new("config/routes/api/#{BulletTrain::Api.current_version}.rb", child, parent, cli_options)
1410
+ api_routes_manipulator.apply([BulletTrain::Api.current_version.to_sym])
1411
+ rescue => e
1412
+ puts "We weren't able to automatically add your `api/#{BulletTrain::Api.current_version}` routes for you. In theory this should be very rare, so if you could reach out on Slack, you could probably provide context that will help us fix whatever the problem was. In the meantime, to add the routes manually, we've got a guide at https://blog.bullettrain.co/nested-namespaced-rails-routing-examples/ .".send(:yellow)
1413
+ raise e
1414
+ end
1415
+
1416
+ Scaffolding::FileManipulator.write("config/routes/api/#{BulletTrain::Api.current_version}.rb", api_routes_manipulator.lines)
1417
+ end
1445
1418
  end
1446
1419
 
1447
1420
  unless cli_options["skip-parent"]
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.0.42
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Culver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-24 00:00:00.000000000 Z
11
+ date: 2022-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: standard
@@ -85,9 +85,8 @@ files:
85
85
  - app/controllers/api/v1.rb
86
86
  - app/controllers/api/v1/scaffolding.rb
87
87
  - app/controllers/api/v1/scaffolding/absolutely_abstract.rb
88
- - app/controllers/api/v1/scaffolding/absolutely_abstract/creative_concepts_endpoint.rb
89
88
  - app/controllers/api/v1/scaffolding/completely_concrete.rb
90
- - app/controllers/api/v1/scaffolding/completely_concrete/tangible_things_endpoint.rb
89
+ - app/controllers/api/v1/scaffolding/completely_concrete/tangible_things_controller.rb
91
90
  - app/controllers/concerns/scaffolding/absolutely_abstract/creative_concepts/controller_support.rb
92
91
  - app/helpers/super_scaffolding_helper.rb
93
92
  - app/models/scaffolding.rb
@@ -99,8 +98,6 @@ files:
99
98
  - app/models/scaffolding/completely_concrete/tangible_thing.rb
100
99
  - app/models/scaffolding/completely_concrete/tangible_things.rb
101
100
  - app/models/scaffolding/completely_concrete/tangible_things/assignment.rb
102
- - app/serializers/api/v1/scaffolding/absolutely_abstract/creative_concept_serializer.rb
103
- - app/serializers/api/v1/scaffolding/completely_concrete/tangible_thing_serializer.rb
104
101
  - app/views/account/scaffolding/absolutely_abstract/creative_concepts/_breadcrumbs.html.erb
105
102
  - app/views/account/scaffolding/absolutely_abstract/creative_concepts/_creative_concept.json.jbuilder
106
103
  - app/views/account/scaffolding/absolutely_abstract/creative_concepts/_form.html.erb
@@ -127,13 +124,13 @@ files:
127
124
  - app/views/account/scaffolding/completely_concrete/tangible_things/_form.html.erb
128
125
  - app/views/account/scaffolding/completely_concrete/tangible_things/_index.html.erb
129
126
  - app/views/account/scaffolding/completely_concrete/tangible_things/_menu_item.html.erb
130
- - app/views/account/scaffolding/completely_concrete/tangible_things/_tangible_thing.json.jbuilder
131
127
  - app/views/account/scaffolding/completely_concrete/tangible_things/edit.html.erb
132
128
  - app/views/account/scaffolding/completely_concrete/tangible_things/index.html.erb
133
- - app/views/account/scaffolding/completely_concrete/tangible_things/index.json.jbuilder
134
129
  - app/views/account/scaffolding/completely_concrete/tangible_things/new.html.erb
135
130
  - app/views/account/scaffolding/completely_concrete/tangible_things/show.html.erb
136
- - app/views/account/scaffolding/completely_concrete/tangible_things/show.json.jbuilder
131
+ - app/views/api/v1/scaffolding/completely_concrete/tangible_things/_tangible_thing.json.jbuilder
132
+ - app/views/api/v1/scaffolding/completely_concrete/tangible_things/index.json.jbuilder
133
+ - app/views/api/v1/scaffolding/completely_concrete/tangible_things/show.json.jbuilder
137
134
  - app/views/shared/_bulk_action_select.html.erb
138
135
  - app/views/shared/tables/_checkbox.html.erb
139
136
  - app/views/shared/tables/_select_all.html.erb
@@ -1,103 +0,0 @@
1
- class Api::V1::Scaffolding::AbsolutelyAbstract::CreativeConceptsEndpoint < Api::V1::Root
2
- helpers do
3
- include Scaffolding::AbsolutelyAbstract::CreativeConcepts::ControllerSupport
4
-
5
- params :team_id do
6
- requires :team_id, type: Integer, allow_blank: false, desc: Api.heading(:team_id)
7
- end
8
-
9
- params :id do
10
- requires :id, type: Integer, allow_blank: false, desc: Api.heading(:id)
11
- end
12
-
13
- params :creative_concept do
14
- optional :name, type: String, allow_blank: false, desc: Api.heading(:name)
15
- optional :description, type: String, allow_blank: true, desc: Api.heading(:description)
16
- # 🚅 super scaffolding will insert new fields above this line.
17
- # 🚅 super scaffolding will insert new arrays above this line.
18
-
19
- # 🚅 super scaffolding will insert processing for new fields above this line.
20
- end
21
- end
22
-
23
- # uses shallow routing to support teams
24
- resource :teams, desc: Api.title(:collection_actions) do
25
- after_validation do
26
- load_and_authorize_api_resource Scaffolding::AbsolutelyAbstract::CreativeConcept
27
- end
28
-
29
- desc Api.title(:index), &Api.index_desc
30
- params do
31
- use :team_id
32
- end
33
- oauth2
34
- paginate per_page: 100
35
- get "/:team_id/scaffolding/absolutely_abstract/creative_concepts" do
36
- @paginated_creative_concepts = paginate @creative_concepts
37
- render @paginated_creative_concepts, serializer: Api.serializer, adapter: :attributes
38
- end
39
-
40
- desc Api.title(:create), &Api.create_desc
41
- params do
42
- use :team_id
43
- use :creative_concept
44
- end
45
- route_setting :api_resource_options, permission: :create
46
- oauth2 "write"
47
- post "/:team_id/scaffolding/absolutely_abstract/creative_concepts" do
48
- ensure_current_user_can_manage_creative_concept @creative_concept
49
-
50
- if @creative_concept.save
51
- render @creative_concept, serializer: Api.serializer
52
- else
53
- record_not_saved @creative_concept
54
- end
55
- end
56
- end
57
-
58
- resource "scaffolding/absolutely_abstract/creative_concepts", desc: Api.title(:member_actions) do
59
- after_validation do
60
- load_and_authorize_api_resource Scaffolding::AbsolutelyAbstract::CreativeConcept
61
- end
62
-
63
- desc Api.title(:show), &Api.show_desc
64
- params do
65
- use :id
66
- end
67
- oauth2
68
- route_param :id do
69
- get do
70
- render @creative_concept, serializer: Api.serializer
71
- end
72
- end
73
-
74
- desc Api.title(:update), &Api.update_desc
75
- params do
76
- use :id
77
- use :creative_concept
78
- end
79
- route_setting :api_resource_options, permission: :update
80
- oauth2 "write"
81
- route_param :id do
82
- put do
83
- if @creative_concept.update(declared(params, include_missing: false))
84
- render @creative_concept, serializer: Api.serializer
85
- else
86
- record_not_saved @creative_concept
87
- end
88
- end
89
- end
90
-
91
- desc Api.title(:destroy), &Api.destroy_desc
92
- params do
93
- use :id
94
- end
95
- route_setting :api_resource_options, permission: :destroy
96
- oauth2 "delete"
97
- route_param :id do
98
- delete do
99
- render @creative_concept.destroy, serializer: Api.serializer
100
- end
101
- end
102
- end
103
- end
@@ -1,136 +0,0 @@
1
- class Api::V1::Scaffolding::CompletelyConcrete::TangibleThingsEndpoint < Api::V1::Root
2
- helpers do
3
- params :absolutely_abstract_creative_concept_id do
4
- requires :absolutely_abstract_creative_concept_id, type: Integer, allow_blank: false, desc: "Creative Concept ID"
5
- end
6
-
7
- params :id do
8
- requires :id, type: Integer, allow_blank: false, desc: "Tangible Thing ID"
9
- end
10
-
11
- params :tangible_thing do
12
- # 🚅 skip this section when scaffolding.
13
- optional :text_field_value, type: String, allow_blank: true, desc: Api.heading(:text_field_value)
14
- optional :button_value, type: String, allow_blank: true, desc: Api.heading(:button_value)
15
- optional :cloudinary_image_value, type: String, allow_blank: true, desc: Api.heading(:cloudinary_image_value)
16
- optional :date_field_value, type: Date, allow_blank: true, desc: Api.heading(:date_field_value)
17
- optional :date_and_time_field_value, type: DateTime, allow_blank: true, desc: Api.heading(:date_and_time_field_value)
18
- optional :email_field_value, type: String, allow_blank: true, desc: Api.heading(:email_field_value)
19
- optional :file_field_value, type: String, allow_blank: true, desc: Api.heading(:file_field_value)
20
- optional :password_field_value, type: String, allow_blank: true, desc: Api.heading(:password_field_value)
21
- optional :phone_field_value, type: String, allow_blank: true, desc: Api.heading(:phone_field_value)
22
- optional :option_value, type: String, allow_blank: true, desc: Api.heading(:option_value)
23
- optional :super_select_value, type: String, allow_blank: true, desc: Api.heading(:super_select_value)
24
- optional :text_area_value, type: String, allow_blank: true, desc: Api.heading(:text_area_value)
25
- optional :action_text_value, type: String, allow_blank: true, desc: Api.heading(:action_text_value)
26
- # 🚅 stop any skipping we're doing now.
27
- # 🚅 super scaffolding will insert new fields above this line.
28
- # 🚅 skip this section when scaffolding.
29
- optional :multiple_button_values, type: Array, default: [], desc: Api.heading(:multiple_button_values)
30
- optional :multiple_option_values, type: Array, default: [], desc: Api.heading(:multiple_option_values)
31
- optional :multiple_super_select_values, type: Array, default: [], desc: Api.heading(:multiple_super_select_values)
32
- # 🚅 stop any skipping we're doing now.
33
- # 🚅 super scaffolding will insert new arrays above this line.
34
-
35
- # 🚅 super scaffolding will insert processing for new fields above this line.
36
- end
37
- end
38
-
39
- resource "scaffolding/absolutely_abstract/creative_concepts", desc: Api.title(:collection_actions) do
40
- after_validation do
41
- load_and_authorize_api_resource Scaffolding::CompletelyConcrete::TangibleThing
42
- end
43
-
44
- #
45
- # INDEX
46
- #
47
-
48
- desc Api.title(:index), &Api.index_desc
49
- params do
50
- use :absolutely_abstract_creative_concept_id
51
- end
52
- oauth2
53
- paginate per_page: 100
54
- get "/:absolutely_abstract_creative_concept_id/completely_concrete/tangible_things" do
55
- @paginated_tangible_things = paginate @tangible_things
56
- render @paginated_tangible_things, serializer: Api.serializer
57
- end
58
-
59
- #
60
- # CREATE
61
- #
62
-
63
- desc Api.title(:create), &Api.create_desc
64
- params do
65
- use :absolutely_abstract_creative_concept_id
66
- use :tangible_thing
67
- end
68
- route_setting :api_resource_options, permission: :create
69
- oauth2 "write"
70
- post "/:absolutely_abstract_creative_concept_id/completely_concrete/tangible_things" do
71
- if @tangible_thing.save
72
- render @tangible_thing, serializer: Api.serializer
73
- else
74
- record_not_saved @tangible_thing
75
- end
76
- end
77
- end
78
-
79
- resource "scaffolding/completely_concrete/tangible_things", desc: Api.title(:member_actions) do
80
- after_validation do
81
- load_and_authorize_api_resource Scaffolding::CompletelyConcrete::TangibleThing
82
- end
83
-
84
- #
85
- # SHOW
86
- #
87
-
88
- desc Api.title(:show), &Api.show_desc
89
- params do
90
- use :id
91
- end
92
- oauth2
93
- route_param :id do
94
- get do
95
- render @tangible_thing, serializer: Api.serializer
96
- end
97
- end
98
-
99
- #
100
- # UPDATE
101
- #
102
-
103
- desc Api.title(:update), &Api.update_desc
104
- params do
105
- use :id
106
- use :tangible_thing
107
- end
108
- route_setting :api_resource_options, permission: :update
109
- oauth2 "write"
110
- route_param :id do
111
- put do
112
- if @tangible_thing.update(declared(params, include_missing: false))
113
- render @tangible_thing, serializer: Api.serializer
114
- else
115
- record_not_saved @tangible_thing
116
- end
117
- end
118
- end
119
-
120
- #
121
- # DESTROY
122
- #
123
-
124
- desc Api.title(:destroy), &Api.destroy_desc
125
- params do
126
- use :id
127
- end
128
- route_setting :api_resource_options, permission: :destroy
129
- oauth2 "delete"
130
- route_param :id do
131
- delete do
132
- render @tangible_thing.destroy, serializer: Api.serializer
133
- end
134
- end
135
- end
136
- end
@@ -1,14 +0,0 @@
1
- class Api::V1::Scaffolding::AbsolutelyAbstract::CreativeConceptSerializer < Api::V1::ApplicationSerializer
2
- set_type "scaffolding/absolutely_abstract/creative_concept"
3
-
4
- attributes :id,
5
- :team_id,
6
- :name,
7
- :description,
8
- # 🚅 super scaffolding will insert new fields above this line.
9
- :created_at,
10
- :updated_at
11
-
12
- belongs_to :team, serializer: Api::V1::TeamSerializer
13
- has_many :completely_concrete_tangible_things, serializer: Api::V1::Scaffolding::CompletelyConcrete::TangibleThingSerializer
14
- end
@@ -1,37 +0,0 @@
1
- class Api::V1::Scaffolding::CompletelyConcrete::TangibleThingSerializer < Api::V1::ApplicationSerializer
2
- set_type "scaffolding/completely_concrete/tangible_thing"
3
- singleton_class.include Rails.application.routes.url_helpers
4
-
5
- attributes :id,
6
- :absolutely_abstract_creative_concept_id,
7
- # 🚅 skip this section when scaffolding.
8
- :text_field_value,
9
- :button_value,
10
- :multiple_button_values,
11
- :color_picker_value,
12
- :cloudinary_image_value,
13
- :date_field_value,
14
- :date_and_time_field_value,
15
- :email_field_value,
16
- :password_field_value,
17
- :phone_field_value,
18
- :option_value,
19
- # :multiple_option_values,
20
- :super_select_value,
21
- # :multiple_super_select_values,
22
- # :text_area_value,
23
- # :action_text_value,
24
- # 🚅 stop any skipping we're doing now.
25
- # 🚅 super scaffolding will insert new fields above this line.
26
- :created_at,
27
- :updated_at
28
-
29
- # 🚅 skip this section when scaffolding.
30
- attribute :file_field_value do |object|
31
- rails_blob_path(object.file_field_value, disposition: "attachment", only_path: true) if object.file_field_value.attached?
32
- end
33
- # 🚅 stop any skipping we're doing now.
34
- # 🚅 super scaffolding will insert file-related logic above this line.
35
-
36
- belongs_to :absolutely_abstract_creative_concept, serializer: Api::V1::Scaffolding::AbsolutelyAbstract::CreativeConceptSerializer
37
- end
@@ -1 +0,0 @@
1
- json.array! @tangible_things, partial: "scaffolding/completely_concrete/tangible_things/tangible_thing", as: :tangible_thing
@@ -1 +0,0 @@
1
- json.partial! "scaffolding/completely_concrete/tangible_things/tangible_thing", tangible_thing: @tangible_thing