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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a0a091b4f81e2b96a736954d7aab969b2330e677244c7ac750313a2076da5bc
4
- data.tar.gz: ba0ac8dab04f32472fe82c48fb7a077b6620cc94e8d277e3cd99b9ed665a858b
3
+ metadata.gz: c224eb3b5f12d9dec7be94dfa54f052ecdb147e2db3d4b258bc364423da7f935
4
+ data.tar.gz: 5543378384bb3d38987f93a49cbd2c31759fd098417ee56449987a36a0e649d0
5
5
  SHA512:
6
- metadata.gz: 43c835cbdd0fdb404d09d785b493f3944eab5b452147e46ac11bbae77ce144f95ca46c77449b06327ac98e7fbfc48e1124e959a46ff9f6bdc64d54b75cf9d437
7
- data.tar.gz: 5413ebaf8683673e5418b2aabcffbe24687d8bb1c361ba61bec88d2cc371cb1591fc5519045015ec0871df72ea2643380cbf746d666886ea3bb365013d27fa34
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
- 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,
@@ -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
- ```bin/rspec```
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).
@@ -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
@@ -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 if association_path != path
44
+ return association_path unless association_path.empty?
47
45
  end
48
46
 
49
- path
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: '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.3'
4
+ VERSION = '0.2.8'
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.3
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-05-05 00:00:00.000000000 Z
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.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