propel_api 0.1.3 โ†’ 0.2.0

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.
@@ -5,9 +5,18 @@ require "test_helper"
5
5
  class <%= class_name %>Test < ActiveSupport::TestCase
6
6
 
7
7
  def setup
8
- @organization = organizations(:one)
9
- @user = users(:one)
8
+ @organization = organizations(:acme_org)
9
+ @user = users(:john_user)
10
+ @agency = agencies(:marketing_agency)
11
+ <% if singular_table_name == 'organization' -%>
12
+ @<%= singular_table_name %> = <%= table_name %>(:acme_org)
13
+ <% elsif singular_table_name == 'user' -%>
14
+ @<%= singular_table_name %> = <%= table_name %>(:john_user)
15
+ <% elsif singular_table_name == 'agency' -%>
16
+ @<%= singular_table_name %> = <%= table_name %>(:marketing_agency)
17
+ <% else -%>
10
18
  @<%= singular_table_name %> = <%= table_name %>(:one)
19
+ <% end -%>
11
20
  end
12
21
 
13
22
  # === ASSOCIATION TESTS ===
@@ -158,16 +167,25 @@ class <%= class_name %>Test < ActiveSupport::TestCase
158
167
  <% end -%>
159
168
  end
160
169
 
170
+ <%
171
+ # Only generate test when model has large content fields that should be excluded from short facet
172
+ large_content_attributes = attributes.select { |attr|
173
+ attr.name.to_s.match?(/\A(description|content|body|notes|comment|bio|about|summary|text|html|markdown)\z/i)
174
+ }
175
+ -%>
176
+ <% if large_content_attributes.any? -%>
161
177
  test "short facet should not include large content fields" do
162
178
  short_json = @<%= singular_table_name %>.as_json(facet: :short)
163
179
 
164
- # Should not include large content fields in short facet
165
- <% attributes.each do |attribute| -%>
166
- <% if attribute.name.to_s.match?(/\A(description|content|body|notes|comment|bio|about|summary)\z/i) -%>
167
- assert_not_includes short_json.keys, '<%= attribute.name %>', "Short facet should not include <%= attribute.name %>"
168
- <% end -%>
180
+ # Short facets should exclude large content fields for performance and API efficiency
181
+ <% large_content_attributes.each do |attribute| -%>
182
+ assert_not_includes short_json.keys, '<%= attribute.name %>', "Short facet should not include <%= attribute.name %> (large content field)"
169
183
  <% end -%>
184
+
185
+ # Verify short facet still includes essential fields
186
+ assert_includes short_json.keys, 'id', "Short facet should always include ID field"
170
187
  end
188
+ <% end -%>
171
189
 
172
190
  # === BUSINESS LOGIC TESTS ===
173
191
 
@@ -16,7 +16,7 @@
16
16
  #
17
17
  module PropelApi
18
18
  class UnpackGenerator < Rails::Generators::Base
19
- source_root File.expand_path("../../templates", __dir__)
19
+ source_root File.expand_path("../templates", __dir__)
20
20
 
21
21
  desc "Extract PropelApi generator code from gem to lib/generators/propel_api/ for full customization"
22
22
 
@@ -98,7 +98,7 @@ module PropelApi
98
98
  if options[:controllers_only]
99
99
  return %w[controllers]
100
100
  elsif options[:scaffolds_only]
101
- return %w[scaffolds]
101
+ return %w[scaffold]
102
102
  elsif options[:tests_only]
103
103
  return %w[tests]
104
104
  elsif options[:seeds_only]
@@ -108,10 +108,10 @@ module PropelApi
108
108
  elsif options[:generator_only]
109
109
  return %w[generator_logic]
110
110
  elsif options[:templates_only]
111
- return %w[controllers scaffolds tests seeds config]
111
+ return %w[controllers scaffold tests seeds config]
112
112
  else
113
113
  # Default: everything including generator logic
114
- return %w[controllers scaffolds tests seeds config generator_logic]
114
+ return %w[controllers scaffold tests seeds config generator_logic]
115
115
  end
116
116
  end
117
117
 
@@ -127,7 +127,7 @@ module PropelApi
127
127
  case component
128
128
  when 'controllers'
129
129
  copy_controller_templates(destination_path)
130
- when 'scaffolds'
130
+ when 'scaffold'
131
131
  copy_scaffold_templates(destination_path)
132
132
  when 'tests'
133
133
  copy_test_templates(destination_path)
@@ -185,48 +185,66 @@ module PropelApi
185
185
  def copy_generator_logic(destination_path)
186
186
  say "๐Ÿ“‚ Extracting generator logic code...", :blue
187
187
 
188
- # Copy the main generator files with proper Rails registration
188
+ # Map of source files to destination paths (relative to the generator base directory)
189
189
  generator_files = {
190
- 'install_generator.rb' => 'install_generator.rb',
191
- 'propel_api_generator.rb' => 'propel_api_generator.rb',
192
- 'relationship_inferrer.rb' => 'relationship_inferrer.rb'
190
+ 'install/install_generator.rb' => 'install_generator.rb',
191
+ 'controller/controller_generator.rb' => 'controller_generator.rb',
192
+ 'resource/resource_generator.rb' => 'resource_generator.rb',
193
+ 'core/base.rb' => 'core/base.rb',
194
+ 'core/configuration_methods.rb' => 'core/configuration_methods.rb',
195
+ 'core/named_base.rb' => 'core/named_base.rb',
196
+ 'core/path_generation_methods.rb' => 'core/path_generation_methods.rb',
197
+ 'core/relationship_inferrer.rb' => 'core/relationship_inferrer.rb'
193
198
  }
194
199
 
195
200
  copied_count = 0
196
- generator_files.each do |source_name, dest_name|
197
- source_file = File.join(File.dirname(__dir__), source_name)
198
- dest_file = File.join(destination_path, dest_name)
201
+ generator_base_dir = File.dirname(__dir__) # Points to propel_api/lib/generators/propel_api/
202
+
203
+ generator_files.each do |source_path, dest_path|
204
+ source_file = File.join(generator_base_dir, source_path)
205
+ dest_file = File.join(destination_path, dest_path)
199
206
 
200
207
  if File.exist?(source_file)
201
- if source_name == 'install_generator.rb'
208
+ # Ensure destination directory exists
209
+ FileUtils.mkdir_p(File.dirname(dest_file))
210
+
211
+ if source_path == 'install/install_generator.rb'
202
212
  # Copy install generator with proper Rails namespace for host app
203
213
  source_content = File.read(source_file)
204
214
 
205
215
  # Ensure proper module structure for Rails generator registration
206
216
  modified_content = source_content.gsub(
207
- /^class PropelApi::InstallGenerator/,
217
+ /^module PropelApi\s*\n\s*class InstallGenerator/,
208
218
  "module PropelApi\n class InstallGenerator"
209
219
  )
210
220
 
211
- # Add module end if we added module start
212
- if modified_content != source_content
213
- modified_content += "\nend" unless modified_content.end_with?("end\n") || modified_content.end_with?("end")
221
+ # Also handle the case where it's already a class without module wrapper
222
+ if !modified_content.include?("module PropelApi")
223
+ modified_content = modified_content.gsub(
224
+ /^class PropelApi::InstallGenerator/,
225
+ "module PropelApi\n class InstallGenerator"
226
+ )
227
+
228
+ # Add module end if we added module start
229
+ if !modified_content.end_with?("end\n") && !modified_content.end_with?("end")
230
+ modified_content += "\nend"
231
+ end
214
232
  end
215
233
 
216
- FileUtils.mkdir_p(File.dirname(dest_file))
217
234
  File.write(dest_file, modified_content)
218
235
  else
219
236
  # Copy other files normally
220
- FileUtils.cp(source_file, dest_file)
237
+ FileUtils.cp(source_file, dest_file)
221
238
  end
222
239
  copied_count += 1
240
+ say " โœ… #{source_path} โ†’ #{dest_path}", :cyan
223
241
  else
224
- say " โš ๏ธ Generator file not found: #{source_name}", :yellow
242
+ say " โš ๏ธ Generator file not found: #{source_path}", :yellow
225
243
  end
226
244
  end
227
245
 
228
246
  if copied_count > 0
229
- say " โœ… Generator logic code extracted with proper Rails registration (#{copied_count} files)", :green
247
+ say " โœ… Generator logic extracted (#{copied_count} files)", :green
230
248
  else
231
249
  say " โš ๏ธ No generator logic files found", :yellow
232
250
  end
@@ -267,13 +285,15 @@ module PropelApi
267
285
 
268
286
  say "๐Ÿ”ง GENERATOR customization guide:", :bold
269
287
  say " โš™๏ธ Install generator: #{destination_path}/install_generator.rb"
270
- say " ๐Ÿ—๏ธ Main generator: #{destination_path}/propel_api_generator.rb"
271
- say " ๐Ÿ”— Relationship logic: #{destination_path}/relationship_inferrer.rb"
272
- say " ๐ŸŽฎ Controller templates: #{destination_path}/templates/controllers/"
273
- say " ๐Ÿš€ Scaffold templates: #{destination_path}/templates/scaffold/"
274
- say " ๏ฟฝ๏ฟฝ Test templates: #{destination_path}/templates/tests/"
275
- say " ๐ŸŒฑ Seed templates: #{destination_path}/templates/seeds/"
276
- say " โš™๏ธ Config templates: #{destination_path}/templates/config/"
288
+ say " ๐ŸŽฎ Controller generator: #{destination_path}/controller_generator.rb"
289
+ say " ๐Ÿ—๏ธ Resource generator: #{destination_path}/resource_generator.rb"
290
+ say " ๐Ÿ”— Core logic: #{destination_path}/core/"
291
+ say " ๐Ÿ“‹ Templates: #{destination_path}/templates/"
292
+ say " ๐ŸŽฎ Controllers: #{destination_path}/templates/controllers/"
293
+ say " ๐Ÿš€ Scaffold: #{destination_path}/templates/scaffold/"
294
+ say " ๐Ÿงช Tests: #{destination_path}/templates/tests/"
295
+ say " ๐ŸŒฑ Seeds: #{destination_path}/templates/seeds/"
296
+ say " โš™๏ธ Config: #{destination_path}/templates/config/"
277
297
  say ""
278
298
 
279
299
  say "โš ๏ธ Important: You now have a LOCAL GENERATOR, not gem generator:", :yellow
@@ -286,7 +306,8 @@ module PropelApi
286
306
  say "๐Ÿ’ก Test your customized generator:", :blue
287
307
  say " # Your local generator will be used instead of the gem:"
288
308
  say " rails generate propel_api:install"
289
- say " rails generate propel_api User name:string email:string"
309
+ say " rails generate propel_api:controller User"
310
+ say " rails generate propel_api:resource User name:string email:string"
290
311
  say ""
291
312
 
292
313
  say "๐Ÿ”„ To use gem generator again:", :cyan
@@ -297,7 +318,8 @@ module PropelApi
297
318
  say " โ€ข Modify API controller templates for your organization's standards"
298
319
  say " โ€ข Customize scaffold generation logic and output"
299
320
  say " โ€ข Add new serialization adapters beyond propel_facets/graphiti"
300
- say " โ€ข Change relationship inference rules in relationship_inferrer.rb"
321
+ say " โ€ข Change relationship inference rules in core/relationship_inferrer.rb"
322
+ say " โ€ข Modify controller and resource generation logic"
301
323
  say " โ€ข Create company-specific API patterns and conventions"
302
324
  end
303
325
  end
data/lib/propel_api.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module PropelApi
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: propel_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Martin, Rafael Pivato, Chi Putera
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-07-22 00:00:00.000000000 Z
11
+ date: 2025-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails