croods 0.2.2 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4a3ece0f2c1db0e1f5c9f85c0abd1c5148bae4b47b9f65d7ff4e94e4ab0791d
4
- data.tar.gz: 588d9db567ccbe5ceb229a29605507436690d31e9ea47a3603db9fa9bcb45f1c
3
+ metadata.gz: 1d384b5ea86ec6b48095b9772afb47414627799144627547722b6322aae58d73
4
+ data.tar.gz: e58a394c1e3c9bd4b6787c092a09d1bb6582e313151baaedcb9ec0aee8c72735
5
5
  SHA512:
6
- metadata.gz: 0e0dae287641c6fd8a404c9f22ade7cf1300534c1f5d64c6062f3bc7eb5d796384f419562595e3ef8e433d4b8cc0770d562aa7b1358beeb605653bff9a3d962a
7
- data.tar.gz: 0c339cbf37dc393e8bed3a065bb05551ac74e0965c5d54cbccb134c924edca5ff4ffcf026da0e73e1c7650ce21bb4759b55fafffb6cc4911e0e7affee3be5c79
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
- Short description and motivation.
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
- ```rails g migration CreateProjects```
33
+ `rails g migration CreateProjects`
15
34
 
16
- ``` ruby
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
- ```ruby
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
- 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
+
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
- ```bin/rspec```
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).
@@ -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)
@@ -24,6 +24,7 @@ module Croods
24
24
 
25
25
  request do
26
26
  add_attribute :password, :string, null: false
27
+ skip_attribute :admin
27
28
  end
28
29
  end
29
30
 
@@ -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: '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
@@ -18,21 +19,30 @@ module Croods
18
19
  end
19
20
 
20
21
  def format(attribute)
21
- is_date = attribute.type == :datetime || attribute.type == :date
22
- return {} unless is_date
23
-
24
- { format: 'date-time' }
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
- types << type(attribute.type)
30
- types << 'null' if attribute.null
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 type(type)
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
@@ -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.2'
4
+ VERSION = '0.2.7'
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.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-05-04 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