croods 0.2.2 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +41 -24
- data/lib/croods/controller/multi_tenancy.rb +1 -1
- data/lib/croods/policy/scope.rb +2 -4
- data/lib/croods/resource/authentication.rb +1 -0
- data/lib/croods/resource/json_schema/definition.rb +23 -13
- 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: 1d384b5ea86ec6b48095b9772afb47414627799144627547722b6322aae58d73
|
4
|
+
data.tar.gz: e58a394c1e3c9bd4b6787c092a09d1bb6582e313151baaedcb9ec0aee8c72735
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 369cc10370be1f7e010d07a858143d929292633752286529b72c7f5558195146a350e5071585adb6a35d6c2edb1bf2a4915ab87f293001fc5669f90a0f46e77c
|
7
|
+
data.tar.gz: ffaec510b409f9cd1d93337aa9939af86d685f4d144cc9e6a06b8fe259a0fabbe1d60fb9628d90ea53ebcf5d313d02d8a3d09b49d548d8aac86abcb56710673b
|
data/README.md
CHANGED
@@ -1,19 +1,38 @@
|
|
1
1
|
[![CircleCI](https://circleci.com/gh/SeasonedSoftware/croods-rails.svg?style=svg)](https://circleci.com/gh/SeasonedSoftware/croods-rails)
|
2
2
|
[![Maintainability](https://api.codeclimate.com/v1/badges/5531c26549b427684578/maintainability)](https://codeclimate.com/github/SeasonedSoftware/croods-rails/maintainability)
|
3
3
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/5531c26549b427684578/test_coverage)](https://codeclimate.com/github/SeasonedSoftware/croods-rails/test_coverage)
|
4
|
+
![](https://ruby-gem-downloads-badge.herokuapp.com/croods?type=total)
|
4
5
|
|
5
6
|
# Croods
|
6
|
-
|
7
|
+
|
8
|
+
A framework for creating CRUDs in Rails APIs. https://croods-rails.netlify.app
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'croods'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
```bash
|
21
|
+
$ bundle
|
22
|
+
```
|
7
23
|
|
8
24
|
## Usage
|
25
|
+
|
9
26
|
### Resource
|
27
|
+
|
10
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/`.
|
11
29
|
|
12
30
|
### Creating a resource
|
31
|
+
|
13
32
|
To add a `Project` resource to your app, start by generating a migration:
|
14
|
-
|
33
|
+
`rails g migration CreateProjects`
|
15
34
|
|
16
|
-
```
|
35
|
+
```ruby
|
17
36
|
# It's crucial to write really solid migrations
|
18
37
|
# croods will use your database schema to build your resources.
|
19
38
|
class CreateProjects < ActiveRecord::Migration[5.2]
|
@@ -25,8 +44,10 @@ class CreateProjects < ActiveRecord::Migration[5.2]
|
|
25
44
|
end
|
26
45
|
end
|
27
46
|
```
|
47
|
+
|
28
48
|
Then create the module and the main file `app/resources/projects/resource.rb`:
|
29
|
-
|
49
|
+
|
50
|
+
```ruby
|
30
51
|
module Projects
|
31
52
|
class Resource < ApplicationResource
|
32
53
|
end
|
@@ -34,12 +55,15 @@ end
|
|
34
55
|
```
|
35
56
|
|
36
57
|
Last step is to initialize your resource in `config/initializers/croods.rb`:
|
58
|
+
|
37
59
|
```ruby
|
38
60
|
Croods.initialize_for(:users, :projects)
|
39
61
|
```
|
40
62
|
|
41
63
|
### Skip actions
|
42
|
-
|
64
|
+
|
65
|
+
Croods creates five basic endpoints for your resource. If you don't want one, you need to skip its action:
|
66
|
+
|
43
67
|
```ruby
|
44
68
|
module Projects
|
45
69
|
class Resource < ApplicationResource
|
@@ -47,8 +71,11 @@ module Projects
|
|
47
71
|
end
|
48
72
|
end
|
49
73
|
```
|
74
|
+
|
50
75
|
### Skip attributes
|
76
|
+
|
51
77
|
By default, every single attribute in your table is exposed in your endpoints. If you don't want this, let croods know:
|
78
|
+
|
52
79
|
```ruby
|
53
80
|
module Projects
|
54
81
|
class Resource < ApplicationResource
|
@@ -58,7 +85,9 @@ end
|
|
58
85
|
```
|
59
86
|
|
60
87
|
### Extend model
|
88
|
+
|
61
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
|
+
|
62
91
|
```ruby
|
63
92
|
module Projects
|
64
93
|
class Resource < ApplicationResource
|
@@ -70,6 +99,7 @@ end
|
|
70
99
|
```
|
71
100
|
|
72
101
|
Protip: you can create a Model module and `extend_model { include Projects::Model }`.
|
102
|
+
|
73
103
|
```ruby
|
74
104
|
module Projects
|
75
105
|
module Model
|
@@ -81,9 +111,12 @@ module Projects
|
|
81
111
|
end
|
82
112
|
end
|
83
113
|
```
|
114
|
+
|
84
115
|
### Authentication
|
116
|
+
|
85
117
|
Croods uses [devise_token_auth](https://github.com/lynndylanhurley/devise_token_auth) under the hood.
|
86
118
|
To customize which devise modules are loaded, you can pass them as arguments to `use_for_authentication!`
|
119
|
+
|
87
120
|
```ruby
|
88
121
|
use_for_authentication!(
|
89
122
|
:database_authenticatable,
|
@@ -93,37 +126,21 @@ use_for_authentication!(
|
|
93
126
|
:validatable
|
94
127
|
)
|
95
128
|
```
|
96
|
-
## Installation
|
97
|
-
Add this line to your application's Gemfile:
|
98
|
-
|
99
|
-
```ruby
|
100
|
-
gem 'croods'
|
101
|
-
```
|
102
|
-
|
103
|
-
And then execute:
|
104
|
-
```bash
|
105
|
-
$ bundle
|
106
|
-
```
|
107
|
-
|
108
|
-
Or install it yourself as:
|
109
|
-
```bash
|
110
|
-
$ gem install croods
|
111
|
-
```
|
112
|
-
|
113
129
|
|
114
130
|
## Contributing
|
115
131
|
|
116
132
|
You can manually check your changes in the dummy Rails app under `/todos`.
|
117
133
|
|
118
134
|
To set it up:
|
135
|
+
|
119
136
|
```
|
120
137
|
cd todos/
|
121
138
|
bin/setup
|
122
139
|
```
|
123
140
|
|
124
141
|
To run specs use:
|
125
|
-
|
142
|
+
`bin/rspec`
|
126
143
|
|
127
144
|
## License
|
128
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
129
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,11 +5,12 @@ 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
|
@@ -18,21 +19,30 @@ module Croods
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def format(attribute)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
case attribute.type
|
23
|
+
when :datetime
|
24
|
+
{ format: 'date-time' }
|
25
|
+
when :date
|
26
|
+
{ format: 'date' }
|
27
|
+
else
|
28
|
+
{}
|
29
|
+
end
|
25
30
|
end
|
26
31
|
|
27
32
|
def types(attribute)
|
28
33
|
types = []
|
29
|
-
|
30
|
-
|
34
|
+
converted_types(attribute.type).each do |converted_type|
|
35
|
+
types << converted_type
|
36
|
+
end
|
37
|
+
null = (
|
38
|
+
attribute.null || attribute.default || attribute.default_function
|
39
|
+
)
|
40
|
+
types << 'null' if null
|
31
41
|
types
|
32
42
|
end
|
33
43
|
|
34
|
-
def
|
35
|
-
TYPES[type] || type.to_s
|
44
|
+
def converted_types(type)
|
45
|
+
TYPES[type] || [type.to_s]
|
36
46
|
end
|
37
47
|
end
|
38
48
|
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.7
|
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
|