croods 0.2.3 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -7
- data/lib/croods/controller/member.rb +1 -1
- data/lib/croods/controller/multi_tenancy.rb +1 -1
- data/lib/croods/policy/scope.rb +2 -4
- 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: c224eb3b5f12d9dec7be94dfa54f052ecdb147e2db3d4b258bc364423da7f935
|
4
|
+
data.tar.gz: 5543378384bb3d38987f93a49cbd2c31759fd098417ee56449987a36a0e649d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4694b6e09ff03c4110fc5031f2ddf51da0923330a3a58ee9f79b52cd36190a87e32a39787164c1db2b96fb5dc44605d7233df24274bb228e478daab004be697b
|
7
|
+
data.tar.gz: 6d20d856d3abcb11b71c4a511f43d6bbbed01aeaa110879af56c142cffae0ee26ea07473886254d9d9f9eed935118f4c28e93b8322c8ae1b9d80c9d64db87108
|
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,
|
@@ -112,14 +132,15 @@ use_for_authentication!(
|
|
112
132
|
You can manually check your changes in the dummy Rails app under `/todos`.
|
113
133
|
|
114
134
|
To set it up:
|
135
|
+
|
115
136
|
```
|
116
137
|
cd todos/
|
117
138
|
bin/setup
|
118
139
|
```
|
119
140
|
|
120
141
|
To run specs use:
|
121
|
-
|
142
|
+
`bin/rspec`
|
122
143
|
|
123
144
|
## License
|
124
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
125
145
|
|
146
|
+
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
@@ -37,16 +37,14 @@ module Croods
|
|
37
37
|
|
38
38
|
associations = scope.reflect_on_all_associations(:belongs_to)
|
39
39
|
|
40
|
-
return path if associations.empty?
|
41
|
-
|
42
40
|
associations.each do |association|
|
43
41
|
model = association.class_name.constantize
|
44
42
|
expanded_path = path + [association]
|
45
43
|
association_path = reflection_path(model, target, expanded_path)
|
46
|
-
return association_path
|
44
|
+
return association_path unless association_path.empty?
|
47
45
|
end
|
48
46
|
|
49
|
-
|
47
|
+
[]
|
50
48
|
end
|
51
49
|
|
52
50
|
def joins(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.8
|
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-25 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
|