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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59599cc31e9e3b596fe761b140365fb2efcd9c319dc7e60b94c491ad94f9cee3
4
- data.tar.gz: 0b551e14af91d32e9f69c44a0a23a40f235b8929127b28cce5fc96dcd077c385
3
+ metadata.gz: c48ff1f8f4575752544cd790c77fe2c9b3ad1986ce56198d4ff552e701043d3b
4
+ data.tar.gz: fe604e9c23a6bbb90890d7056d7c835ae33ac6dad8c63db1151d121f60b13c4a
5
5
  SHA512:
6
- metadata.gz: 25a199ab073a4fd7156fb97cf4628a6033e49269df3dc83ed34647b2411897f0bba5658a22cbd40d0590938b9d9059739d66021efc39ee62a6eb5b6b6bda10e9
7
- data.tar.gz: 16a87c71799fd7f0cf5dd05ad3a16d9566918ae85074a1e719f9e085b8c25b7761bb09b3a3b3a53ce3c41be0b0adc696ec6c0f76d1329c37700c63785d5e3566
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
- Short description and motivation.
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
- ```rails g migration CreateProjects```
33
+ `rails g migration CreateProjects`
28
34
 
29
- ``` ruby
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
- ```ruby
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
- Croods creates five basic endpoints for your resource. If you don't want one, you need to skip it's action:
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
- To set it up:
115
- ```
116
- cd todos/
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
- ```bin/rspec```
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).
@@ -29,7 +29,7 @@ module Croods
29
29
  .merge(
30
30
  params
31
31
  .require(resource.resource_name)
32
- .permit(resource.request_attributes.keys)
32
+ .permit!
33
33
  )
34
34
  end
35
35
 
@@ -14,7 +14,7 @@ module Croods
14
14
  def tenant_model
15
15
  return unless Croods.multi_tenancy?
16
16
 
17
- Croods.multi_tenancy_by.to_s.titleize.constantize
17
+ Croods.multi_tenancy_by.to_s.camelize.constantize
18
18
  end
19
19
 
20
20
  def header_tenant
@@ -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: 'object',
12
- float: 'number'
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) }.merge(format(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
- types << type(attribute.type)
34
- types << 'null' if attribute.null
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 type(type)
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
@@ -30,7 +30,7 @@ module Croods
30
30
  end
31
31
 
32
32
  def action_module(name)
33
- "Croods::Resource::JsonSchema::Links::#{name.to_s.titleize}"
33
+ "Croods::Resource::JsonSchema::Links::#{name.to_s.camelize}"
34
34
  .constantize
35
35
  end
36
36
  end
@@ -26,7 +26,7 @@ module Croods
26
26
  end
27
27
 
28
28
  def policy_scope_name(action)
29
- "#{model_name}#{action.to_s.titleize}Scope"
29
+ "#{model_name}#{action.to_s.titleize.gsub(/\ /, '')}Scope"
30
30
  end
31
31
 
32
32
  def create_policy!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Croods
4
- VERSION = '0.2.4'
4
+ VERSION = '0.2.9'
5
5
  end
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
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-05-06 00:00:00.000000000 Z
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.2
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.2
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.0.rc1
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.0.rc1
166
+ version: 4.0.1
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: rspec_junit_formatter
169
169
  requirement: !ruby/object:Gem::Requirement