rails-fields 0.1.0 → 0.2.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 +4 -4
- data/README.md +67 -8
- data/lib/rails_fields/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b999d7f43e0cae7f26122e81c3a7c7106ee1226fedee0621cc4ef548ac76883e
|
4
|
+
data.tar.gz: c1d624fc00ae4e3c595ae06d857758c55088342d8dba908ac73a11c514cf8e47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8e0d1712858632023a259026a9b43634714f898a6a79eacb5602931711b0d4edc488375ae5ed222e6b9c8fb4348f7bbb8eb4645645385d33ee0a28a9758fe76
|
7
|
+
data.tar.gz: 8ddf8b005b637e7004ab598579bc66b76d53a126305598a3c8563e33c5025211ce882e69b19f0b909ff9cbacf6f6c9768fff9cd5d5f999328e375bdc4a20b034
|
data/README.md
CHANGED
@@ -1,11 +1,60 @@
|
|
1
|
+
<p align="center">
|
2
|
+
<a href="https://rails-fields.dev" target="_blank"><img src="./assets/logo.svg" width="300" /></a>
|
3
|
+
</p>
|
4
|
+
|
5
|
+
[](https://badge.fury.io/rb/rails-fields)
|
6
|
+
|
1
7
|
# Rails Fields
|
2
8
|
|
3
|
-
## Summary
|
4
9
|
Enforce field types and attributes for ActiveRecord models in Ruby on Rails applications.
|
5
10
|
|
11
|
+
- 🚀 Automagic ActiveRecord Migrations generations
|
12
|
+
- 🦄 Automatic [GraphqQL types](https://graphql-ruby.org/type_definitions/objects.html) generation
|
13
|
+
- 📝 Explicit declarative model attributes annotation
|
14
|
+
- 💪🏻 Enforcement of fields declaration with real db columns
|
15
|
+
- 📜 Automatic YARD model documentation
|
16
|
+
|
6
17
|
## Description
|
7
18
|
The `rails-fields` gem provides robust field type enforcement for ActiveRecord models in Ruby on Rails applications. It includes utility methods for type validation, logging, and field mappings between GraphQL and ActiveRecord types. Custom error classes provide clear diagnostics for field-related issues, making it easier to maintain consistent data models.
|
8
19
|
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
In your ActiveRecord models:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
class User < ApplicationRecord
|
26
|
+
field :id, :integer
|
27
|
+
field :created_at, :datetime
|
28
|
+
field :updated_at, :datetime
|
29
|
+
|
30
|
+
field :first_name, :string
|
31
|
+
field :country, :string
|
32
|
+
field :welcome, :string
|
33
|
+
|
34
|
+
has_many :todos
|
35
|
+
|
36
|
+
def welcome
|
37
|
+
"Welcome #{first_name}!"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
Autogenerate GraphQL types using `#gql_type` class method:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
module Types
|
46
|
+
class QueryType < Types::BaseObject
|
47
|
+
|
48
|
+
field :users, [User.gql_type], null: true
|
49
|
+
|
50
|
+
def users
|
51
|
+
User.all
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
9
58
|
## Installation
|
10
59
|
|
11
60
|
Add this line to your application's Gemfile:
|
@@ -14,21 +63,31 @@ Add this line to your application's Gemfile:
|
|
14
63
|
gem 'rails-fields'
|
15
64
|
```
|
16
65
|
|
66
|
+
If you want to have graphql types generated for your models, add this line to your application's Gemfile:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
gem 'graphql'
|
70
|
+
```
|
71
|
+
|
72
|
+
*Don't forget to install it `$ ./bin/rails generate graphql:install`*
|
73
|
+
|
17
74
|
And then execute:
|
18
75
|
|
19
76
|
```bash
|
20
77
|
$ bundle install
|
21
78
|
```
|
79
|
+
Update your `ApplicationRecord`:
|
22
80
|
|
23
|
-
|
24
|
-
|
25
|
-
```
|
26
|
-
$ gem install rails-fields
|
27
|
-
```
|
81
|
+
```patch
|
82
|
+
+require 'rails_fields'
|
28
83
|
|
29
|
-
|
84
|
+
class ApplicationRecord < ActiveRecord::Base
|
85
|
+
primary_abstract_class
|
30
86
|
|
31
|
-
|
87
|
+
+ extend RailsFields::ClassMethods
|
88
|
+
+ include RailsFields
|
89
|
+
end
|
90
|
+
```
|
32
91
|
|
33
92
|
## License
|
34
93
|
|
data/lib/rails_fields/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-fields
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gaston Morixe
|
@@ -44,7 +44,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '2.7'
|
48
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
50
50
|
- - ">="
|