active_buddy 0.1.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/README.md +95 -0
- data/lib/active_buddy/analyzer.rb +56 -0
- data/lib/active_buddy/version.rb +3 -0
- data/lib/active_buddy.rb +5 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dba8d5ca86fb84aaa848f0601afac08f3c7517cbd6d6341669524dd1ac8f53da
|
4
|
+
data.tar.gz: 2beb15ac92a2f1e03a4528c56faba61f1bfbf88adfdbe7d771b8039f89d4df0a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 72d5ea4d1ff607b132cd3260cfc9ec8c89bb2e2313f5a601409d0c39c4bda8210e762b04ab133e0c2c8967ad86baf91c747e6e5809c09d0f28b04e03b26c38bc
|
7
|
+
data.tar.gz: 656bca91541db3c026f6b24e8c70b18647beb886a92a136908d476d6f8ff1d3489c58c7cfb868aecd38c6619725cc783eab6b40177c0b25f94aaae3ae5c364c3
|
data/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# ๐ง ActiveBuddy โ AI-assisted Model Validator for Rails
|
2
|
+
|
3
|
+
**ActiveBuddy** is a professional-grade Ruby gem that intelligently analyzes your ActiveRecord models and suggests validations and associations based on column names, data types, constraints, and naming conventions.
|
4
|
+
|
5
|
+
Perfect for jump-starting new Rails projects with smart, conventional best-practice validations.
|
6
|
+
|
7
|
+
---
|
8
|
+
|
9
|
+
## ๐ฏ Features
|
10
|
+
|
11
|
+
- โ
Smart inference of:
|
12
|
+
- `presence`
|
13
|
+
- `uniqueness`
|
14
|
+
- `length`
|
15
|
+
- `numericality`
|
16
|
+
- `format` validations
|
17
|
+
- ๐งฉ Association recommendations:
|
18
|
+
- `belongs_to`, `has_many`, etc.
|
19
|
+
- ๐ Custom rule engine based on Rails conventions and common model types (User, Payment, Account, etc.)
|
20
|
+
- ๐ฎ Expandable AI-based ruleset planned for future updates
|
21
|
+
|
22
|
+
---
|
23
|
+
|
24
|
+
## ๐ Installation
|
25
|
+
|
26
|
+
Add this line to your application's Gemfile:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
gem 'active_buddy'
|
30
|
+
```
|
31
|
+
|
32
|
+
And then execute:
|
33
|
+
|
34
|
+
```bash
|
35
|
+
bundle install
|
36
|
+
```
|
37
|
+
|
38
|
+
Or install it yourself as a standalone gem:
|
39
|
+
|
40
|
+
```bash
|
41
|
+
gem install active_buddy
|
42
|
+
```
|
43
|
+
|
44
|
+
---
|
45
|
+
|
46
|
+
## โก๏ธ Usage
|
47
|
+
|
48
|
+
In your Rails app or console:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
require 'active_Buddy'
|
52
|
+
|
53
|
+
analyzer = ActiveBuddy::Analyzer.new(User)
|
54
|
+
puts analyzer.suggest_validations
|
55
|
+
puts analyzer.suggest_associations
|
56
|
+
```
|
57
|
+
|
58
|
+
Output:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
validates :email, presence: true
|
62
|
+
validates :email, uniqueness: true
|
63
|
+
validates :email, format: { with: /\A[^@\s]+@[^@\s]+\.[^@\s]+\z/ }
|
64
|
+
validates :name, presence: true
|
65
|
+
belongs_to :account
|
66
|
+
```
|
67
|
+
|
68
|
+
---
|
69
|
+
|
70
|
+
## โ
Supported Patterns
|
71
|
+
|
72
|
+
ActiveBuddy automatically picks up and suggests validations based on:
|
73
|
+
|
74
|
+
| Field Pattern | Suggested Validations |
|
75
|
+
|---------------------|------------------------|
|
76
|
+
| `email` | format, presence, uniqueness |
|
77
|
+
| `phone`, `mobile` | phone format |
|
78
|
+
| `name`, `title` | presence, length |
|
79
|
+
| `password` | length (>= 6) |
|
80
|
+
| `age`, `count`, `qty` | numericality (integer) |
|
81
|
+
| `price`, `amount` | numericality (>= 0) |
|
82
|
+
| `bio`, `description`| length (max 1000) |
|
83
|
+
| `status`, `role`, `type` | presence |
|
84
|
+
|
85
|
+
Also detects and formats associations from ActiveRecord relationships.
|
86
|
+
|
87
|
+
---
|
88
|
+
|
89
|
+
## ๐งช Run Specs
|
90
|
+
|
91
|
+
```bash
|
92
|
+
bundle exec rspec
|
93
|
+
```
|
94
|
+
|
95
|
+
---
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module ActiveBuddy
|
4
|
+
class Analyzer
|
5
|
+
EMAIL_REGEX = /\A[^@\s]+@[^@\s]+\.[^@\s]+\z/
|
6
|
+
PHONE_REGEX = /\A\+?[0-9]{7,15}\z/
|
7
|
+
|
8
|
+
def initialize(model_class)
|
9
|
+
@model = model_class
|
10
|
+
@columns = model_class.columns
|
11
|
+
@reflections = model_class.reflect_on_all_associations
|
12
|
+
end
|
13
|
+
|
14
|
+
def suggest_validations
|
15
|
+
suggestions = []
|
16
|
+
|
17
|
+
@columns.each do |col|
|
18
|
+
name = col.name
|
19
|
+
type = col.type
|
20
|
+
null = col.null
|
21
|
+
|
22
|
+
case name
|
23
|
+
when /email/
|
24
|
+
suggestions << "validates :#{name}, format: { with: #{EMAIL_REGEX.inspect} }"
|
25
|
+
suggestions << "validates :#{name}, presence: true"
|
26
|
+
suggestions << "validates :#{name}, uniqueness: true"
|
27
|
+
when /phone|mobile|contact/
|
28
|
+
suggestions << "validates :#{name}, format: { with: #{PHONE_REGEX.inspect} }"
|
29
|
+
when /password/
|
30
|
+
suggestions << "validates :#{name}, length: { minimum: 6 }"
|
31
|
+
when /name|title/
|
32
|
+
suggestions << "validates :#{name}, presence: true"
|
33
|
+
suggestions << "validates :#{name}, length: { minimum: 2, maximum: 50 }"
|
34
|
+
when /bio|description|summary|notes/
|
35
|
+
suggestions << "validates :#{name}, length: { maximum: 1000 }"
|
36
|
+
when /price|amount|cost|total|balance|fee/
|
37
|
+
suggestions << "validates :#{name}, numericality: { greater_than_or_equal_to: 0 }"
|
38
|
+
when /age|count|quantity|number|size/
|
39
|
+
suggestions << "validates :#{name}, numericality: { only_integer: true, greater_than_or_equal_to: 0 }"
|
40
|
+
when /status|role|type|category/
|
41
|
+
suggestions << "validates :#{name}, presence: true"
|
42
|
+
end
|
43
|
+
|
44
|
+
suggestions << "validates :#{name}, presence: true" if !null && !name.match?(/id|_at$/)
|
45
|
+
end
|
46
|
+
|
47
|
+
suggestions.uniq.sort
|
48
|
+
end
|
49
|
+
|
50
|
+
def suggest_associations
|
51
|
+
@reflections.map do |assoc|
|
52
|
+
"#{assoc.macro} :#{assoc.name}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/active_buddy.rb
ADDED
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_buddy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Your Name
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-04-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Suggests validations and associations for ActiveRecord models
|
42
|
+
email:
|
43
|
+
- your@email.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- README.md
|
49
|
+
- lib/active_buddy.rb
|
50
|
+
- lib/active_buddy/analyzer.rb
|
51
|
+
- lib/active_buddy/version.rb
|
52
|
+
homepage: https://github.com/your_username/active_buddy
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubygems_version: 3.2.3
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: AI-assisted model validator for Rails
|
75
|
+
test_files: []
|