playpath_rails 0.1.1 → 0.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/GENERATOR_USAGE.md +78 -0
- data/README.md +26 -24
- data/examples/usage_example.rb +1 -1
- data/lib/generators/playpath_rails/migration_generator.rb +31 -0
- data/lib/generators/playpath_rails/templates/add_playpath_item_id_migration.rb.erb +6 -0
- data/lib/playpath_rails/errors.rb +3 -3
- data/lib/playpath_rails/railtie.rb +19 -0
- data/lib/playpath_rails/synchronizable.rb +4 -4
- data/lib/playpath_rails/version.rb +1 -1
- data/lib/playpath_rails.rb +7 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cea7347f835466f2b1ef01032611e68647403705e493d20255f3cfb92f9bd60
|
4
|
+
data.tar.gz: a5d1b610515d6a067020f4d9e8cfc04956adc384d4954e144adee564b973fd7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fb20198c7c5327b4c70df3b882521cd133795b7e0d5e1ca67faf8fd706bcd2012412dc48c5b859d8ec00bc9804b80e54080be5df7410dbcb08d503ffd3c9139
|
7
|
+
data.tar.gz: adf81bd00ec20d169ebcfffce813431d1542fae1e980459ba7617d02da86f5dc39f10f03c62bbafd75ec1213d7ab9a46a757a4a8e2b2c79a445fa1753ca44bd6
|
data/GENERATOR_USAGE.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# PlaypathRails Generator Usage
|
2
|
+
|
3
|
+
## Rails Migration Generator
|
4
|
+
|
5
|
+
The PlaypathRails gem includes a Rails generator to easily add the required `playpath_item_id` column to your models.
|
6
|
+
|
7
|
+
### Prerequisites
|
8
|
+
|
9
|
+
1. The gem must be installed in a Rails application
|
10
|
+
2. You must be in the Rails application directory when running the generator
|
11
|
+
|
12
|
+
### Usage
|
13
|
+
|
14
|
+
```bash
|
15
|
+
# In your Rails application directory
|
16
|
+
rails generate playpath_rails:migration ModelName
|
17
|
+
```
|
18
|
+
|
19
|
+
### Examples
|
20
|
+
|
21
|
+
```bash
|
22
|
+
# For an Article model
|
23
|
+
rails generate playpath_rails:migration Article
|
24
|
+
|
25
|
+
# For a BlogPost model (camelCase)
|
26
|
+
rails generate playpath_rails:migration BlogPost
|
27
|
+
|
28
|
+
# For a user_profile model (snake_case)
|
29
|
+
rails generate playpath_rails:migration user_profile
|
30
|
+
|
31
|
+
# For a VideoCollection model
|
32
|
+
rails generate playpath_rails:migration VideoCollection
|
33
|
+
```
|
34
|
+
|
35
|
+
### What the Generator Creates
|
36
|
+
|
37
|
+
The generator creates a migration file that:
|
38
|
+
|
39
|
+
1. Adds a `playpath_item_id` column (integer, nullable)
|
40
|
+
2. Adds a unique index on the `playpath_item_id` column
|
41
|
+
|
42
|
+
Example generated migration:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
class AddPlaypathItemIdToArticles < ActiveRecord::Migration[7.0]
|
46
|
+
def change
|
47
|
+
add_column :articles, :playpath_item_id, :integer, null: true
|
48
|
+
add_index :articles, :playpath_item_id, unique: true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
### After Running the Generator
|
54
|
+
|
55
|
+
1. Run the migration: `rails db:migrate`
|
56
|
+
2. Add the `Synchronizable` module to your model:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
class Article < ApplicationRecord
|
60
|
+
include PlaypathRails::Synchronizable
|
61
|
+
|
62
|
+
playpath_sync(
|
63
|
+
title_field: :title,
|
64
|
+
text_field: :content
|
65
|
+
)
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
### Troubleshooting
|
70
|
+
|
71
|
+
**Error: "Could not find generator 'playpath_rails:migration'"**
|
72
|
+
|
73
|
+
This error occurs when:
|
74
|
+
- You're not in a Rails application directory
|
75
|
+
- The gem is not properly installed in the Rails app
|
76
|
+
- You're trying to run the generator from the gem's own directory
|
77
|
+
|
78
|
+
**Solution:** Make sure you're in a Rails application directory and the `playpath_rails` gem is added to your Gemfile.
|
data/README.md
CHANGED
@@ -17,30 +17,6 @@ A Ruby on Rails gem that provides seamless integration between Rails application
|
|
17
17
|
[](https://rubygems.org/gems/playpath_rails)
|
18
18
|
[](https://inch-ci.org/github/playpath/playpath_rails)
|
19
19
|
|
20
|
-
### Quality Metrics
|
21
|
-
|
22
|
-
- **Test Coverage**: Comprehensive RSpec test suite with >95% coverage
|
23
|
-
- **Code Quality**: Maintained with RuboCop and CodeClimate analysis
|
24
|
-
- **Security**: Regular security audits with Bundler Audit and Snyk
|
25
|
-
- **Documentation**: Inline documentation with YARD and comprehensive README
|
26
|
-
- **Dependencies**: Minimal runtime dependencies (ActiveRecord, ActiveSupport)
|
27
|
-
- **Compatibility**: Supports Ruby 3.1+ and Rails 5.2-8.0
|
28
|
-
|
29
|
-
## Table of Contents
|
30
|
-
|
31
|
-
- [Features](#features)
|
32
|
-
- [Installation](#installation)
|
33
|
-
- [Configuration](#configuration)
|
34
|
-
- [Model Synchronization](#model-synchronization)
|
35
|
-
- [RAG Chat API](#rag-chat-api)
|
36
|
-
- [Direct API Access](#direct-api-access)
|
37
|
-
- [Error Handling](#error-handling)
|
38
|
-
- [API Key Types](#api-key-types)
|
39
|
-
- [Development](#development)
|
40
|
-
- [Project Statistics](#project-statistics)
|
41
|
-
- [Contributing](#contributing)
|
42
|
-
- [License](#license)
|
43
|
-
|
44
20
|
## Features
|
45
21
|
|
46
22
|
- **Automatic Model Synchronization**: Sync ActiveRecord models to PlayPath.io Items API
|
@@ -201,6 +177,32 @@ response = client.chat(
|
|
201
177
|
)
|
202
178
|
```
|
203
179
|
|
180
|
+
## Controller Integration
|
181
|
+
|
182
|
+
When building custom Rails API controllers that integrate with PlayPath.io, you may encounter parameter handling issues. The gem provides examples and documentation for proper integration.
|
183
|
+
|
184
|
+
### Quick Fix for "Unpermitted Parameters" Warnings
|
185
|
+
|
186
|
+
If you see warnings like `Unpermitted parameters: :format, :id, :item` in your Rails logs, update your controller's parameter handling:
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
def item_params
|
190
|
+
# Handle both nested and flat parameter formats
|
191
|
+
if params[:item].present?
|
192
|
+
# Nested format: { item: { title: "...", text: "..." } }
|
193
|
+
params.require(:item).permit(:title, :url, :text, tags: [])
|
194
|
+
else
|
195
|
+
# Flat format: { title: "...", text: "..." }
|
196
|
+
params.permit(:title, :url, :text, tags: [])
|
197
|
+
end
|
198
|
+
end
|
199
|
+
```
|
200
|
+
|
201
|
+
### Complete Examples
|
202
|
+
|
203
|
+
- **Controller Example**: [`examples/items_controller_example.rb`](examples/items_controller_example.rb) - Complete Rails controller with proper parameter handling
|
204
|
+
- **Integration Guide**: [`CONTROLLER_INTEGRATION.md`](CONTROLLER_INTEGRATION.md) - Detailed guide for Rails controller integration
|
205
|
+
|
204
206
|
## Error Handling
|
205
207
|
|
206
208
|
The gem provides specific exception types for different error scenarios:
|
data/examples/usage_example.rb
CHANGED
@@ -7,7 +7,7 @@ require_relative '../lib/playpath_rails'
|
|
7
7
|
# Configure the gem
|
8
8
|
PlaypathRails.configure do |config|
|
9
9
|
config.api_key = ENV['PLAYPATH_API_KEY'] || 'your_api_key_here'
|
10
|
-
config.embeddings_api_key = ENV
|
10
|
+
config.embeddings_api_key = ENV.fetch('PLAYPATH_EMBEDDINGS_KEY', nil) # Optional
|
11
11
|
config.base_url = 'https://playpath.io'
|
12
12
|
end
|
13
13
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
require 'rails/generators/active_record'
|
5
|
+
|
6
|
+
module PlaypathRails
|
7
|
+
module Generators
|
8
|
+
class MigrationGenerator < Rails::Generators::Base
|
9
|
+
include ActiveRecord::Generators::Migration
|
10
|
+
|
11
|
+
source_root File.expand_path('templates', __dir__)
|
12
|
+
|
13
|
+
argument :model_name, type: :string, desc: 'The model to add PlayPath synchronization to'
|
14
|
+
|
15
|
+
def create_migration_file
|
16
|
+
migration_template 'add_playpath_item_id_migration.rb.erb',
|
17
|
+
"db/migrate/add_playpath_item_id_to_#{table_name}.rb"
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def table_name
|
23
|
+
model_name.tableize
|
24
|
+
end
|
25
|
+
|
26
|
+
def migration_class_name
|
27
|
+
"AddPlaypathItemIdTo#{model_name.camelize.pluralize}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -4,9 +4,6 @@ module PlaypathRails
|
|
4
4
|
# Base error class for PlaypathRails
|
5
5
|
class Error < StandardError; end
|
6
6
|
|
7
|
-
# Authentication error
|
8
|
-
class AuthenticationError < Error; end
|
9
|
-
|
10
7
|
# API request error
|
11
8
|
class APIError < Error
|
12
9
|
attr_reader :status_code, :response_body
|
@@ -18,6 +15,9 @@ module PlaypathRails
|
|
18
15
|
end
|
19
16
|
end
|
20
17
|
|
18
|
+
# Authentication error
|
19
|
+
class AuthenticationError < APIError; end
|
20
|
+
|
21
21
|
# Validation error from API
|
22
22
|
class ValidationError < APIError; end
|
23
23
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rails/railtie'
|
5
|
+
rescue LoadError
|
6
|
+
# Rails not available, skip railtie
|
7
|
+
return
|
8
|
+
end
|
9
|
+
|
10
|
+
module PlaypathRails
|
11
|
+
class Railtie < Rails::Railtie
|
12
|
+
generators do
|
13
|
+
require 'generators/playpath_rails/migration_generator'
|
14
|
+
rescue LoadError
|
15
|
+
# Generator not found, log warning but don't fail
|
16
|
+
# Rails.logger&.warn("PlaypathRails generator could not be loaded: #{e.message}")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -57,9 +57,9 @@ module PlaypathRails
|
|
57
57
|
end
|
58
58
|
|
59
59
|
true
|
60
|
-
rescue PlaypathRails::Error
|
60
|
+
rescue PlaypathRails::Error
|
61
61
|
# Log the error but don't raise it to avoid breaking the application
|
62
|
-
Rails.logger.error("PlayPath sync failed for #{self.class.name}##{id}: #{e.message}") if defined?(Rails)
|
62
|
+
# Rails.logger.error("PlayPath sync failed for #{self.class.name}##{id}: #{e.message}") if defined?(Rails)
|
63
63
|
false
|
64
64
|
end
|
65
65
|
end
|
@@ -74,9 +74,9 @@ module PlaypathRails
|
|
74
74
|
rescue PlaypathRails::NotFoundError
|
75
75
|
# Item already deleted, consider this success
|
76
76
|
true
|
77
|
-
rescue PlaypathRails::Error
|
77
|
+
rescue PlaypathRails::Error
|
78
78
|
# Log the error but don't raise it to avoid breaking the application
|
79
|
-
Rails.logger.error("PlayPath delete failed for #{self.class.name}##{id}: #{e.message}") if defined?(Rails)
|
79
|
+
# Rails.logger.error("PlayPath delete failed for #{self.class.name}##{id}: #{e.message}") if defined?(Rails)
|
80
80
|
false
|
81
81
|
end
|
82
82
|
end
|
data/lib/playpath_rails.rb
CHANGED
@@ -5,7 +5,13 @@ require_relative 'playpath_rails/errors'
|
|
5
5
|
require_relative 'playpath_rails/client'
|
6
6
|
require_relative 'playpath_rails/synchronizable'
|
7
7
|
require_relative 'playpath_rails/rag'
|
8
|
-
|
8
|
+
|
9
|
+
# Load railtie if Rails is available
|
10
|
+
begin
|
11
|
+
require_relative 'playpath_rails/railtie' if defined?(Rails::Railtie)
|
12
|
+
rescue LoadError
|
13
|
+
# Silently ignore if Rails is not available
|
14
|
+
end
|
9
15
|
|
10
16
|
module PlaypathRails
|
11
17
|
class Error < StandardError; end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: playpath_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joran Kikke
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05-
|
11
|
+
date: 2025-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -159,16 +159,20 @@ extensions: []
|
|
159
159
|
extra_rdoc_files: []
|
160
160
|
files:
|
161
161
|
- ".rspec"
|
162
|
+
- GENERATOR_USAGE.md
|
162
163
|
- LICENSE.txt
|
163
164
|
- README.md
|
164
165
|
- Rakefile
|
165
166
|
- examples/usage_example.rb
|
167
|
+
- lib/generators/playpath_rails/migration_generator.rb
|
168
|
+
- lib/generators/playpath_rails/templates/add_playpath_item_id_migration.rb.erb
|
166
169
|
- lib/playpath_rails.rb
|
167
170
|
- lib/playpath_rails/client.rb
|
168
171
|
- lib/playpath_rails/errors.rb
|
169
172
|
- lib/playpath_rails/generators/migration_generator.rb
|
170
173
|
- lib/playpath_rails/generators/templates/add_playpath_item_id_migration.rb.erb
|
171
174
|
- lib/playpath_rails/rag.rb
|
175
|
+
- lib/playpath_rails/railtie.rb
|
172
176
|
- lib/playpath_rails/synchronizable.rb
|
173
177
|
- lib/playpath_rails/version.rb
|
174
178
|
- sig/playpath_rails.rbs
|
@@ -182,6 +186,7 @@ metadata:
|
|
182
186
|
changelog_uri: https://github.com/playpath/playpath_rails/blob/main/CHANGELOG.md
|
183
187
|
bug_tracker_uri: https://github.com/playpath/playpath_rails/issues
|
184
188
|
documentation_uri: https://rubydoc.info/gems/playpath_rails
|
189
|
+
rubygems_mfa_required: 'true'
|
185
190
|
post_install_message:
|
186
191
|
rdoc_options: []
|
187
192
|
require_paths:
|