propel_api 0.3.1.3 → 0.3.1.4
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 +17 -1
- data/README.md +60 -7
- data/lib/generators/propel_api/controller/controller_generator.rb +1 -1
- data/lib/generators/propel_api/core/named_base.rb +4 -20
- data/lib/generators/propel_api/resource/resource_generator.rb +1 -1
- data/lib/propel_api.rb +1 -1
- 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: 57d463a766fd115825dccf217caabd982bf849c9aac5a9dfafc7ef11b2a75c04
|
4
|
+
data.tar.gz: 171026f0732372a319fb79946d3c7991293542a7b080bda4559b28427017b741
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0576b9c86f00a1dde3691dfafc7049d6ffcc58c0717c98cab5739b3bee7c354046f711f3eaf061caa11f6c43c29f43008e988c55d706e84dfaa57e8ca0266de4
|
7
|
+
data.tar.gz: fd24e624bd103eb1bdd96c4e85701198b77964716ebf35d267b1d08f75ee7fc8f6016b85c5374eedc111bb7371af8210779874050db707c906290129fdc1d828
|
data/CHANGELOG.md
CHANGED
@@ -10,6 +10,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
10
10
|
### Planned Features
|
11
11
|
- GraphQL adapter support
|
12
12
|
|
13
|
+
## [0.3.1.4] - 2025-09-11
|
14
|
+
|
15
|
+
### 🐛 Critical Bug Fixes
|
16
|
+
- **Polymorphic Parents Parsing Regression**: Fixed `NoMethodError: undefined method 'strip' for Array`
|
17
|
+
- Reverted to original, working `parse_polymorphic_parent_types` implementation
|
18
|
+
- Fixed overcomplicated parsing logic that incorrectly assumed Thor gives Arrays
|
19
|
+
- Thor consistently provides comma-separated String values that need simple `.split(',')` handling
|
20
|
+
- Resolves crash when using `--parents` option with polymorphic generators
|
21
|
+
|
22
|
+
### 📖 Documentation Improvements
|
23
|
+
- **--parents Flag Usage Guide**: Added comprehensive documentation for correct --parents syntax
|
24
|
+
- Fixed misleading error messages that suggested unsupported syntax
|
25
|
+
- Added clear examples of correct vs incorrect --parents usage
|
26
|
+
- Enhanced README with detailed usage guide and common pitfalls
|
27
|
+
- Updated all generator descriptions to show required field_name:Parent1,Parent2 syntax
|
28
|
+
|
13
29
|
## [0.3.1.3] - 2025-09-11
|
14
30
|
|
15
31
|
### 🐛 Bug Fixes
|
@@ -91,7 +107,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
91
107
|
- **Integration Test Templates**: Enhanced error handling and parameter validation in generated integration tests
|
92
108
|
|
93
109
|
### ⚠️ Breaking Changes
|
94
|
-
- **REQUIRED --parents for Polymorphic**: Polymorphic associations now require explicit `--parents Parent1,Parent2` declaration. Auto-discovery fallback has been removed. Generator will block with confirmation if --parents is missing.
|
110
|
+
- **REQUIRED --parents for Polymorphic**: Polymorphic associations now require explicit `--parents field_name:Parent1,Parent2` declaration. Auto-discovery fallback has been removed. Generator will block with confirmation if --parents is missing.
|
95
111
|
|
96
112
|
## [0.3.0] - 2025-01-15
|
97
113
|
|
data/README.md
CHANGED
@@ -55,10 +55,10 @@ rails generate propel_api:resource User name:string email:string role:string
|
|
55
55
|
rails generate propel_api:resource Article title:string content:text user:references category:references
|
56
56
|
|
57
57
|
# 🎉 NEW: Polymorphic associations (v0.3.0) - REQUIRES --parents flag
|
58
|
-
rails generate propel_api:resource Comment content:text commentable:references{polymorphic} --parents Post,Video,Product
|
58
|
+
rails generate propel_api:resource Comment content:text commentable:references{polymorphic} --parents commentable:Post,Video,Product
|
59
59
|
|
60
60
|
# Polymorphic with tenancy
|
61
|
-
rails generate propel_api:resource Review rating:integer comment:text review_parent:polymorphic --parents Product,Agency
|
61
|
+
rails generate propel_api:resource Review rating:integer comment:text review_parent:polymorphic --parents review_parent:Product,Agency
|
62
62
|
|
63
63
|
# With Graphiti adapter
|
64
64
|
rails generate propel_api Product name:string price:decimal --adapter=graphiti
|
@@ -81,10 +81,10 @@ PropelApi now provides comprehensive support for polymorphic associations with a
|
|
81
81
|
|
82
82
|
```bash
|
83
83
|
# Generate a Comment that can belong to Posts, Videos, or Products
|
84
|
-
rails generate propel_api:resource Comment body:text commentable:references{polymorphic} --parents Post,Video,Product
|
84
|
+
rails generate propel_api:resource Comment body:text commentable:references{polymorphic} --parents commentable:Post,Video,Product
|
85
85
|
|
86
|
-
# Generate a Review with full tenancy support
|
87
|
-
rails generate propel_api:resource Review rating:integer comment:text review_parent:references{polymorphic} --parents Product,Agency
|
86
|
+
# Generate a Review with full tenancy support
|
87
|
+
rails generate propel_api:resource Review rating:integer comment:text review_parent:references{polymorphic} --parents review_parent:Product,Agency
|
88
88
|
```
|
89
89
|
|
90
90
|
### Key Features
|
@@ -94,7 +94,8 @@ rails generate propel_api:resource Review rating:integer comment:text review_par
|
|
94
94
|
- No need for complex quote escaping or nested syntax
|
95
95
|
|
96
96
|
#### 🎯 Required Parent Specification
|
97
|
-
- `--parents Parent1,Parent2,Parent3` defines valid parent models (REQUIRED for polymorphic associations)
|
97
|
+
- `--parents field_name:Parent1,Parent2,Parent3` defines valid parent models (REQUIRED for polymorphic associations)
|
98
|
+
- Field name must match the polymorphic association name (e.g., `commentable`, `schedule_parent`)
|
98
99
|
- Automatically generates varied test data using different parent types
|
99
100
|
- Generator will block with confirmation if --parents is not provided
|
100
101
|
|
@@ -139,6 +140,58 @@ class Api::V1::CommentsController < Api::V1::ApiController
|
|
139
140
|
end
|
140
141
|
```
|
141
142
|
|
143
|
+
### --parents Flag Usage Guide
|
144
|
+
|
145
|
+
⚠️ **IMPORTANT**: The `--parents` flag requires specific syntax to work correctly.
|
146
|
+
|
147
|
+
#### ✅ **Correct Syntax:**
|
148
|
+
```bash
|
149
|
+
# Single polymorphic field
|
150
|
+
--parents field_name:Parent1,Parent2,Parent3
|
151
|
+
|
152
|
+
# Real examples:
|
153
|
+
--parents commentable:Post,Photo,Video
|
154
|
+
--parents schedule_parent:User,Room,MeetingLink
|
155
|
+
--parents review_parent:Product,Agency
|
156
|
+
|
157
|
+
# Multiple polymorphic fields
|
158
|
+
--parents commentable:Post,Photo schedule_parent:User,Room
|
159
|
+
```
|
160
|
+
|
161
|
+
#### ❌ **Incorrect Syntax (Will Fail):**
|
162
|
+
```bash
|
163
|
+
# Missing field name (Thor can't parse this)
|
164
|
+
--parents Post,Photo,Video
|
165
|
+
|
166
|
+
# Array brackets (not supported)
|
167
|
+
--parents commentable:[Post,Photo,Video]
|
168
|
+
|
169
|
+
# JSON-like syntax (not supported)
|
170
|
+
--parents "{commentable: [Post,Photo,Video]}"
|
171
|
+
```
|
172
|
+
|
173
|
+
#### 🔑 **Key Rules:**
|
174
|
+
1. **Always include field name**: `field_name:Parent1,Parent2`
|
175
|
+
2. **Field name must match polymorphic association**: If your field is `commentable:polymorphic`, use `--parents commentable:...`
|
176
|
+
3. **Use commas to separate parent types**: `Post,Photo,Video` not `Post Photo Video`
|
177
|
+
4. **Whitespace is automatically cleaned**: `Post, Photo, Video` works fine
|
178
|
+
|
179
|
+
### Complete Usage Examples
|
180
|
+
|
181
|
+
```bash
|
182
|
+
# Standard resource with polymorphic association
|
183
|
+
rails generate propel_api:resource Comment content:text commentable:polymorphic --parents commentable:Post,Photo,Video
|
184
|
+
|
185
|
+
# Multi-tenant polymorphic resource
|
186
|
+
rails generate propel_api:resource Review rating:integer organization:references agency:references review_parent:polymorphic --parents review_parent:Product,Agency,User
|
187
|
+
|
188
|
+
# Schedule system with polymorphic parent
|
189
|
+
rails generate propel_api:resource Schedule name:string start_time:datetime schedule_parent:polymorphic --parents schedule_parent:User,Room,MeetingLink
|
190
|
+
|
191
|
+
# Multiple polymorphic associations in one resource
|
192
|
+
rails generate propel_api:resource Attachment file_name:string attachable:polymorphic owner:polymorphic --parents attachable:Post,Comment,Email owner:User,Agency
|
193
|
+
```
|
194
|
+
|
142
195
|
### Breaking Changes from v0.2.x
|
143
196
|
|
144
197
|
⚠️ **Migration Required**: The polymorphic syntax and test generation has been completely rewritten for better reliability and Rails compatibility.
|
@@ -148,7 +201,7 @@ end
|
|
148
201
|
|
149
202
|
The new approach provides:
|
150
203
|
- More reliable test generation
|
151
|
-
- Better fixture management
|
204
|
+
- Better fixture management
|
152
205
|
- Cleaner, more maintainable code
|
153
206
|
- Full Rails compatibility
|
154
207
|
|
@@ -52,7 +52,7 @@ module PropelApi
|
|
52
52
|
class_option :parents,
|
53
53
|
type: :hash,
|
54
54
|
default: {},
|
55
|
-
desc: "Specify parent types for polymorphic associations (e.g., --parents commentable:Post,Photo,Video)"
|
55
|
+
desc: "Specify parent types for polymorphic associations. REQUIRED syntax: --parents model_polymorphic_name:Parent1,Parent2,Parent3 (e.g., --parents commentable:Post,Photo,Video)"
|
56
56
|
|
57
57
|
def validate_model_exists
|
58
58
|
# Ensure attributes are parsed before validation
|
@@ -549,7 +549,7 @@ module PropelApi
|
|
549
549
|
# Fallback to User if no parent types specified and no models auto-discovered
|
550
550
|
if parent_types.empty?
|
551
551
|
say "Warning: No parent types specified for polymorphic association '#{attr.name}' and no models found to auto-discover.", :yellow
|
552
|
-
say "Falling back to 'User' as parent type. Use --parents
|
552
|
+
say "Falling back to 'User' as parent type. Use --parents #{attr.name}:Parent1,Parent2,Parent3 to specify parent types.", :yellow
|
553
553
|
parent_types = ['User']
|
554
554
|
end
|
555
555
|
|
@@ -599,28 +599,12 @@ module PropelApi
|
|
599
599
|
private
|
600
600
|
|
601
601
|
def parse_polymorphic_parent_types
|
602
|
-
return {} unless defined?(options) && options[:parents]
|
602
|
+
return {} unless defined?(options) && options[:parents]
|
603
603
|
|
604
|
-
# With the simplified syntax, we apply the same parent types to all polymorphic associations
|
605
|
-
parent_types = options[:parents].map(&:strip).map(&:camelize)
|
606
|
-
|
607
|
-
# Debug: Show what we parsed
|
608
|
-
say "Debug: Parsed parent types from --parents: #{parent_types.inspect}", :cyan if parent_types.any?
|
609
|
-
|
610
|
-
# Find all polymorphic associations and apply the same parent types to each
|
611
604
|
parsed_types = {}
|
612
|
-
|
613
|
-
|
614
|
-
if attrs && !attrs.empty?
|
615
|
-
polymorphic_attrs = attrs.select { |attr| attr.type == :references && attr.respond_to?(:polymorphic?) && attr.polymorphic? }
|
616
|
-
polymorphic_attrs.each do |attr|
|
617
|
-
parsed_types[attr.name.to_s] = parent_types
|
618
|
-
say "Debug: Applied parent types #{parent_types.inspect} to polymorphic field '#{attr.name}'", :cyan
|
619
|
-
end
|
620
|
-
else
|
621
|
-
say "Debug: No attributes found when parsing polymorphic parent types", :yellow
|
605
|
+
options[:parents].each do |field_name, parent_list|
|
606
|
+
parsed_types[field_name] = parent_list.split(',').map(&:strip).map(&:camelize)
|
622
607
|
end
|
623
|
-
|
624
608
|
parsed_types
|
625
609
|
end
|
626
610
|
|
@@ -74,7 +74,7 @@ module PropelApi
|
|
74
74
|
class_option :parents,
|
75
75
|
type: :hash,
|
76
76
|
default: {},
|
77
|
-
desc: "Specify parent types for polymorphic associations (e.g., --parents commentable:Post,Photo,Video)"
|
77
|
+
desc: "Specify parent types for polymorphic associations. REQUIRED syntax: --parents field_name:Parent1,Parent2,Parent3 (e.g., --parents commentable:Post,Photo,Video)"
|
78
78
|
|
79
79
|
def create_migration
|
80
80
|
initialize_propel_api_settings
|
data/lib/propel_api.rb
CHANGED