jpie 0.4.5 → 1.0.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.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +21 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +35 -110
  5. data/.travis.yml +7 -0
  6. data/Gemfile +21 -0
  7. data/Gemfile.lock +312 -0
  8. data/README.md +2072 -140
  9. data/Rakefile +3 -14
  10. data/bin/console +15 -0
  11. data/bin/setup +8 -0
  12. data/jpie.gemspec +18 -35
  13. data/kiln/app/resources/user_message_resource.rb +2 -0
  14. data/lib/jpie.rb +3 -24
  15. data/lib/json_api/active_storage/deserialization.rb +106 -0
  16. data/lib/json_api/active_storage/detection.rb +74 -0
  17. data/lib/json_api/active_storage/serialization.rb +32 -0
  18. data/lib/json_api/configuration.rb +58 -0
  19. data/lib/json_api/controllers/base_controller.rb +26 -0
  20. data/lib/json_api/controllers/concerns/controller_helpers.rb +223 -0
  21. data/lib/json_api/controllers/concerns/resource_actions.rb +657 -0
  22. data/lib/json_api/controllers/relationships_controller.rb +504 -0
  23. data/lib/json_api/controllers/resources_controller.rb +6 -0
  24. data/lib/json_api/errors/parameter_not_allowed.rb +19 -0
  25. data/lib/json_api/railtie.rb +75 -0
  26. data/lib/json_api/resources/active_storage_blob_resource.rb +11 -0
  27. data/lib/json_api/resources/resource.rb +238 -0
  28. data/lib/json_api/resources/resource_loader.rb +35 -0
  29. data/lib/json_api/routing.rb +72 -0
  30. data/lib/json_api/serialization/deserializer.rb +362 -0
  31. data/lib/json_api/serialization/serializer.rb +320 -0
  32. data/lib/json_api/support/active_storage_support.rb +85 -0
  33. data/lib/json_api/support/collection_query.rb +406 -0
  34. data/lib/json_api/support/instrumentation.rb +42 -0
  35. data/lib/json_api/support/param_helpers.rb +51 -0
  36. data/lib/json_api/support/relationship_guard.rb +16 -0
  37. data/lib/json_api/support/relationship_helpers.rb +74 -0
  38. data/lib/json_api/support/resource_identifier.rb +87 -0
  39. data/lib/json_api/support/responders.rb +100 -0
  40. data/lib/json_api/support/response_helpers.rb +10 -0
  41. data/lib/json_api/support/sort_parsing.rb +21 -0
  42. data/lib/json_api/support/type_conversion.rb +21 -0
  43. data/lib/json_api/testing/test_helper.rb +76 -0
  44. data/lib/json_api/testing.rb +3 -0
  45. data/lib/{jpie → json_api}/version.rb +2 -2
  46. data/lib/json_api.rb +50 -0
  47. data/lib/rubocop/cop/custom/hash_value_omission.rb +53 -0
  48. metadata +50 -169
  49. data/.cursor/rules/dependencies.mdc +0 -19
  50. data/.cursor/rules/examples.mdc +0 -16
  51. data/.cursor/rules/git.mdc +0 -14
  52. data/.cursor/rules/project_structure.mdc +0 -30
  53. data/.cursor/rules/publish_gem.mdc +0 -73
  54. data/.cursor/rules/security.mdc +0 -14
  55. data/.cursor/rules/style.mdc +0 -15
  56. data/.cursor/rules/testing.mdc +0 -16
  57. data/.overcommit.yml +0 -35
  58. data/CHANGELOG.md +0 -164
  59. data/LICENSE.txt +0 -21
  60. data/PUBLISHING.md +0 -111
  61. data/examples/basic_example.md +0 -146
  62. data/examples/including_related_resources.md +0 -491
  63. data/examples/pagination.md +0 -303
  64. data/examples/relationships.md +0 -114
  65. data/examples/resource_attribute_configuration.md +0 -147
  66. data/examples/resource_meta_configuration.md +0 -244
  67. data/examples/rspec_testing.md +0 -130
  68. data/examples/single_table_inheritance.md +0 -160
  69. data/lib/jpie/configuration.rb +0 -12
  70. data/lib/jpie/controller/crud_actions.rb +0 -141
  71. data/lib/jpie/controller/error_handling/handler_setup.rb +0 -124
  72. data/lib/jpie/controller/error_handling/handlers.rb +0 -109
  73. data/lib/jpie/controller/error_handling.rb +0 -23
  74. data/lib/jpie/controller/json_api_validation.rb +0 -193
  75. data/lib/jpie/controller/parameter_parsing.rb +0 -78
  76. data/lib/jpie/controller/related_actions.rb +0 -45
  77. data/lib/jpie/controller/relationship_actions.rb +0 -291
  78. data/lib/jpie/controller/relationship_validation.rb +0 -117
  79. data/lib/jpie/controller/rendering.rb +0 -154
  80. data/lib/jpie/controller.rb +0 -45
  81. data/lib/jpie/deserializer.rb +0 -110
  82. data/lib/jpie/errors.rb +0 -117
  83. data/lib/jpie/generators/resource_generator.rb +0 -116
  84. data/lib/jpie/generators/templates/resource.rb.erb +0 -31
  85. data/lib/jpie/railtie.rb +0 -42
  86. data/lib/jpie/resource/attributable.rb +0 -112
  87. data/lib/jpie/resource/inferrable.rb +0 -43
  88. data/lib/jpie/resource/sortable.rb +0 -93
  89. data/lib/jpie/resource.rb +0 -147
  90. data/lib/jpie/routing.rb +0 -59
  91. data/lib/jpie/serializer.rb +0 -205
@@ -1,30 +0,0 @@
1
- ---
2
- description:
3
- globs:
4
- alwaysApply: false
5
- ---
6
- # Project Information
7
- - Project Name: jpie
8
- - Description: Ruby gem for JSON:API implementation
9
-
10
- # Project Structure
11
-
12
- ## Core Structure
13
- - Keep core functionality in lib/jpie/
14
- - Place tests in spec/jpie/
15
- - Use proper namespacing (JPie module)
16
- - Follow Ruby gem best practices
17
-
18
- ## Protected Files
19
- - Do not update spec/jpie/database.rb unless absolutely necessary
20
- - Do not update spec/jpie/resources.rb unless absolutely necessary
21
-
22
- ## Documentation
23
- - Keep README.md up to date with installation and usage instructions
24
- - Include example usage in documentation
25
-
26
- ## Development Process
27
- - Always read the .aiconfig file
28
- - Always implement code slowly and methodically
29
- - Always test as you go
30
- - Always make sure rubocop passes
@@ -1,73 +0,0 @@
1
- # Publish JPie Gem
2
-
3
- This rule helps publish a new version of the JPie gem.
4
-
5
- ## Requirements
6
- # Publish JPie Gem
7
-
8
- This rule helps publish a new version of the JPie gem.
9
-
10
- ## Requirements
11
-
12
- 1. You must have publishing rights on RubyGems.org
13
- 2. You must have 2FA enabled on RubyGems.org
14
- 3. The version must be updated in `lib/jpie/version.rb`
15
- 4. The changelog must be updated in `CHANGELOG.md`
16
-
17
- ## Steps
18
-
19
- 1. First, ensure the version and changelog are updated and committed
20
- 2. Build the gem
21
- 3. Get OTP code from user
22
- 4. Push to RubyGems with OTP
23
- 5. Update bundle
24
- 6. Tag the release
25
- 7. Push tags
26
-
27
- ## Example Chat
28
-
29
- Human: Publish new version of JPie gem
30
-
31
- Assistant: I will help you publish the gem. First, let me check if the version and changelog are updated.
32
- [Checks version and changelog]
33
-
34
- Now I will build the gem:
35
- > gem build jpie.gemspec
36
-
37
- The gem has been built. To publish it, I will need your OTP code from RubyGems.org.
38
- What is your OTP code?
39
-
40
- Human: 123456
41
-
42
- Assistant: Thanks! I will now push the gem with your OTP:
43
- > gem push jpie-x.y.z.gem --otp 123456
44
-
45
- Great! The gem has been published. Now I will:
46
- 1. Update the bundle
47
- > bundle update jpie
48
-
49
- 2. Tag the release
50
- > git tag -a vx.y.z -m "Version x.y.z"
51
-
52
- 3. Push the tags
53
- > git push origin --tags
54
-
55
- The gem has been successfully published and all post-publish steps are complete!
56
-
57
- ## Automation
58
-
59
- ```bash
60
- # Build the gem
61
- gem build jpie.gemspec
62
-
63
- # Push to RubyGems (OTP will be requested via chat)
64
- gem push jpie-*.gem --otp ${OTP_CODE}
65
-
66
- # Update bundle
67
- bundle update jpie
68
-
69
- # Tag and push
70
- VERSION=$(ruby -r ./lib/jpie/version.rb -e "puts JPie::VERSION")
71
- git tag -a v${VERSION} -m "Version ${VERSION}"
72
- git push origin --tags
73
- ```
@@ -1,14 +0,0 @@
1
- ---
2
- description:
3
- globs:
4
- alwaysApply: false
5
- ---
6
- # Security Guidelines
7
-
8
- - Never commit sensitive data or credentials
9
- - Use environment variables for configuration
10
- - Follow secure coding practices
11
- - Keep dependencies up to date
12
- - Follow Rails 8+ security best practices
13
- - Use Ruby 3.4+ security features
14
- - Implement proper input validation
@@ -1,15 +0,0 @@
1
- ---
2
- description:
3
- globs:
4
- alwaysApply: false
5
- ---
6
- # Style Guidelines
7
-
8
- ## Ruby Style
9
- - Follow Ruby style guide and RuboCop rules defined in .rubocop.yml
10
- - Prefer rubocop autocorrect
11
- - Always pass rubocop before committing to git
12
- - Use `{data:}` rather than `{data: data}`
13
- - Only use code comments when absolutely necessary
14
- - Keep any code comments short and concise
15
- - Don't update .rubocop.yml unless absolutely necessary
@@ -1,16 +0,0 @@
1
- ---
2
- description:
3
- globs:
4
- alwaysApply: false
5
- ---
6
- # Testing Guidelines
7
-
8
- - Write RSpec tests for all new features
9
- - Maintain test coverage for all public methods
10
- - Use meaningful test descriptions
11
- - Follow the existing test structure in spec/
12
- - Test both success and error cases
13
- - Use modern RSpec features and syntax
14
- - Don't reduce test coverage (line, file, branch, or other)
15
- - Only care about coverage reduction when running all specs
16
- - Do not add any functionality for new features to existing tests unless absolutely necessary
data/.overcommit.yml DELETED
@@ -1,35 +0,0 @@
1
- # Use this file to configure the Overcommit hooks you wish to use. This will
2
- # extend the default configuration defined in:
3
- # https://github.com/sds/overcommit/blob/master/config/default.yml
4
-
5
- # Global settings
6
- verify_signatures: false
7
-
8
- PreCommit:
9
- ALL:
10
- problem_on_unmodified_line: ignore
11
- requires_files: true
12
- quiet: false
13
-
14
- # Run RuboCop on Ruby files before commit
15
- RuboCop:
16
- enabled: true
17
- command: ['bundle', 'exec', 'rubocop']
18
- flags: ['--force-exclusion']
19
- on_warn: fail
20
-
21
- # Check for trailing whitespace
22
- TrailingWhitespace:
23
- enabled: true
24
- exclude:
25
- - '**/*.md'
26
-
27
- # Check for merge conflicts
28
- MergeConflicts:
29
- enabled: true
30
-
31
- PrePush:
32
- # Run RSpec tests before push
33
- RSpec:
34
- enabled: true
35
- command: ['bundle', 'exec', 'rspec']
data/CHANGELOG.md DELETED
@@ -1,164 +0,0 @@
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.4.2] - 2025-01-25
11
-
12
- ### Added
13
- - **Pagination Example**: Comprehensive pagination example demonstrating both simple and JSON:API standard pagination formats
14
- - Simple pagination parameters (`page`, `per_page`)
15
- - JSON:API standard pagination format (`page[number]`, `page[size]`)
16
- - Pagination combined with sorting functionality
17
- - Edge cases including last page and empty results
18
- - Complete HTTP request/response examples following project format
19
-
20
- ### Enhanced
21
- - **Documentation**: Improved example coverage with detailed pagination use cases
22
- - **Developer Experience**: Clear examples for implementing pagination in JPie applications
23
-
24
- ## [0.4.1] - 2025-01-25
25
-
26
- ### Fixed
27
- - **Test Suite Stability**: Fixed require statements in spec files that were incorrectly requiring `rails_helper` instead of `spec_helper`
28
- - Fixed `spec/jpie/automatic_crud_spec.rb`
29
- - Fixed `spec/jpie/polymorphic_crud_spec.rb`
30
- - Fixed `spec/jpie/through_associations_crud_spec.rb`
31
- - **Code Quality**: Addressed RuboCop warnings and improved code style compliance
32
- - **Error Handling**: Improved error message consistency for unsupported sort fields and include parameters
33
-
34
- ### Enhanced
35
- - **Test Coverage**: Maintained high test coverage (93.39%) with improved test reliability
36
- - **Documentation**: Updated gem publishing workflow and development guidelines
37
-
38
- ### Technical Details
39
- - All spec files now correctly use `spec_helper` for consistent test environment setup
40
- - Improved gem build process with proper dependency management
41
- - Enhanced RuboCop configuration for better code quality enforcement
42
-
43
- ## [0.4.0] - 2025-01-25
44
-
45
- ### Added
46
- - **Semantic Generator Syntax**: Complete rewrite of resource generator with JSON:API-focused field categorization
47
- - `attribute:field` - Explicit JSON:API attribute definition
48
- - `meta:field` - Explicit JSON:API meta attribute definition
49
- - `has_many:resource` - Shorthand relationship syntax
50
- - `relationship:type:field` - Explicit relationship syntax
51
- - **Improved Developer Experience**: More intuitive and semantic generator approach focused on JSON:API concepts rather than database types
52
-
53
- ### Enhanced
54
- - **Generator Logic**: Refactored generator into cleaner, more maintainable methods with proper separation of concerns
55
- - **Backward Compatibility**: Legacy `field:type` syntax fully preserved - existing usage continues to work unchanged
56
- - **Code Quality**: Fixed all RuboCop violations in generator code with improved method structure
57
- - **Test Coverage**: Comprehensive test suite covering semantic syntax, legacy compatibility, and all feature combinations
58
-
59
- ### Improved
60
- - **Generator Syntax**: Replaced meaningless database types (`name:string`) with semantic JSON:API categorization (`attribute:name`)
61
- - **Documentation**: README completely updated to showcase new semantic approach with comprehensive examples
62
- - **Generator Help**: Updated help text and banners to reflect new semantic syntax
63
-
64
- ### Technical Details
65
- - Generator automatically categorizes fields based on semantic prefixes
66
- - Auto-detection of common meta attributes (`created_at`, `updated_at`, etc.) preserved
67
- - Relationship inference and resource class detection maintained
68
- - All 373 tests pass with 95.97% coverage maintained
69
-
70
- ### Migration Guide
71
- - **New syntax (recommended)**: `rails generate jpie:resource User attribute:name meta:created_at has_many:posts`
72
- - **Legacy syntax (still works)**: `rails generate jpie:resource User name:string created_at:datetime --relationships=has_many:posts`
73
- - No breaking changes - existing generators continue to work as before
74
-
75
- ## [0.3.1] - 2025-01-24
76
-
77
- ### Fixed
78
- - **Gemspec Metadata**: Updated homepage URL to correct GitHub repository (https://github.com/emk-klaay/jpie)
79
- - **Documentation Links**: Fixed source code and changelog URLs in gem metadata
80
-
81
- ## [0.3.0] - 2025-01-24
82
-
83
- ### Added
84
- - **Modern DSL Aliases**: Introduced concise aliases following Rails conventions
85
- - `render_jsonapi` - Single method for rendering both resources and collections
86
- - `resource` - Concise alias for `jsonapi_resource` in controllers
87
- - `meta` and `metas` - Short aliases for `meta_attribute` and `meta_attributes`
88
- - `sortable` - Concise alias for `sortable_by` in resources
89
- - **Method Override Support**: Custom attribute methods can now be defined directly on resource classes
90
- - Support for both public and private method definitions
91
- - Access to `object` and `context` within custom methods
92
- - Method precedence: blocks → options blocks → custom methods → model attributes
93
- - **Enhanced Documentation**: Comprehensive README updates with Key Features section and modern DSL examples
94
-
95
- ### Enhanced
96
- - **Controller DSL**: Simplified rendering with intelligent `render_jsonapi` method that handles both single resources and collections automatically
97
- - **Resource DSL**: More intuitive and concise method names aligned with modern Rails patterns
98
- - **Backward Compatibility**: All original method names preserved via aliases - no breaking changes
99
- - **Code Quality**: 100% test coverage maintained with 363 passing tests and full RuboCop compliance
100
-
101
- ### Improved
102
- - **Developer Experience**: Cleaner, more intuitive API that follows Rails conventions
103
- - **IDE Support**: Better support for custom attribute methods with proper method definitions
104
- - **Testing**: Easier testing of individual custom methods vs block-based approaches
105
- - **Performance**: Method-based attributes avoid block overhead for simple transformations
106
-
107
- ### Technical Details
108
- - Custom methods support both public and private visibility
109
- - Intelligent method detection prevents overriding existing custom implementations
110
- - All render methods consolidated into single polymorphic `render_jsonapi` method
111
- - Full backward compatibility ensures seamless upgrades
112
-
113
- ## [0.2.0] - 2025-01-24
114
-
115
- ### Added
116
- - **Single Table Inheritance (STI) Support**: Comprehensive support for Rails STI models with automatic type inference, resource inheritance, and polymorphic serialization
117
- - **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`
118
- - **Enhanced Test Coverage**: Added comprehensive test suites for STI and meta method functionality with 95.13% line coverage
119
- - **RuboCop Configuration**: Improved RuboCop configuration for test files, reducing offenses from 247 to 0 while maintaining code quality
120
-
121
- ### Enhanced
122
- - **STI Models**: Automatic JSON:API type inference from STI model classes (e.g., `Car` model → `"cars"` type)
123
- - **STI Resources**: Seamless resource inheritance matching model inheritance patterns
124
- - **STI Serialization**: Each STI model serializes with correct type and specific attributes
125
- - **STI Controllers**: Automatic scoping to specific STI types while supporting polymorphic queries
126
- - **Meta Method Features**: Dynamic meta data generation with context access and inheritance support
127
- - **Documentation**: Comprehensive README updates with STI examples and meta method usage
128
-
129
- ### Improved
130
- - **Test Suite**: 343 tests covering all functionality including complex STI scenarios
131
- - **Code Quality**: Zero RuboCop offenses with reasonable configuration for comprehensive test suites
132
- - **Error Handling**: Proper validation for meta method return types with helpful error messages
133
-
134
- ### Technical Details
135
- - STI models automatically infer correct resource classes for polymorphic serialization
136
- - Meta methods can access `object`, `context`, and call `super` for attribute merging
137
- - RuboCop configuration optimized for integration tests without compromising production code standards
138
- - Comprehensive test coverage for edge cases and complex scenarios
139
-
140
- ## [0.1.0] - 2024-01-01
141
-
142
- ### Added
143
- - Initial release with core functionality
144
- - JSON:API compliant serialization and deserialization
145
- - Resource definition with attributes
146
- - Controller integration module
147
- - Rails generator for creating resources
148
- - Comprehensive error handling
149
- - Configuration system for key formats
150
- - Full test suite with RSpec
151
-
152
- ### Features
153
- - `JPie::Resource` - Base class for defining API resources
154
- - `JPie::Serializer` - Converts Ruby objects to JSON:API format
155
- - `JPie::Deserializer` - Converts JSON:API format to Ruby hashes
156
- - `JPie::Controller` - Rails integration module
157
- - `JPie::Configuration` - Gem-wide configuration management
158
- - `JPie::Errors` - JSON:API compliant error classes
159
- - Rails generator: `rails generate jpie:resource`
160
-
161
- ### Dependencies
162
- - Ruby >= 3.4.0
163
- - Rails >= 8.0.0
164
- - ActiveSupport >= 8.0.0
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
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.
data/PUBLISHING.md DELETED
@@ -1,111 +0,0 @@
1
- # Publishing JPie
2
-
3
- This guide explains how to publish new versions of the JPie gem to RubyGems.org.
4
-
5
- ## Prerequisites
6
-
7
- 1. Ensure you have a RubyGems.org account
8
- 2. Ensure you have ownership/publishing rights to the gem
9
- 3. Configure your local credentials:
10
- ```bash
11
- gem signin
12
- ```
13
-
14
- ## Publishing Process
15
-
16
- ### 1. Update Version
17
-
18
- Update the version number in `lib/jpie/version.rb`:
19
-
20
- ```ruby
21
- module JPie
22
- VERSION = "x.y.z" # Use semantic versioning
23
- end
24
- ```
25
-
26
- ### 2. Update Changelog
27
-
28
- Update `CHANGELOG.md` with the changes in the new version:
29
-
30
- ```markdown
31
- ## [x.y.z] - YYYY-MM-DD
32
-
33
- ### Added
34
- - New features
35
-
36
- ### Changed
37
- - Changes in existing functionality
38
-
39
- ### Deprecated
40
- - Soon-to-be removed features
41
-
42
- ### Removed
43
- - Removed features
44
-
45
- ### Fixed
46
- - Bug fixes
47
-
48
- ### Security
49
- - Security fixes
50
- ```
51
-
52
- ### 3. Build the Gem
53
-
54
- ```bash
55
- gem build jpie.gemspec
56
- ```
57
-
58
- This will create a file named `jpie-x.y.z.gem`.
59
-
60
- ### 4. Test the Gem Locally (Optional)
61
-
62
- ```bash
63
- # In a test project
64
- gem install ../path/to/jpie-x.y.z.gem
65
- ```
66
-
67
- ### 5. Push to RubyGems
68
-
69
- ```bash
70
- gem push jpie-x.y.z.gem
71
- ```
72
-
73
- ### 6. Tag the Release
74
-
75
- ```bash
76
- git add lib/jpie/version.rb CHANGELOG.md
77
- git commit -m "Release version x.y.z"
78
- git tag -a vx.y.z -m "Version x.y.z"
79
- git push origin main --tags
80
- ```
81
-
82
- ## Versioning Guidelines
83
-
84
- Follow [Semantic Versioning](https://semver.org/):
85
-
86
- - MAJOR version (x) - incompatible API changes
87
- - MINOR version (y) - add functionality in a backward compatible manner
88
- - PATCH version (z) - backward compatible bug fixes
89
-
90
- ## Troubleshooting
91
-
92
- ### Common Issues
93
-
94
- 1. **Authentication Failed**
95
- ```bash
96
- gem signin # Re-authenticate with RubyGems
97
- ```
98
-
99
- 2. **Gem Name Conflict**
100
- - Ensure the version number is unique
101
- - Check if the gem name is available on RubyGems.org
102
-
103
- 3. **Build Errors**
104
- - Ensure all dependencies are correctly specified in the gemspec
105
- - Verify the gem builds locally before pushing
106
-
107
- ### Getting Help
108
-
109
- - [RubyGems Guides](https://guides.rubygems.org/)
110
- - [Semantic Versioning](https://semver.org/)
111
- - Open an issue in the JPie repository
@@ -1,146 +0,0 @@
1
- # Basic JPie Example
2
-
3
- This example shows the minimal setup to get a JPie resource working with HTTP requests and responses.
4
-
5
- ## Setup
6
-
7
- ### 1. Model (`app/models/user.rb`)
8
- ```ruby
9
- class User < ActiveRecord::Base
10
- validates :name, presence: true
11
- validates :email, presence: true, uniqueness: true
12
- end
13
- ```
14
-
15
- ### 2. Resource (`app/resources/user_resource.rb`)
16
- ```ruby
17
- class UserResource < JPie::Resource
18
- attributes :name, :email
19
- end
20
- ```
21
-
22
- ### 3. Controller (`app/controllers/users_controller.rb`)
23
- ```ruby
24
- class UsersController < ApplicationController
25
- include JPie::Controller
26
- end
27
- ```
28
-
29
- ### 4. Routes (`config/routes.rb`)
30
- ```ruby
31
- Rails.application.routes.draw do
32
- resources :users
33
- end
34
- ```
35
-
36
- ## HTTP Examples
37
-
38
- ### Create User
39
- ```http
40
- POST /users
41
- Content-Type: application/vnd.api+json
42
-
43
- {
44
- "data": {
45
- "type": "users",
46
- "attributes": {
47
- "name": "John Doe",
48
- "email": "john@example.com"
49
- }
50
- }
51
- }
52
-
53
- HTTP/1.1 201 Created
54
- Content-Type: application/vnd.api+json
55
-
56
- {
57
- "data": {
58
- "id": "1",
59
- "type": "users",
60
- "attributes": {
61
- "name": "John Doe",
62
- "email": "john@example.com"
63
- }
64
- }
65
- }
66
- ```
67
-
68
- ### Get All Users
69
- ```http
70
- GET /users
71
- Accept: application/vnd.api+json
72
-
73
- HTTP/1.1 200 OK
74
- Content-Type: application/vnd.api+json
75
-
76
- {
77
- "data": [
78
- {
79
- "id": "1",
80
- "type": "users",
81
- "attributes": {
82
- "name": "John Doe",
83
- "email": "john@example.com"
84
- }
85
- }
86
- ]
87
- }
88
- ```
89
-
90
- ### Get Single User
91
- ```http
92
- GET /users/1
93
- Accept: application/vnd.api+json
94
-
95
- HTTP/1.1 200 OK
96
- Content-Type: application/vnd.api+json
97
-
98
- {
99
- "data": {
100
- "id": "1",
101
- "type": "users",
102
- "attributes": {
103
- "name": "John Doe",
104
- "email": "john@example.com"
105
- }
106
- }
107
- }
108
- ```
109
-
110
- ### Update User
111
- ```http
112
- PATCH /users/1
113
- Content-Type: application/vnd.api+json
114
-
115
- {
116
- "data": {
117
- "id": "1",
118
- "type": "users",
119
- "attributes": {
120
- "name": "Jane Doe"
121
- }
122
- }
123
- }
124
-
125
- HTTP/1.1 200 OK
126
- Content-Type: application/vnd.api+json
127
-
128
- {
129
- "data": {
130
- "id": "1",
131
- "type": "users",
132
- "attributes": {
133
- "name": "Jane Doe",
134
- "email": "john@example.com"
135
- }
136
- }
137
- }
138
- ```
139
-
140
- ### Delete User
141
- ```http
142
- DELETE /users/1
143
- Accept: application/vnd.api+json
144
-
145
- HTTP/1.1 204 No Content
146
- ```