rails-fields 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6148f3e28ada22e83ccdd3d5c9ebe0054a61e61d28af95fcac0052b42e03ef5
4
- data.tar.gz: 9095670043d7f5df6fc540739c2b81951d16b2abc4da9b901ce3f58c7aa71515
3
+ metadata.gz: b999d7f43e0cae7f26122e81c3a7c7106ee1226fedee0621cc4ef548ac76883e
4
+ data.tar.gz: c1d624fc00ae4e3c595ae06d857758c55088342d8dba908ac73a11c514cf8e47
5
5
  SHA512:
6
- metadata.gz: 16125dfe4d17cc6b2c12465bf7182a0e73d0be3e2e79efb33b6feaa8272bc79bed026bc4ff5f35d3cf1bf27ed23c6b17151083827b55f9cf2f09be80b7410782
7
- data.tar.gz: 956dc90b7ee6e99f1a0fb75987d86b1d0f88db2e294d9ff334c77f06da1476cc29fb538d4c2e7748b55f1f7e76b24a8bd574328d5e2a33be22524cb81536d21e
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
+ [![Gem Version](https://badge.fury.io/rb/rails-fields.svg)](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
- Or install it yourself as:
24
-
25
- ```
26
- $ gem install rails-fields
27
- ```
81
+ ```patch
82
+ +require 'rails_fields'
28
83
 
29
- ## Usage
84
+ class ApplicationRecord < ActiveRecord::Base
85
+ primary_abstract_class
30
86
 
31
- (TBD: Add usage examples here)
87
+ + extend RailsFields::ClassMethods
88
+ + include RailsFields
89
+ end
90
+ ```
32
91
 
33
92
  ## License
34
93
 
@@ -1,3 +1,3 @@
1
1
  module RailsFields
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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: 3.2.2
47
+ version: '2.7'
48
48
  required_rubygems_version: !ruby/object:Gem::Requirement
49
49
  requirements:
50
50
  - - ">="