jpie 0.3.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 +7 -0
- data/.aiconfig +65 -0
- data/.rubocop.yml +140 -0
- data/CHANGELOG.md +93 -0
- data/LICENSE.txt +21 -0
- data/README.md +1032 -0
- data/Rakefile +19 -0
- data/jpie.gemspec +48 -0
- data/lib/jpie/configuration.rb +12 -0
- data/lib/jpie/controller/crud_actions.rb +110 -0
- data/lib/jpie/controller/error_handling.rb +41 -0
- data/lib/jpie/controller/parameter_parsing.rb +35 -0
- data/lib/jpie/controller/rendering.rb +60 -0
- data/lib/jpie/controller.rb +18 -0
- data/lib/jpie/deserializer.rb +110 -0
- data/lib/jpie/errors.rb +70 -0
- data/lib/jpie/generators/resource_generator.rb +39 -0
- data/lib/jpie/generators/templates/resource.rb.erb +12 -0
- data/lib/jpie/railtie.rb +36 -0
- data/lib/jpie/resource/attributable.rb +98 -0
- data/lib/jpie/resource/inferrable.rb +43 -0
- data/lib/jpie/resource/sortable.rb +93 -0
- data/lib/jpie/resource.rb +107 -0
- data/lib/jpie/serializer.rb +205 -0
- data/lib/jpie/version.rb +5 -0
- data/lib/jpie.rb +26 -0
- metadata +223 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8f594e2f3e5123f2663c45f616ecd71ecfd3536dfa18584a717fc1dd009725ea
|
4
|
+
data.tar.gz: 1f58bb161f508a317eba59075067f8b11ee8d0c9c2f06bdbf1db97ec954c436b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f1a6e30858f39970bcd27e6b32fef2bdcf8b988fe9feb1cf69d5edb146ccebbe4bf0f01f68b75129916678f4431ba02e95b126086cd08f7966e2f4974778f8e7
|
7
|
+
data.tar.gz: bfc7c45df14267309e08f05d1ec66134d5a64ba19da1492eb04f04ae6cce19455ba4ca3d7c53aa209b723d7208d42f8df38a65a139e69520a570b37e93b4f634
|
data/.aiconfig
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# AI Assistant Configuration
|
2
|
+
# This file contains rules and guidelines for AI assistants working on the jpie project
|
3
|
+
|
4
|
+
# Follow these code style guidelines
|
5
|
+
- Follow Ruby style guide and RuboCop rules defined in .rubocop.yml
|
6
|
+
- Prefer rubocop autocorrect
|
7
|
+
- Always pass rubocop before committing to git
|
8
|
+
|
9
|
+
# Documentation requirements
|
10
|
+
- Keep README.md up to date with installation and usage instructions
|
11
|
+
- Include example usage in documentation
|
12
|
+
|
13
|
+
# Testing guidelines
|
14
|
+
- Write RSpec tests for all new features
|
15
|
+
- Maintain test coverage for all public methods
|
16
|
+
- Use meaningful test descriptions
|
17
|
+
- Follow the existing test structure in spec/
|
18
|
+
- Test both success and error cases
|
19
|
+
- Use modern RSpec features and syntax
|
20
|
+
- Don't reduce test coverage (line, file, branch, or other)
|
21
|
+
|
22
|
+
# Git commit guidelines
|
23
|
+
- Write clear, descriptive commit messages
|
24
|
+
- Keep commits focused and atomic
|
25
|
+
- Run tests before committing
|
26
|
+
- Update documentation in the same commit as code changes
|
27
|
+
- Ignore spec/examples.txt and other files listed in .gitignore
|
28
|
+
- Include Ruby/Rails version requirements in relevant commits
|
29
|
+
- Update tests in the same commit as code changes
|
30
|
+
|
31
|
+
# Maintain the following project structure
|
32
|
+
- Keep core functionality in lib/jpie/
|
33
|
+
- Place tests in spec/jpie/
|
34
|
+
- Use proper namespacing (JPie module)
|
35
|
+
- Follow Ruby gem best practices
|
36
|
+
|
37
|
+
# Dependency management
|
38
|
+
- Keep dependencies minimal and justified
|
39
|
+
- Document new dependencies in README.md
|
40
|
+
- Keep development dependencies in Gemfile
|
41
|
+
- Ensure compatibility with Ruby 3.4+
|
42
|
+
- Only support Rails 8+ features
|
43
|
+
- Use modern gem versions
|
44
|
+
|
45
|
+
# Security guidelines
|
46
|
+
- Never commit sensitive data or credentials
|
47
|
+
- Use environment variables for configuration
|
48
|
+
- Follow secure coding practices
|
49
|
+
- Keep dependencies up to date
|
50
|
+
- Follow Rails 8+ security best practices
|
51
|
+
- Use Ruby 3.4+ security features
|
52
|
+
- Implement proper input validation
|
53
|
+
|
54
|
+
# Compatibility requirements
|
55
|
+
- Maintain Ruby 3.4+ compatibility
|
56
|
+
- Support Rails 8+ integration
|
57
|
+
- Follow JSON:API specification strictly
|
58
|
+
|
59
|
+
# Styleguide
|
60
|
+
- Use `{data:}` rather than `{data: data}`
|
61
|
+
|
62
|
+
# When implementing new features or refactoring
|
63
|
+
- Always read the .aiconfig file
|
64
|
+
- Always implement code slowly and methodically
|
65
|
+
- Always test as you go
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require:
|
4
|
+
- rubocop-performance
|
5
|
+
- rubocop-rails
|
6
|
+
- rubocop-rspec
|
7
|
+
|
8
|
+
AllCops:
|
9
|
+
TargetRubyVersion: 3.4
|
10
|
+
TargetRailsVersion: 8.0
|
11
|
+
NewCops: enable
|
12
|
+
Exclude:
|
13
|
+
- 'vendor/**/*'
|
14
|
+
- 'bin/**/*'
|
15
|
+
- 'db/schema.rb'
|
16
|
+
- 'tmp/**/*'
|
17
|
+
- 'spec/examples.txt'
|
18
|
+
|
19
|
+
Layout/LineLength:
|
20
|
+
Max: 120
|
21
|
+
AllowedPatterns: ['\A\s*#']
|
22
|
+
|
23
|
+
Style/Documentation:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Style/StringLiterals:
|
27
|
+
EnforcedStyle: single_quotes
|
28
|
+
|
29
|
+
Style/StringLiteralsInInterpolation:
|
30
|
+
EnforcedStyle: single_quotes
|
31
|
+
|
32
|
+
# Naming cops
|
33
|
+
Naming/PredicateName:
|
34
|
+
AllowedMethods:
|
35
|
+
- has_many # DSL method for defining relationships
|
36
|
+
- has_one # DSL method for defining relationships
|
37
|
+
|
38
|
+
Metrics/ClassLength:
|
39
|
+
Max: 150
|
40
|
+
|
41
|
+
Metrics/ModuleLength:
|
42
|
+
Max: 150
|
43
|
+
|
44
|
+
Metrics/MethodLength:
|
45
|
+
Max: 20
|
46
|
+
|
47
|
+
Metrics/BlockLength:
|
48
|
+
Exclude:
|
49
|
+
- 'spec/**/*'
|
50
|
+
- '*.gemspec'
|
51
|
+
- 'lib/jpie/resource/**/*' # Resource modules have large class_methods blocks for DSL methods
|
52
|
+
- 'lib/jpie/controller/**/*' # Controller modules have large class_methods blocks for DSL methods
|
53
|
+
|
54
|
+
# Rails cops that don't apply to our gem
|
55
|
+
Rails/TimeZone:
|
56
|
+
Enabled: false
|
57
|
+
|
58
|
+
Rails/ApplicationRecord:
|
59
|
+
Enabled: false
|
60
|
+
|
61
|
+
# Gemspec cops that are acceptable for gems
|
62
|
+
Gemspec/DevelopmentDependencies:
|
63
|
+
Enabled: false
|
64
|
+
|
65
|
+
# Capybara cops that are causing issues (rubocop bug)
|
66
|
+
Capybara/RSpec/PredicateMatcher:
|
67
|
+
Enabled: false
|
68
|
+
|
69
|
+
# RSpec cops that are acceptable for our test style
|
70
|
+
RSpec/ExampleLength:
|
71
|
+
Max: 30
|
72
|
+
|
73
|
+
RSpec/MultipleExpectations:
|
74
|
+
Max: 8 # Allow more expectations for complex integration tests
|
75
|
+
|
76
|
+
RSpec/MultipleMemoizedHelpers:
|
77
|
+
Max: 20 # Allow more helpers for complex test scenarios
|
78
|
+
|
79
|
+
RSpec/NestedGroups:
|
80
|
+
Max: 4
|
81
|
+
|
82
|
+
RSpec/DescribeClass:
|
83
|
+
Exclude:
|
84
|
+
- 'spec/**/*_integration_spec.rb'
|
85
|
+
- 'spec/**/*_spec.rb' # Allow integration and feature tests without class specification
|
86
|
+
|
87
|
+
RSpec/ContextWording:
|
88
|
+
Enabled: false # Allow flexible context descriptions for better readability
|
89
|
+
|
90
|
+
RSpec/IndexedLet:
|
91
|
+
Enabled: false # Allow indexed let statements for test data setup
|
92
|
+
|
93
|
+
RSpec/LetSetup:
|
94
|
+
Enabled: false # Allow let! for test data setup
|
95
|
+
|
96
|
+
RSpec/StubbedMock:
|
97
|
+
Enabled: false # Allow expect().to receive for test clarity
|
98
|
+
|
99
|
+
RSpec/IteratedExpectation:
|
100
|
+
Enabled: false # Allow iteration over arrays in tests
|
101
|
+
|
102
|
+
RSpec/InstanceVariable:
|
103
|
+
Enabled: false # Allow instance variables in tests for setup
|
104
|
+
|
105
|
+
RSpec/FilePath:
|
106
|
+
Enabled: false
|
107
|
+
|
108
|
+
RSpec/SpecFilePathFormat:
|
109
|
+
Enabled: false
|
110
|
+
|
111
|
+
RSpec/MultipleDescribes:
|
112
|
+
Enabled: false
|
113
|
+
|
114
|
+
RSpec/LeakyConstantDeclaration:
|
115
|
+
Enabled: false
|
116
|
+
|
117
|
+
RSpec/VerifiedDoubles:
|
118
|
+
Enabled: false
|
119
|
+
|
120
|
+
RSpec/MessageSpies:
|
121
|
+
Enabled: false
|
122
|
+
|
123
|
+
# Style cops that are acceptable for test code
|
124
|
+
Style/OpenStructUse:
|
125
|
+
Exclude:
|
126
|
+
- 'spec/**/*'
|
127
|
+
|
128
|
+
# Lint cops that are acceptable for test initialization methods
|
129
|
+
Lint/MissingSuper:
|
130
|
+
Exclude:
|
131
|
+
- 'spec/**/*'
|
132
|
+
|
133
|
+
Lint/ConstantDefinitionInBlock:
|
134
|
+
Exclude:
|
135
|
+
- 'spec/**/*'
|
136
|
+
|
137
|
+
# Rails cops that we can ignore in test support files
|
138
|
+
Rails/SkipsModelValidations:
|
139
|
+
Exclude:
|
140
|
+
- 'spec/**/*'
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [Unreleased]
|
9
|
+
|
10
|
+
## [0.3.0] - 2025-01-24
|
11
|
+
|
12
|
+
### Added
|
13
|
+
- **Modern DSL Aliases**: Introduced concise aliases following Rails conventions
|
14
|
+
- `render_jsonapi` - Single method for rendering both resources and collections
|
15
|
+
- `resource` - Concise alias for `jsonapi_resource` in controllers
|
16
|
+
- `meta` and `metas` - Short aliases for `meta_attribute` and `meta_attributes`
|
17
|
+
- `sortable` - Concise alias for `sortable_by` in resources
|
18
|
+
- **Method Override Support**: Custom attribute methods can now be defined directly on resource classes
|
19
|
+
- Support for both public and private method definitions
|
20
|
+
- Access to `object` and `context` within custom methods
|
21
|
+
- Method precedence: blocks → options blocks → custom methods → model attributes
|
22
|
+
- **Enhanced Documentation**: Comprehensive README updates with Key Features section and modern DSL examples
|
23
|
+
|
24
|
+
### Enhanced
|
25
|
+
- **Controller DSL**: Simplified rendering with intelligent `render_jsonapi` method that handles both single resources and collections automatically
|
26
|
+
- **Resource DSL**: More intuitive and concise method names aligned with modern Rails patterns
|
27
|
+
- **Backward Compatibility**: All original method names preserved via aliases - no breaking changes
|
28
|
+
- **Code Quality**: 100% test coverage maintained with 363 passing tests and full RuboCop compliance
|
29
|
+
|
30
|
+
### Improved
|
31
|
+
- **Developer Experience**: Cleaner, more intuitive API that follows Rails conventions
|
32
|
+
- **IDE Support**: Better support for custom attribute methods with proper method definitions
|
33
|
+
- **Testing**: Easier testing of individual custom methods vs block-based approaches
|
34
|
+
- **Performance**: Method-based attributes avoid block overhead for simple transformations
|
35
|
+
|
36
|
+
### Technical Details
|
37
|
+
- Custom methods support both public and private visibility
|
38
|
+
- Intelligent method detection prevents overriding existing custom implementations
|
39
|
+
- All render methods consolidated into single polymorphic `render_jsonapi` method
|
40
|
+
- Full backward compatibility ensures seamless upgrades
|
41
|
+
|
42
|
+
## [0.2.0] - 2025-01-24
|
43
|
+
|
44
|
+
### Added
|
45
|
+
- **Single Table Inheritance (STI) Support**: Comprehensive support for Rails STI models with automatic type inference, resource inheritance, and polymorphic serialization
|
46
|
+
- **Custom Meta Method**: Resources can now define a `meta` method to provide dynamic meta data alongside the existing `meta_attributes` macro, with access to `object`, `context`, and ability to call `super`
|
47
|
+
- **Enhanced Test Coverage**: Added comprehensive test suites for STI and meta method functionality with 95.13% line coverage
|
48
|
+
- **RuboCop Configuration**: Improved RuboCop configuration for test files, reducing offenses from 247 to 0 while maintaining code quality
|
49
|
+
|
50
|
+
### Enhanced
|
51
|
+
- **STI Models**: Automatic JSON:API type inference from STI model classes (e.g., `Car` model → `"cars"` type)
|
52
|
+
- **STI Resources**: Seamless resource inheritance matching model inheritance patterns
|
53
|
+
- **STI Serialization**: Each STI model serializes with correct type and specific attributes
|
54
|
+
- **STI Controllers**: Automatic scoping to specific STI types while supporting polymorphic queries
|
55
|
+
- **Meta Method Features**: Dynamic meta data generation with context access and inheritance support
|
56
|
+
- **Documentation**: Comprehensive README updates with STI examples and meta method usage
|
57
|
+
|
58
|
+
### Improved
|
59
|
+
- **Test Suite**: 343 tests covering all functionality including complex STI scenarios
|
60
|
+
- **Code Quality**: Zero RuboCop offenses with reasonable configuration for comprehensive test suites
|
61
|
+
- **Error Handling**: Proper validation for meta method return types with helpful error messages
|
62
|
+
|
63
|
+
### Technical Details
|
64
|
+
- STI models automatically infer correct resource classes for polymorphic serialization
|
65
|
+
- Meta methods can access `object`, `context`, and call `super` for attribute merging
|
66
|
+
- RuboCop configuration optimized for integration tests without compromising production code standards
|
67
|
+
- Comprehensive test coverage for edge cases and complex scenarios
|
68
|
+
|
69
|
+
## [0.1.0] - 2024-01-01
|
70
|
+
|
71
|
+
### Added
|
72
|
+
- Initial release with core functionality
|
73
|
+
- JSON:API compliant serialization and deserialization
|
74
|
+
- Resource definition with attributes
|
75
|
+
- Controller integration module
|
76
|
+
- Rails generator for creating resources
|
77
|
+
- Comprehensive error handling
|
78
|
+
- Configuration system for key formats
|
79
|
+
- Full test suite with RSpec
|
80
|
+
|
81
|
+
### Features
|
82
|
+
- `JPie::Resource` - Base class for defining API resources
|
83
|
+
- `JPie::Serializer` - Converts Ruby objects to JSON:API format
|
84
|
+
- `JPie::Deserializer` - Converts JSON:API format to Ruby hashes
|
85
|
+
- `JPie::Controller` - Rails integration module
|
86
|
+
- `JPie::Configuration` - Gem-wide configuration management
|
87
|
+
- `JPie::Errors` - JSON:API compliant error classes
|
88
|
+
- Rails generator: `rails generate jpie:resource`
|
89
|
+
|
90
|
+
### Dependencies
|
91
|
+
- Ruby >= 3.4.0
|
92
|
+
- Rails >= 8.0.0
|
93
|
+
- ActiveSupport >= 8.0.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Emil Kampp
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|