croods 0.2.4 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -13
- data/lib/croods/controller/member.rb +1 -1
- data/lib/croods/controller/multi_tenancy.rb +1 -1
- data/lib/croods/policy/scope.rb +2 -0
- data/lib/croods/resource/json_schema/definition.rb +24 -10
- data/lib/croods/resource/json_schema/links.rb +1 -1
- data/lib/croods/resource/policy.rb +1 -1
- data/lib/croods/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c48ff1f8f4575752544cd790c77fe2c9b3ad1986ce56198d4ff552e701043d3b
|
4
|
+
data.tar.gz: fe604e9c23a6bbb90890d7056d7c835ae33ac6dad8c63db1151d121f60b13c4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bab3bfec3298e879dd7d7f1c10c2d65b9b40e51ba5af0d42937d9c8687daf847ceb1004d561dc0faa7ad45fb86296324c992a48a342e906cd3316710f4dd6416
|
7
|
+
data.tar.gz: ba23108357cd2bd5de0969c605db9262f363a4231a9aa9b70e17a47373e427d5ae3af454577e6e67f6b42cb129ff25d27ba682be02111c2931a299e93d529b52
|
data/README.md
CHANGED
@@ -4,9 +4,11 @@
|
|
4
4
|
![](https://ruby-gem-downloads-badge.herokuapp.com/croods?type=total)
|
5
5
|
|
6
6
|
# Croods
|
7
|
-
|
7
|
+
|
8
|
+
A framework for creating CRUDs in Rails APIs. https://croods-rails.netlify.app
|
8
9
|
|
9
10
|
## Installation
|
11
|
+
|
10
12
|
Add this line to your application's Gemfile:
|
11
13
|
|
12
14
|
```ruby
|
@@ -14,19 +16,23 @@ gem 'croods'
|
|
14
16
|
```
|
15
17
|
|
16
18
|
And then execute:
|
19
|
+
|
17
20
|
```bash
|
18
21
|
$ bundle
|
19
22
|
```
|
20
23
|
|
21
24
|
## Usage
|
25
|
+
|
22
26
|
### Resource
|
27
|
+
|
23
28
|
Resource is a generic abstraction for any object your app needs to represent. Instead of `app/models/` and `app/controllers/`, with croods we have `app/resources/`.
|
24
29
|
|
25
30
|
### Creating a resource
|
31
|
+
|
26
32
|
To add a `Project` resource to your app, start by generating a migration:
|
27
|
-
|
33
|
+
`rails g migration CreateProjects`
|
28
34
|
|
29
|
-
```
|
35
|
+
```ruby
|
30
36
|
# It's crucial to write really solid migrations
|
31
37
|
# croods will use your database schema to build your resources.
|
32
38
|
class CreateProjects < ActiveRecord::Migration[5.2]
|
@@ -38,8 +44,10 @@ class CreateProjects < ActiveRecord::Migration[5.2]
|
|
38
44
|
end
|
39
45
|
end
|
40
46
|
```
|
47
|
+
|
41
48
|
Then create the module and the main file `app/resources/projects/resource.rb`:
|
42
|
-
|
49
|
+
|
50
|
+
```ruby
|
43
51
|
module Projects
|
44
52
|
class Resource < ApplicationResource
|
45
53
|
end
|
@@ -47,12 +55,15 @@ end
|
|
47
55
|
```
|
48
56
|
|
49
57
|
Last step is to initialize your resource in `config/initializers/croods.rb`:
|
58
|
+
|
50
59
|
```ruby
|
51
60
|
Croods.initialize_for(:users, :projects)
|
52
61
|
```
|
53
62
|
|
54
63
|
### Skip actions
|
55
|
-
|
64
|
+
|
65
|
+
Croods creates five basic endpoints for your resource. If you don't want one, you need to skip its action:
|
66
|
+
|
56
67
|
```ruby
|
57
68
|
module Projects
|
58
69
|
class Resource < ApplicationResource
|
@@ -60,8 +71,11 @@ module Projects
|
|
60
71
|
end
|
61
72
|
end
|
62
73
|
```
|
74
|
+
|
63
75
|
### Skip attributes
|
76
|
+
|
64
77
|
By default, every single attribute in your table is exposed in your endpoints. If you don't want this, let croods know:
|
78
|
+
|
65
79
|
```ruby
|
66
80
|
module Projects
|
67
81
|
class Resource < ApplicationResource
|
@@ -71,7 +85,9 @@ end
|
|
71
85
|
```
|
72
86
|
|
73
87
|
### Extend model
|
88
|
+
|
74
89
|
Croods creates a model for your resource. It looks at your database and automatically infers your model's `belongs_to` associations. But if you need to add code to your model just use `extend_model`.
|
90
|
+
|
75
91
|
```ruby
|
76
92
|
module Projects
|
77
93
|
class Resource < ApplicationResource
|
@@ -83,6 +99,7 @@ end
|
|
83
99
|
```
|
84
100
|
|
85
101
|
Protip: you can create a Model module and `extend_model { include Projects::Model }`.
|
102
|
+
|
86
103
|
```ruby
|
87
104
|
module Projects
|
88
105
|
module Model
|
@@ -94,9 +111,12 @@ module Projects
|
|
94
111
|
end
|
95
112
|
end
|
96
113
|
```
|
114
|
+
|
97
115
|
### Authentication
|
116
|
+
|
98
117
|
Croods uses [devise_token_auth](https://github.com/lynndylanhurley/devise_token_auth) under the hood.
|
99
118
|
To customize which devise modules are loaded, you can pass them as arguments to `use_for_authentication!`
|
119
|
+
|
100
120
|
```ruby
|
101
121
|
use_for_authentication!(
|
102
122
|
:database_authenticatable,
|
@@ -110,16 +130,15 @@ use_for_authentication!(
|
|
110
130
|
## Contributing
|
111
131
|
|
112
132
|
You can manually check your changes in the dummy Rails app under `/todos`.
|
133
|
+
Use it to run integration tests since it doesn't have an UI.
|
113
134
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
bin/setup
|
118
|
-
```
|
135
|
+
- Clone the repository
|
136
|
+
- Install bundler `gem install bundler`
|
137
|
+
- Install gems `bin/bundle`
|
119
138
|
|
120
|
-
To run specs use:
|
121
|
-
|
139
|
+
To run both Croods-rails' and the example's specs use:
|
140
|
+
`bin/rspec`
|
122
141
|
|
123
142
|
## License
|
124
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
125
143
|
|
144
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/croods/policy/scope.rb
CHANGED
@@ -38,6 +38,8 @@ module Croods
|
|
38
38
|
associations = scope.reflect_on_all_associations(:belongs_to)
|
39
39
|
|
40
40
|
associations.each do |association|
|
41
|
+
next if association.options[:optional]
|
42
|
+
|
41
43
|
model = association.class_name.constantize
|
42
44
|
expanded_path = path + [association]
|
43
45
|
association_path = reflection_path(model, target, expanded_path)
|
@@ -5,16 +5,25 @@ module Croods
|
|
5
5
|
module JsonSchema
|
6
6
|
module Definition
|
7
7
|
TYPES = {
|
8
|
-
datetime: 'string',
|
9
|
-
date: 'string',
|
10
|
-
text: 'string',
|
11
|
-
json:
|
12
|
-
|
8
|
+
datetime: ['string'],
|
9
|
+
date: ['string'],
|
10
|
+
text: ['string'],
|
11
|
+
json: %w[object array],
|
12
|
+
jsonb: %w[object array],
|
13
|
+
float: ['number']
|
13
14
|
}.freeze
|
14
15
|
|
15
16
|
class << self
|
16
17
|
def schema(attribute)
|
17
|
-
{ type: types(attribute) }
|
18
|
+
{ type: types(attribute) }
|
19
|
+
.merge(format(attribute))
|
20
|
+
.merge(items(attribute))
|
21
|
+
end
|
22
|
+
|
23
|
+
def items(attribute)
|
24
|
+
return {} unless %i[json jsonb].include?(attribute.type)
|
25
|
+
|
26
|
+
{ items: { type: %w[string number object] } }
|
18
27
|
end
|
19
28
|
|
20
29
|
def format(attribute)
|
@@ -30,13 +39,18 @@ module Croods
|
|
30
39
|
|
31
40
|
def types(attribute)
|
32
41
|
types = []
|
33
|
-
|
34
|
-
|
42
|
+
converted_types(attribute.type).each do |converted_type|
|
43
|
+
types << converted_type
|
44
|
+
end
|
45
|
+
null = (
|
46
|
+
attribute.null || attribute.default || attribute.default_function
|
47
|
+
)
|
48
|
+
types << 'null' if null
|
35
49
|
types
|
36
50
|
end
|
37
51
|
|
38
|
-
def
|
39
|
-
TYPES[type] || type.to_s
|
52
|
+
def converted_types(type)
|
53
|
+
TYPES[type] || [type.to_s]
|
40
54
|
end
|
41
55
|
end
|
42
56
|
end
|
data/lib/croods/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: croods
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Weinmann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: committee
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 5.2.4.
|
61
|
+
version: 5.2.4.3
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 5.2.4.
|
68
|
+
version: 5.2.4.3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: schema_associations
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,14 +156,14 @@ dependencies:
|
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 4.0.
|
159
|
+
version: 4.0.1
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 4.0.
|
166
|
+
version: 4.0.1
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: rspec_junit_formatter
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|