kriangle 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +30 -0
- data/Gemfile.lock +216 -0
- data/LICENSE.txt +21 -0
- data/README.md +307 -0
- data/Rakefile +4 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/kriangle.gemspec +42 -0
- data/lib/generators/kriangle/generator_helpers.rb +95 -0
- data/lib/generators/kriangle/install_generator.rb +149 -0
- data/lib/generators/kriangle/module_generator.rb +273 -0
- data/lib/generators/kriangle/templates/active_serializer.rb +9 -0
- data/lib/generators/kriangle/templates/application_record.rb +9 -0
- data/lib/generators/kriangle/templates/auth.rb +138 -0
- data/lib/generators/kriangle/templates/authentication.rb +7 -0
- data/lib/generators/kriangle/templates/authenticator.rb +70 -0
- data/lib/generators/kriangle/templates/avatar.rb +5 -0
- data/lib/generators/kriangle/templates/avatar_uploader.rb +49 -0
- data/lib/generators/kriangle/templates/base.rb +6 -0
- data/lib/generators/kriangle/templates/controller.rb +241 -0
- data/lib/generators/kriangle/templates/controllers.rb +21 -0
- data/lib/generators/kriangle/templates/counter_cache_migration.rb +5 -0
- data/lib/generators/kriangle/templates/create_authentications.rb +10 -0
- data/lib/generators/kriangle/templates/create_avatars.rb +10 -0
- data/lib/generators/kriangle/templates/create_users.rb.erb +48 -0
- data/lib/generators/kriangle/templates/custom_description.rb +30 -0
- data/lib/generators/kriangle/templates/defaults.rb +29 -0
- data/lib/generators/kriangle/templates/kriangle.rb +5 -0
- data/lib/generators/kriangle/templates/model.rb +33 -0
- data/lib/generators/kriangle/templates/module_migration.rb +33 -0
- data/lib/generators/kriangle/templates/responder.rb +170 -0
- data/lib/generators/kriangle/templates/serializer.rb +35 -0
- data/lib/generators/kriangle/templates/swagger.rb +8 -0
- data/lib/generators/kriangle/templates/user.rb +35 -0
- data/lib/kriangle.rb +36 -0
- data/lib/kriangle/version.rb +5 -0
- metadata +355 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 94a8b6cad02b4f2290c4db90ec9c521d6e4524f5eedb16d5080560c64d4b669d
|
4
|
+
data.tar.gz: 2427a89e91ea3ee96b5c9461e53028f3a94db4c88fcc4efd5a5518dcea4b95dd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c94d697623ca4c12f389244d9bb600b6b8dfd15ad59fbb407d1bcd824a3c35e472386f25a840eecdcf6c15eab9233d3a7d60ae5c21b9c26313921202e2eb99b
|
7
|
+
data.tar.gz: 8cafdce35a5c41f46ea45d1e743513654877de90ae1ce322bb4686bf17ec7805d33e76d4d23a74a01c300c4662d5fe09d74e7f9495e31b31f209b1372be410f5
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at lalit.logical@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
|
+
|
7
|
+
# Specify your gem's dependencies in kriangle.gemspec
|
8
|
+
gemspec
|
9
|
+
|
10
|
+
gem 'byebug', platform: :mri
|
11
|
+
|
12
|
+
gem 'sqlite3', '~> 1.4', '>= 1.4.2'
|
13
|
+
|
14
|
+
gem 'bcrypt', '~> 3.1.7'
|
15
|
+
gem 'dotenv-rails', '~> 2.7', '>= 2.7.6'
|
16
|
+
gem 'devise', '~> 4.4', '>= 4.4.3'
|
17
|
+
|
18
|
+
gem 'grape', '~> 1.2', '>= 1.2.4'
|
19
|
+
gem 'grape-active_model_serializers', '~> 1.5', '>= 1.5.2'
|
20
|
+
gem 'grape-rails-cache', '~> 0.1.2'
|
21
|
+
gem 'grape-swagger', '~> 1.4'
|
22
|
+
gem 'grape-swagger-rails', '~> 0.3.1'
|
23
|
+
|
24
|
+
gem 'api-pagination', '~> 4.7'
|
25
|
+
gem 'kaminari', '~> 1.0', '>= 1.0.1'
|
26
|
+
|
27
|
+
gem 'rack-cors', '~> 1.1', '>= 1.1.1'
|
28
|
+
gem 'ransack', '~> 2.3'
|
29
|
+
|
30
|
+
gem 'carrierwave', '~> 2.0', '>= 2.0.2'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,216 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
kriangle (0.1.0)
|
5
|
+
api-pagination (~> 4.7)
|
6
|
+
bcrypt (~> 3.1.7)
|
7
|
+
carrierwave (~> 2.0, >= 2.0.2)
|
8
|
+
devise (~> 4.4, >= 4.4.3)
|
9
|
+
dotenv-rails (~> 2.7, >= 2.7.6)
|
10
|
+
grape (~> 1.2, >= 1.2.4)
|
11
|
+
grape-active_model_serializers (~> 1.5, >= 1.5.2)
|
12
|
+
grape-rails-cache (~> 0.1.2)
|
13
|
+
grape-swagger (~> 1.4)
|
14
|
+
grape-swagger-rails (~> 0.3.1)
|
15
|
+
kaminari (~> 1.0, >= 1.0.1)
|
16
|
+
rack-cors (~> 1.1, >= 1.1.1)
|
17
|
+
ransack (~> 2.3)
|
18
|
+
sqlite3 (~> 1.4, >= 1.4.2)
|
19
|
+
|
20
|
+
GEM
|
21
|
+
remote: https://rubygems.org/
|
22
|
+
specs:
|
23
|
+
actionpack (6.1.3.2)
|
24
|
+
actionview (= 6.1.3.2)
|
25
|
+
activesupport (= 6.1.3.2)
|
26
|
+
rack (~> 2.0, >= 2.0.9)
|
27
|
+
rack-test (>= 0.6.3)
|
28
|
+
rails-dom-testing (~> 2.0)
|
29
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
30
|
+
actionview (6.1.3.2)
|
31
|
+
activesupport (= 6.1.3.2)
|
32
|
+
builder (~> 3.1)
|
33
|
+
erubi (~> 1.4)
|
34
|
+
rails-dom-testing (~> 2.0)
|
35
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
36
|
+
active_model_serializers (0.10.12)
|
37
|
+
actionpack (>= 4.1, < 6.2)
|
38
|
+
activemodel (>= 4.1, < 6.2)
|
39
|
+
case_transform (>= 0.2)
|
40
|
+
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
|
41
|
+
activemodel (6.1.3.2)
|
42
|
+
activesupport (= 6.1.3.2)
|
43
|
+
activerecord (6.1.3.2)
|
44
|
+
activemodel (= 6.1.3.2)
|
45
|
+
activesupport (= 6.1.3.2)
|
46
|
+
activesupport (6.1.3.2)
|
47
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
48
|
+
i18n (>= 1.6, < 2)
|
49
|
+
minitest (>= 5.1)
|
50
|
+
tzinfo (~> 2.0)
|
51
|
+
zeitwerk (~> 2.3)
|
52
|
+
addressable (2.7.0)
|
53
|
+
public_suffix (>= 2.0.2, < 5.0)
|
54
|
+
api-pagination (4.8.2)
|
55
|
+
bcrypt (3.1.16)
|
56
|
+
builder (3.2.4)
|
57
|
+
byebug (11.1.3)
|
58
|
+
carrierwave (2.2.1)
|
59
|
+
activemodel (>= 5.0.0)
|
60
|
+
activesupport (>= 5.0.0)
|
61
|
+
addressable (~> 2.6)
|
62
|
+
image_processing (~> 1.1)
|
63
|
+
marcel (~> 1.0.0)
|
64
|
+
mini_mime (>= 0.1.3)
|
65
|
+
ssrf_filter (~> 1.0)
|
66
|
+
case_transform (0.2)
|
67
|
+
activesupport
|
68
|
+
concurrent-ruby (1.1.8)
|
69
|
+
crass (1.0.6)
|
70
|
+
devise (4.8.0)
|
71
|
+
bcrypt (~> 3.0)
|
72
|
+
orm_adapter (~> 0.1)
|
73
|
+
railties (>= 4.1.0)
|
74
|
+
responders
|
75
|
+
warden (~> 1.2.3)
|
76
|
+
dotenv (2.7.6)
|
77
|
+
dotenv-rails (2.7.6)
|
78
|
+
dotenv (= 2.7.6)
|
79
|
+
railties (>= 3.2)
|
80
|
+
dry-configurable (0.12.1)
|
81
|
+
concurrent-ruby (~> 1.0)
|
82
|
+
dry-core (~> 0.5, >= 0.5.0)
|
83
|
+
dry-container (0.7.2)
|
84
|
+
concurrent-ruby (~> 1.0)
|
85
|
+
dry-configurable (~> 0.1, >= 0.1.3)
|
86
|
+
dry-core (0.5.0)
|
87
|
+
concurrent-ruby (~> 1.0)
|
88
|
+
dry-inflector (0.2.0)
|
89
|
+
dry-logic (1.2.0)
|
90
|
+
concurrent-ruby (~> 1.0)
|
91
|
+
dry-core (~> 0.5, >= 0.5)
|
92
|
+
dry-types (1.5.1)
|
93
|
+
concurrent-ruby (~> 1.0)
|
94
|
+
dry-container (~> 0.3)
|
95
|
+
dry-core (~> 0.5, >= 0.5)
|
96
|
+
dry-inflector (~> 0.1, >= 0.1.2)
|
97
|
+
dry-logic (~> 1.0, >= 1.0.2)
|
98
|
+
erubi (1.10.0)
|
99
|
+
ffi (1.15.1)
|
100
|
+
grape (1.5.3)
|
101
|
+
activesupport
|
102
|
+
builder
|
103
|
+
dry-types (>= 1.1)
|
104
|
+
mustermann-grape (~> 1.0.0)
|
105
|
+
rack (>= 1.3.0)
|
106
|
+
rack-accept
|
107
|
+
grape-active_model_serializers (1.5.2)
|
108
|
+
active_model_serializers (>= 0.10.0)
|
109
|
+
grape (>= 0.8.0)
|
110
|
+
grape-rails-cache (0.1.2)
|
111
|
+
activesupport
|
112
|
+
grape
|
113
|
+
grape-swagger (1.4.0)
|
114
|
+
grape (~> 1.3)
|
115
|
+
grape-swagger-rails (0.3.1)
|
116
|
+
railties (>= 3.2.12)
|
117
|
+
i18n (1.8.10)
|
118
|
+
concurrent-ruby (~> 1.0)
|
119
|
+
image_processing (1.12.1)
|
120
|
+
mini_magick (>= 4.9.5, < 5)
|
121
|
+
ruby-vips (>= 2.0.17, < 3)
|
122
|
+
jsonapi-renderer (0.2.2)
|
123
|
+
kaminari (1.2.1)
|
124
|
+
activesupport (>= 4.1.0)
|
125
|
+
kaminari-actionview (= 1.2.1)
|
126
|
+
kaminari-activerecord (= 1.2.1)
|
127
|
+
kaminari-core (= 1.2.1)
|
128
|
+
kaminari-actionview (1.2.1)
|
129
|
+
actionview
|
130
|
+
kaminari-core (= 1.2.1)
|
131
|
+
kaminari-activerecord (1.2.1)
|
132
|
+
activerecord
|
133
|
+
kaminari-core (= 1.2.1)
|
134
|
+
kaminari-core (1.2.1)
|
135
|
+
loofah (2.9.1)
|
136
|
+
crass (~> 1.0.2)
|
137
|
+
nokogiri (>= 1.5.9)
|
138
|
+
marcel (1.0.1)
|
139
|
+
method_source (1.0.0)
|
140
|
+
mini_magick (4.11.0)
|
141
|
+
mini_mime (1.1.0)
|
142
|
+
mini_portile2 (2.5.1)
|
143
|
+
minitest (5.14.4)
|
144
|
+
mustermann (1.1.1)
|
145
|
+
ruby2_keywords (~> 0.0.1)
|
146
|
+
mustermann-grape (1.0.1)
|
147
|
+
mustermann (>= 1.0.0)
|
148
|
+
nokogiri (1.11.5)
|
149
|
+
mini_portile2 (~> 2.5.0)
|
150
|
+
racc (~> 1.4)
|
151
|
+
orm_adapter (0.5.0)
|
152
|
+
public_suffix (4.0.6)
|
153
|
+
racc (1.5.2)
|
154
|
+
rack (2.2.3)
|
155
|
+
rack-accept (0.4.5)
|
156
|
+
rack (>= 0.4)
|
157
|
+
rack-cors (1.1.1)
|
158
|
+
rack (>= 2.0.0)
|
159
|
+
rack-test (1.1.0)
|
160
|
+
rack (>= 1.0, < 3)
|
161
|
+
rails-dom-testing (2.0.3)
|
162
|
+
activesupport (>= 4.2.0)
|
163
|
+
nokogiri (>= 1.6)
|
164
|
+
rails-html-sanitizer (1.3.0)
|
165
|
+
loofah (~> 2.3)
|
166
|
+
railties (6.1.3.2)
|
167
|
+
actionpack (= 6.1.3.2)
|
168
|
+
activesupport (= 6.1.3.2)
|
169
|
+
method_source
|
170
|
+
rake (>= 0.8.7)
|
171
|
+
thor (~> 1.0)
|
172
|
+
rake (13.0.3)
|
173
|
+
ransack (2.4.2)
|
174
|
+
activerecord (>= 5.2.4)
|
175
|
+
activesupport (>= 5.2.4)
|
176
|
+
i18n
|
177
|
+
responders (3.0.1)
|
178
|
+
actionpack (>= 5.0)
|
179
|
+
railties (>= 5.0)
|
180
|
+
ruby-vips (2.1.2)
|
181
|
+
ffi (~> 1.12)
|
182
|
+
ruby2_keywords (0.0.4)
|
183
|
+
sqlite3 (1.4.2)
|
184
|
+
ssrf_filter (1.0.7)
|
185
|
+
thor (1.1.0)
|
186
|
+
tzinfo (2.0.4)
|
187
|
+
concurrent-ruby (~> 1.0)
|
188
|
+
warden (1.2.9)
|
189
|
+
rack (>= 2.0.9)
|
190
|
+
zeitwerk (2.4.2)
|
191
|
+
|
192
|
+
PLATFORMS
|
193
|
+
ruby
|
194
|
+
|
195
|
+
DEPENDENCIES
|
196
|
+
api-pagination (~> 4.7)
|
197
|
+
bcrypt (~> 3.1.7)
|
198
|
+
bundler (~> 1.16)
|
199
|
+
byebug
|
200
|
+
carrierwave (~> 2.0, >= 2.0.2)
|
201
|
+
devise (~> 4.4, >= 4.4.3)
|
202
|
+
dotenv-rails (~> 2.7, >= 2.7.6)
|
203
|
+
grape (~> 1.2, >= 1.2.4)
|
204
|
+
grape-active_model_serializers (~> 1.5, >= 1.5.2)
|
205
|
+
grape-rails-cache (~> 0.1.2)
|
206
|
+
grape-swagger (~> 1.4)
|
207
|
+
grape-swagger-rails (~> 0.3.1)
|
208
|
+
kaminari (~> 1.0, >= 1.0.1)
|
209
|
+
kriangle!
|
210
|
+
rack-cors (~> 1.1, >= 1.1.1)
|
211
|
+
rake (~> 13.0)
|
212
|
+
ransack (~> 2.3)
|
213
|
+
sqlite3 (~> 1.4, >= 1.4.2)
|
214
|
+
|
215
|
+
BUNDLED WITH
|
216
|
+
1.16.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Lalit Kumar Maurya
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,307 @@
|
|
1
|
+
# Kriangle
|
2
|
+
|
3
|
+
Kriangle is a library (gem) built upon ruby to scaffold the Modules (Model, Controller, Serialiser, APIs and much more) in rails project.
|
4
|
+
|
5
|
+
Any modules can be consists of below components.
|
6
|
+
1. Model
|
7
|
+
2. Controller (APIs)
|
8
|
+
3. Serialiser
|
9
|
+
5. Swagger Docs
|
10
|
+
6. much more ...
|
11
|
+
|
12
|
+
Kriangle can scaffold any module easily by using it’s [Generators](#generators). You can control the module generation with [skip options](#skip-options). Also you can choose the [options](#options) as per your requirements.
|
13
|
+
|
14
|
+
## Contents
|
15
|
+
|
16
|
+
- [Getting Started](#getting-started)
|
17
|
+
- [Generators](#generators)
|
18
|
+
- [Initial Setup](#initial-setup)
|
19
|
+
- [Module Generator](#module-generator)
|
20
|
+
- [Options](#options)
|
21
|
+
- [Associations](#associations)
|
22
|
+
- [Columns](#columns)
|
23
|
+
- [Controller Actions](#controller-actions)
|
24
|
+
- [Skip Options](#skip-options)
|
25
|
+
- [Advanced Options](#advanced-options)
|
26
|
+
- [Database](#database)
|
27
|
+
- [Wrapper](#wrapper)
|
28
|
+
- [APIs Routes](#apis-routes)
|
29
|
+
- [Parent Reference](#parent-reference)
|
30
|
+
- [Self Reference](#self-reference)
|
31
|
+
- [Example](#example)
|
32
|
+
- [License](#license)
|
33
|
+
- [Code of Conduct](#code-of-conduct)
|
34
|
+
|
35
|
+
## Getting started
|
36
|
+
|
37
|
+
Kriangle works with Rails 5.1 onwards (< 6). Add the following line to your Gemfile:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
gem 'kriangle'
|
41
|
+
```
|
42
|
+
|
43
|
+
Or you can use the master branch code as gem. Add the following line to your Gemfile:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
gem 'kriangle', git: 'git@github.com:lalitlogical/kriangle.git', branch: 'master'
|
47
|
+
```
|
48
|
+
|
49
|
+
Then run `bundle install`
|
50
|
+
|
51
|
+
Kriangle dependent on [Devise](https://github.com/heartcombo/devise) gem for its authentication module. So we have to generate its intialiser file by installing it.
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
bundle exec rails g devise:install
|
55
|
+
```
|
56
|
+
|
57
|
+
Next, you need to run the generators:
|
58
|
+
|
59
|
+
### Generators
|
60
|
+
|
61
|
+
Kriangle provides two generator for this purpose:
|
62
|
+
1. [Initial Setup](#initial-setup) - Install the Kriangle and it's dependencies into the existing project.
|
63
|
+
2. [Module Generator](#module-generator) - Scaffold new modules into the existing project.
|
64
|
+
|
65
|
+
Always remember the **hierarchy** of modules. So if any module behave as child of any other module then parent module should be generated before the child module. So when you generate the modules, it should follow the hierarchy. i.e. if you enable the counter cache on `Post` model for it's owners, `User` module must created before `Post` module. So hierarchy should be like `User`, `Post`, `Comment`, `Like`, etc for a blog rails application.
|
66
|
+
|
67
|
+
### Initial Setup
|
68
|
+
|
69
|
+
In intial setup, it's create the intialiser files, authentication module (login, register, forgot password, etc), swagger setup, etc. Swagger help to create the APIs docs. This command can be run single time per project and always before module generator.
|
70
|
+
|
71
|
+
In the following command you will replace `MODEL` with the class name used for the application’s users. This will create a model (if one does not exist) and configure it with the authentication module. The generator also configures your config/routes.rb file to point to the authentications controller.This command can be run single time per project and always before module generator.
|
72
|
+
|
73
|
+
`rails g kriangle:install MODEL PATH [column_name:type]`
|
74
|
+
|
75
|
+
i.e. if you want to generate the User model with Authentication model (for authentication purpose), so you can type below command.
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
rails g kriangle:install User Auth first_name last_name gender age
|
79
|
+
```
|
80
|
+
Note: `email`, `password`, other columns and authetication related table will be added automatically.
|
81
|
+
|
82
|
+
### Module Generator
|
83
|
+
|
84
|
+
In above command we have setup the initial authetication module. We can generate the new modules with below command. You have to take care of sequence of options as below.
|
85
|
+
|
86
|
+
`rails g kriangle:module MODULE [association type] [column_name:type] [controller actions] [skip options]`
|
87
|
+
|
88
|
+
if you want to generate `Post` model with title, content columns, you can type below.
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
rails g kriangle:module Post title:string content:text
|
92
|
+
```
|
93
|
+
|
94
|
+
By default, generated the model does not refered to current logged in user. You can enable it by passing reference=true and other arguments as below.
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
rails g kriangle:module Post title:text:false:_cont_any content:text:false:_cont_any published:boolean:false::false index show create update destroy --reference=true --reference_name=current_user --association_type=has_many --skip_tips=true --creation_method=new
|
98
|
+
```
|
99
|
+
|
100
|
+
If you want to enable counter cache on user's record, you should use below command.
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
rails g kriangle:module Post title:text:false:_cont_any content:text:false:_cont_any published:boolean:false::false index show create update destroy --reference=true --reference_name=current_user --association_type=has_many --counter_cache=true --skip_tips=true --creation_method=new
|
104
|
+
```
|
105
|
+
|
106
|
+
## Options
|
107
|
+
|
108
|
+
Kriangle support different arguments to control the code generation.
|
109
|
+
|
110
|
+
### Associations
|
111
|
+
|
112
|
+
If you have rails knowledge, you are already aware about the associations (has_many, belongs_to, etc). You can control this with [Generate New module](#generate-new-module) command. This options support below items in same sequence.
|
113
|
+
|
114
|
+
`ma:association_type:association_name:dependent_type:validate_presence:counter_cache:touch_record:accepts_nested_attributes:foreign_key:class_name`
|
115
|
+
|
116
|
+
Let understand the every options and its supported values. By default false or nil depedents on arguments.
|
117
|
+
|
118
|
+
| Option | Description | Required |
|
119
|
+
|:--- |:--- |:--- |
|
120
|
+
| `association_type` | `has_many` or `belongs_to` or `has_one` | True |
|
121
|
+
| `association_name` | any previously created model name in lower case | True |
|
122
|
+
| `dependent_type` | `delete_all` or `destroy_all` or `nullify`. Works only with `has_many` and `has_one` association | |
|
123
|
+
| `validate_presence` | `true` or `false`. Works only with `belongs_to` association | |
|
124
|
+
| `counter_cache` | `true` or `false` | |
|
125
|
+
| `touch_record` | `true` or `false` | |
|
126
|
+
| `accepts_nested_attributes` | `true` or `false`. Works only with `has_many` and `has_one` association | |
|
127
|
+
| `foreign_key` | custom foreign key | |
|
128
|
+
| `class_name` | any previously created model name | |
|
129
|
+
|
130
|
+
i.e.
|
131
|
+
|
132
|
+
`ma:has_many:comments::false:false:false:false:`
|
133
|
+
|
134
|
+
### Columns
|
135
|
+
|
136
|
+
By default rails support two options into migration. But we have enhance it into Kriangle. It supports as below.
|
137
|
+
|
138
|
+
`column name:type:validate_presence:search_by:default value`
|
139
|
+
|
140
|
+
Let understand the every arguments and its supported values. By default false or nil depedents on arguments.
|
141
|
+
|
142
|
+
| Option | Description | Required |
|
143
|
+
|:--- |:--- |:--- |
|
144
|
+
| column name | any valid column name for your model | True |
|
145
|
+
| type | `string`, `text`, `boolean`, `integer`, `float`, `date`, `DateTime`, `array`, `attachment`, `Polymorphic`, `json` | True |
|
146
|
+
| `validate_presence` | `true` or `false`. To validate the presence of column value | |
|
147
|
+
| `search_by` | `_eq`, `_not_eq`, `_matches`, `_does_not_match`, `_cont`, `_cont_any`, `_cont_all`, `_not_cont`, `_not_cont_any`, `_not_cont_all`, `_true`, `_false` | |
|
148
|
+
| deafult value | pass the default value for columns. i.e. `true` or `false` for boolean type of column | |
|
149
|
+
|
150
|
+
i.e.
|
151
|
+
|
152
|
+
`title:string:false:_cont_any`
|
153
|
+
|
154
|
+
### Controller Actions
|
155
|
+
|
156
|
+
By default, all CRUD APIs generated. But if you want to control it, you have to mentioned the required action. It will generate only those APIs.
|
157
|
+
|
158
|
+
Valid actions mentioned as below.
|
159
|
+
1. index
|
160
|
+
2. show
|
161
|
+
3. create
|
162
|
+
4. update
|
163
|
+
5. destroy
|
164
|
+
6. create_or_destroy - Will update the controller's action according to like dislike feature respective to authenticator model (i.e. User).
|
165
|
+
|
166
|
+
### Skip Options
|
167
|
+
|
168
|
+
There are a lot of skip options available. You can check below.
|
169
|
+
|
170
|
+
| Skip Options | Default | Description |
|
171
|
+
|:--- |:--- |:--- |
|
172
|
+
| `skip_swagger` | `false` | Skip the swagger documentation. **Only** valid with `install` generator |
|
173
|
+
| `skip_avatar` | `true` | Skip the user's avatar feature. **Only** valid with `install` generator |
|
174
|
+
| `skip_model` | `false` | Skip the model creation if model aleady created and you do not want to override it. |
|
175
|
+
| `skip_controller` | `false` | Skip the controller (APIs) generation. |
|
176
|
+
| `skip_migration` | `false` | Skip the table migration if table aleady created and you do not want to override it. |
|
177
|
+
| `skip_tips` | `false` | Skip the tips or comments into files. |
|
178
|
+
| `skip_authentication` | `false` | Skip the authentication for whole APIs of given module. |
|
179
|
+
| `skip_serializer` | `false` | Skip the serialiser. |
|
180
|
+
| `skip_timestamps` | `false` | Skip the timestamps columns (created_at and updated_at) into migration |
|
181
|
+
| `skip_pagination` | `false` | Skip the pagination from index API of controller. |
|
182
|
+
|
183
|
+
### Advanced Options
|
184
|
+
|
185
|
+
Kriangle support some additional arguments also for generate code as per requirement.
|
186
|
+
|
187
|
+
#### Database
|
188
|
+
|
189
|
+
By default, Kriangle generate code based on `sqlite3` database, mostly migration files depends on it. But you can provide the database to generate the code based on that.
|
190
|
+
|
191
|
+
```ruby
|
192
|
+
--database=postgresql
|
193
|
+
```
|
194
|
+
|
195
|
+
Supported databases: `postgresql`, `mysql`, `sqlite3`. You have to add **adapter/gem** based on your database in your **Gemfile**
|
196
|
+
|
197
|
+
|
198
|
+
#### Wrapper
|
199
|
+
|
200
|
+
Kriangle generate all APIs under `app/controllers/api/v1` folder. You can change the wrapper name (v1) as per you need with `wrapper` arguments as below.
|
201
|
+
|
202
|
+
```ruby
|
203
|
+
--wrapper=V2
|
204
|
+
```
|
205
|
+
|
206
|
+
#### APIs Routes
|
207
|
+
|
208
|
+
Kriangle by default use the model name for routes. So if do not pass it will determined with model name. i.e. For `Post` model api routes will be `posts` and whole end points will be like `api/v1/posts`. You can change it by passing your desired path as below.
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
--controller_path=blogs
|
212
|
+
```
|
213
|
+
|
214
|
+
Now all APIs points to `/api/v1/blogs` but model will be `Post`.
|
215
|
+
|
216
|
+
#### Parent Reference
|
217
|
+
|
218
|
+
Kriangle provides mechanism to add parent reference with previously created model (i.e. `User`, `Post` ) or `current_user`.
|
219
|
+
|
220
|
+
If you want that newly created records associate with current logged in user, you have to pass below arguments.
|
221
|
+
|
222
|
+
```ruby
|
223
|
+
--reference=true --reference_name=current_user --association_type=has_many
|
224
|
+
```
|
225
|
+
There are other options also available under this Parent Reference.
|
226
|
+
|
227
|
+
| Option | Default | Description |
|
228
|
+
|:--- |:--- |:--- |
|
229
|
+
| `reference` | `false` | Current model's association sets up a one-to-one connection with selected model, such that each instance of the declaring model 'belongs to' one instance of the selected model. |
|
230
|
+
| `reference_name` | | `current_user` or previously created model name i.e. `User`, `Post` |
|
231
|
+
| `association_type` | `has_many` | `has_many` or `has_one` |
|
232
|
+
| `counter_cache` | `false` | Default false. Instead of counting the associated records in the database every time the page loads, ActiveRecord’s counter caching feature allows storing the counter and updating it every time an associated object is created or removed. Parent model should be defined before this model. |
|
233
|
+
| `touch_record` | `false` | In rails touch is used to update the parent's updated_at field for persisted objects. |
|
234
|
+
| `accepts_nested_attributes` | `false` | Nested attributes allow you to save attributes on associated records through the parent. By default nested attribute updating is turned off and you can enable it using the accepts_nested_attributes_for class method. When you enable nested attributes an attribute writer is defined on the model. |
|
235
|
+
|
236
|
+
#### Self Reference
|
237
|
+
|
238
|
+
Kriangle provides mechanism to add self reference within the model.
|
239
|
+
|
240
|
+
If you want that newly created records associate with existing record of same table, you have to pass below arguments.
|
241
|
+
|
242
|
+
```ruby
|
243
|
+
--self_reference=true --parent_association_name=parent --child_association_name=replies
|
244
|
+
```
|
245
|
+
|
246
|
+
You can chose your desired association name through `parent_association_name` and `child_association_name` arguments.
|
247
|
+
|
248
|
+
## Example
|
249
|
+
|
250
|
+
To understand the uses of Kriangle, we will provide a example of **Blogger** rails application.
|
251
|
+
|
252
|
+
Let's create a rails project.
|
253
|
+
|
254
|
+
```ruby
|
255
|
+
rails _5.2.3_ new blogger
|
256
|
+
```
|
257
|
+
|
258
|
+
Now follow the [Getting Started](#getting-started) to setup the Kriangle gem into your newly created **blogger** rails project. After that we run its generators to scaffold new modules into the **blogger** rails project as below.
|
259
|
+
|
260
|
+
Let generate the **authentication** module. Its a **mendatory** step.
|
261
|
+
|
262
|
+
```ruby
|
263
|
+
rails g kriangle:install User email:string:true name:string:true --skip_avatar=true --skip_tips=true --controller_path=Auth
|
264
|
+
```
|
265
|
+
|
266
|
+
Let now generate the two modules.
|
267
|
+
1. [Blog](https://kriangle.s3.ap-south-1.amazonaws.com/blog-module-setting.png)
|
268
|
+
2. [Comment](https://kriangle.s3.ap-south-1.amazonaws.com/comment-module-setting.png)
|
269
|
+
|
270
|
+
Kriangle provide you different arguments to control the module generation. So we will use some of them mentioned below.
|
271
|
+
|
272
|
+
A full fledge command which contains approx all arguments will be like something below.
|
273
|
+
1. It will generate the `Blog` model with title, description, published columns and with enabling searching on title and description columns.
|
274
|
+
2. It will also create all CRUD APIs.
|
275
|
+
3. It will also associate the records with `current_user` during CRUD.
|
276
|
+
4. It will also enable counter caching on users table to store the blogs_count.
|
277
|
+
|
278
|
+
```ruby
|
279
|
+
rails g kriangle:module Blog ma:has_many:comments:delete_all:false:false:false:false: title:string:false:_cont_any description:text:false:_cont_any published:boolean:false::false index show create update destroy --reference=true --reference_name=current_user --association_type=has_many --counter_cache=true --skip_tips=true --creation_method=new
|
280
|
+
```
|
281
|
+
|
282
|
+
Next command will generate the `Comment` model associated with `Blog` model with message column. Its also provide the self reference mechanism to itself table to store the replies on the comments.
|
283
|
+
|
284
|
+
```ruby
|
285
|
+
rails g kriangle:module Comment ma:belongs_to:user::true:false:false:false: message:text:false index show create update destroy --reference=true --reference_name=Blog --association_type=has_many --counter_cache=true --self_reference=true --parent_association_name=parent --child_association_name=replies --skip_tips=true --creation_method=new
|
286
|
+
```
|
287
|
+
When you are done with these commands, please run `rake db:migrate` to complete the migration.
|
288
|
+
|
289
|
+
Now run the application and go to [http://localhost:3000/swagger](http://localhost:3000/swagger) routes to check the APIs documentation as below.
|
290
|
+
|
291
|
+
![alt text][api-documentation-image]
|
292
|
+
|
293
|
+
Also you can check the rails project which will magically contains the generated code.
|
294
|
+
|
295
|
+
This is the example of Kriangle which can be use to scaffold a full working module with these generators. Play it!
|
296
|
+
|
297
|
+
Hope you like it!. if you face any issue, please feel free to contact us :)
|
298
|
+
|
299
|
+
## License
|
300
|
+
|
301
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
302
|
+
|
303
|
+
## Code of Conduct
|
304
|
+
|
305
|
+
Everyone interacting in the Kriangle project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/lalitlogical/kriangle/blob/master/CODE_OF_CONDUCT.md).
|
306
|
+
|
307
|
+
[api-documentation-image]: https://kriangle.s3.ap-south-1.amazonaws.com/kriangle-api-documentation.png "Swagger APIs documentation"
|