croods 0.2.1 → 0.2.6

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: 650a72062d9460d74e7efa322db3df3ec47e972ed475674aac75f7b05daa6fe9
4
- data.tar.gz: ecdca75bcdadcb9cf07fa97ce5cd5495fca20d29a47a6b40d5c18613aa005d54
3
+ metadata.gz: da70e6c23805cc55c8a4d7db9e97adc567a4bcd436fb0296600238e9826955c7
4
+ data.tar.gz: 43415c1a16fdefeaa51fc4dd5cf4b7c93121c8f16fbefefee5966af4ac714766
5
5
  SHA512:
6
- metadata.gz: 927e71afb7f0cc1f3141dcf8e1c2616b9090008d3aa80c2da54d83a8a15ff554d67af02d73c6958680c8a97a9b0122593e48288ea4960943b7a2c74817cf2c38
7
- data.tar.gz: f63bb7198a6268b4e3ee192689e094a7e58d3476d0b4206569a5a6ae14f713fce1f2f45ba9262594a970d347224a8e587f281b1ef4cd17d8563f5bf6f5a93757
6
+ metadata.gz: 3ea56e2741d2559944657daeeb73ef18cee25a381da09e50fe5f430cc4ae008015ec241e60cf96b7c931cc998fce5333fdd7f13e9e978d6f4ca890ece42554b7
7
+ data.tar.gz: da63eb7581f72c974162b6c905d438ba7afa2b8f18b1c5d319d675e8821c7a3aae4fbb3a420f46f4c09b8548911a53fd2d1b3915b7609859fdac6be82c6ac2b2
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
 
@@ -6,6 +6,7 @@ module Croods
6
6
  module Definition
7
7
  TYPES = {
8
8
  datetime: 'string',
9
+ date: 'string',
9
10
  text: 'string',
10
11
  json: 'object',
11
12
  float: 'number'
@@ -17,9 +18,14 @@ module Croods
17
18
  end
18
19
 
19
20
  def format(attribute)
20
- return {} unless attribute.type == :datetime
21
-
22
- { format: 'date-time' }
21
+ case attribute.type
22
+ when :datetime
23
+ { format: 'date-time' }
24
+ when :date
25
+ { format: 'date' }
26
+ else
27
+ {}
28
+ end
23
29
  end
24
30
 
25
31
  def types(attribute)
@@ -4,8 +4,6 @@ module Croods
4
4
  module Resource
5
5
  module JsonSchema
6
6
  module Definitions
7
- TYPES = { datetime: 'string', text: 'string', json: 'object' }.freeze
8
-
9
7
  class << self
10
8
  def schema(resource)
11
9
  attributes(resource).merge(identity: identity(resource))
@@ -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.camelize}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.1'
4
+ VERSION = '0.2.6'
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.1
4
+ version: 0.2.6
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-04-30 00:00:00.000000000 Z
11
+ date: 2020-06-13 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