propel_api 0.1.4 โ 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +82 -6
- data/lib/generators/propel_api/core/named_base.rb +88 -27
- data/lib/generators/propel_api/core/relationship_inferrer.rb +42 -8
- data/lib/generators/propel_api/templates/config/propel_api.rb.tt +3 -2
- data/lib/generators/propel_api/templates/controllers/api_controller_graphiti.rb +49 -6
- data/lib/generators/propel_api/templates/controllers/api_controller_propel_facets.rb +215 -4
- data/lib/generators/propel_api/templates/scaffold/facet_controller_template.rb.tt +27 -1
- data/lib/generators/propel_api/templates/scaffold/facet_model_template.rb.tt +39 -6
- data/lib/generators/propel_api/templates/seeds/seeds_template.rb.tt +11 -2
- data/lib/generators/propel_api/templates/tests/controller_test_template.rb.tt +279 -36
- data/lib/generators/propel_api/templates/tests/fixtures_template.yml.tt +30 -0
- data/lib/generators/propel_api/templates/tests/integration_test_template.rb.tt +459 -56
- data/lib/generators/propel_api/templates/tests/model_test_template.rb.tt +25 -7
- data/lib/generators/propel_api/unpack/unpack_generator.rb +52 -30
- data/lib/propel_api.rb +1 -1
- metadata +2 -2
@@ -5,9 +5,18 @@ require "test_helper"
|
|
5
5
|
class <%= class_name %>Test < ActiveSupport::TestCase
|
6
6
|
|
7
7
|
def setup
|
8
|
-
@organization = organizations(:
|
9
|
-
@user = users(:
|
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
|
-
#
|
165
|
-
<%
|
166
|
-
|
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("
|
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[
|
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
|
111
|
+
return %w[controllers scaffold tests seeds config]
|
112
112
|
else
|
113
113
|
# Default: everything including generator logic
|
114
|
-
return %w[controllers
|
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 '
|
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
|
-
#
|
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
|
-
'
|
192
|
-
'
|
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
|
-
|
197
|
-
|
198
|
-
|
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
|
-
|
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
|
217
|
+
/^module PropelApi\s*\n\s*class InstallGenerator/,
|
208
218
|
"module PropelApi\n class InstallGenerator"
|
209
219
|
)
|
210
220
|
|
211
|
-
#
|
212
|
-
if modified_content
|
213
|
-
modified_content
|
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
|
-
|
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: #{
|
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
|
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 "
|
271
|
-
say "
|
272
|
-
say "
|
273
|
-
say "
|
274
|
-
say "
|
275
|
-
say "
|
276
|
-
say "
|
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
|
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
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.
|
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-
|
11
|
+
date: 2025-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|