rails_on_rails 0.1.2 → 0.1.3
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 +4 -4
- data/README.md +60 -39
- data/lib/autogenerators/generator_templates/controller.txt +1 -2
- data/lib/autogenerators/handlers/controller.rb +5 -2
- data/lib/autogenerators/rails_templates/api_documentation.rake +2 -2
- data/lib/autogenerators/rails_templates/documentation_controller.rb +1 -1
- data/lib/constants/cli_constants.rb +4 -1
- data/lib/constants/options.rb +1 -1
- data/lib/rails_on_rails.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4e1d585f063847ecd96cba21db767aa8e1bc343e86506c9c60a14fcdabce366
|
4
|
+
data.tar.gz: bbe7ab73544abbfa3de3ea52c2df30d5b3fc60722adf1e611b6ab38d9dd94b26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca9f9534cb03121ece937f26c0c7f40dd6b2c7929adfffcf9a3f6c8c787331d7b480e50c9aadaffaa6794f4fd81f548d2830d11b8a718f9c4377f6f1b19eb666
|
7
|
+
data.tar.gz: 4808d351d2102d30732b8ee9771677891f40c75590480eb6b32d964b14b90f44407c23bab5f10e7e57f05053d15e9a8288266bcf6c0c6acebcdb0cd2ee3712d1
|
data/README.md
CHANGED
@@ -7,7 +7,15 @@ The global controller file has changed
|
|
7
7
|
|
8
8
|
All commands must be execute in your Rails root project directory
|
9
9
|
|
10
|
+
## Gem Dependencies
|
11
|
+
|
12
|
+
- Ruby Version )= 2.5
|
13
|
+
- Rails Version 5: `gem 'rails', '~) 5'`
|
14
|
+
- Rails Rspec Version )= 3.8: `gem 'rspec-rails', '~) 3.8'`
|
15
|
+
- Faker Version )= 1.9: `gem 'faker', '~) 1.9'`
|
16
|
+
|
10
17
|
## Installation
|
18
|
+
|
11
19
|
Install in your gem file and a global install for this gem
|
12
20
|
|
13
21
|
Global Install:
|
@@ -16,30 +24,21 @@ Global Install:
|
|
16
24
|
Gemfile Install:
|
17
25
|
`gem 'rails_on_rails'`
|
18
26
|
|
19
|
-
##
|
20
|
-
- Ruby Version >= 2.5
|
21
|
-
- Rails Version 5: `gem 'rails', '~> 5'`
|
22
|
-
- Rails Rspec Version >= 3.8: `gem 'rspec-rails', '~> 3.8'`
|
23
|
-
- Faker Version >= 1.9: `gem 'faker', '~> 1.9'`
|
27
|
+
## Initialize your project with Rails on Rails
|
24
28
|
|
25
|
-
## Initialize your project with Rails + 1
|
26
29
|
If you run into hangups with spring, run `spring stop` before your `rails_on_rails`
|
27
30
|
Then `spring server` to resume spring
|
28
31
|
|
29
|
-
```
|
32
|
+
```bash
|
30
33
|
rails new tutorial
|
31
34
|
cd tutorial
|
32
|
-
|
33
|
-
# Check to make sure your initial rails database is setup correctly
|
34
|
-
# Check to make sure your initial rails setup is fully functional
|
35
|
-
# Make sure rails_on_rails is install in your gem file
|
36
|
-
|
37
35
|
rails_on_rails init
|
38
36
|
```
|
39
37
|
|
40
38
|
Before running the server add this initializer for the API Documentation
|
41
39
|
in your `config/application.rb` add this inside of your Rails::Apllication inherited class
|
42
|
-
|
40
|
+
|
41
|
+
```ruby
|
43
42
|
config.after_initialize do
|
44
43
|
require 'rake'
|
45
44
|
Rails.application.reload_routes!
|
@@ -49,7 +48,8 @@ end
|
|
49
48
|
```
|
50
49
|
|
51
50
|
In your `config/routes.rb` add this route for your documentation page
|
52
|
-
|
51
|
+
|
52
|
+
```ruby
|
53
53
|
resources :documentation, only: :index
|
54
54
|
```
|
55
55
|
|
@@ -58,24 +58,21 @@ But instead generates a controller for your model with unit tests to test the fu
|
|
58
58
|
and update a model assocations.
|
59
59
|
|
60
60
|
## CLI Commands
|
61
|
-
Rails on Rails: Command Line Interface to make your life easier.
|
62
|
-
=> The Rails on Rails command is 'rails_on_rails'. To blast this project into the fifth dimension.
|
63
|
-
=> Use '--help' or '-h on any of the commands listed below for more details.
|
64
61
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
=> test:spec - Generate a test spec for your controller
|
62
|
+

|
63
|
+
|
64
|
+
All these commands have `--help` flags with more descriptions on it's functionality.
|
65
|
+
|
66
|
+
[For more details on the generated CLI Commands](./docs/API_DOCUMENTATION.md)
|
71
67
|
|
72
68
|
## Generate your CRUD Operations for Index, Show, Create, Update, & Destroy
|
69
|
+
|
73
70
|
The `rails_on_rails model` command which has the same paramters as `rails g model`
|
74
71
|
But instead generates a controller for your model with unit tests to test the fully operationality controller after you declare your routes
|
75
72
|
and update a model assocations.
|
76
73
|
|
77
|
-
```
|
78
|
-
rails_on_rails model
|
74
|
+
```bash
|
75
|
+
rails_on_rails model (ModelName) (*native-rails-model-generate-parameters)
|
79
76
|
```
|
80
77
|
|
81
78
|
By default all our basic CRUD operations are complete for: Index, Show, Create, Update, & Destroy
|
@@ -86,6 +83,7 @@ With your default CRUD operations you have many tools at your deposible
|
|
86
83
|
For all of your options, you can see all the available options in the API docs based on our schema in for that model
|
87
84
|
|
88
85
|
### Querystring paramters
|
86
|
+
|
89
87
|
- Index:
|
90
88
|
-- include: Include will grab any associated tables with that endpoint separated by a comma (Check the docs for your schema's options)
|
91
89
|
-- where: Where will be a custom where hash the string string format is a json object without curly brackets (Check the docs for your schema's options)
|
@@ -97,6 +95,7 @@ For all of your options, you can see all the available options in the API docs b
|
|
97
95
|
-- where: Where will be a custom where hash the string string format is a json object without curly brackets (Check the docs for your schema's options)
|
98
96
|
|
99
97
|
### Body paramters
|
98
|
+
|
100
99
|
All values except id, created_at, updated_at, or deleted_at are available by default you have the available to overwrite everything
|
101
100
|
We use a custom method instead of params.permits
|
102
101
|
For associated keys like 'user_id' provide an array with the first value being a symbol for the assocation ':user'
|
@@ -105,20 +104,26 @@ When using polymorphoric assocations, it is recommended to use a hash map of typ
|
|
105
104
|
the value being the ActiveReord you provide in your schema with the search key being the string_type in the database
|
106
105
|
|
107
106
|
### Bonus Methods
|
107
|
+
|
108
108
|
- bulk_create: Create multiple rows the paramter is 'bulk' which is an array of create hashes
|
109
|
-
|
109
|
+
|
110
|
+
```ruby
|
110
111
|
params[:bulk] = [{ first_name: 'Mr. Robot' },{ first_name: 'Elloit }]
|
111
112
|
```
|
113
|
+
|
112
114
|
- bulk_update: Update multiple rows the paramter is 'bulk' which is a hash of ids with the update hash
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
params[:bulk] = { 1 =) { name: 'Luke Skywalker' }, 2 =) { name: 'Darth Vader' } }
|
113
118
|
```
|
114
|
-
|
115
|
-
```
|
119
|
+
|
116
120
|
- bulk_destroy: Destroy multiple rows the paramter is 'ids' which is an array of ids
|
117
121
|
- duplicate: Create a deep clone of any row in the database with all of it's assocations included the param is 'id' the table is for the controller associated to it
|
118
122
|
- bulk_csv_create: Create multiple rows the paramter is 'file' which is a csv file separated by commas and the first line is keys and the rest of values all separated by commas
|
119
123
|
|
120
124
|
#### Declaring bonus methods in `config/routes.rb`
|
121
|
-
|
125
|
+
|
126
|
+
```ruby
|
122
127
|
resources :user, except: [:edit, :new] do
|
123
128
|
collection do
|
124
129
|
post 'duplicate'
|
@@ -130,21 +135,24 @@ resources :user, except: [:edit, :new] do
|
|
130
135
|
end
|
131
136
|
```
|
132
137
|
|
133
|
-
## API Documentation
|
138
|
+
## API Documentation
|
139
|
+
|
134
140
|
The API Documentation requires CORS on your server, please set that up for all options for the web.
|
135
141
|
Also setup your file uploads (multipart) to be independent of erb templating
|
136
142
|
|
137
143
|
For custom headers that you may add in the future update the `lib/api_documentation.rake`
|
138
144
|
Line 48: is where you can update the needed headers for your axios ajax requests.
|
139
|
-
|
145
|
+
|
146
|
+
```javascript
|
140
147
|
var csrfHeader = { headers: { 'X-CSRF-Token': null } };
|
141
148
|
```
|
142
149
|
|
143
150
|
By default only json formats are unaccept for RESTful API JSON formatting
|
144
151
|
|
145
152
|
### Querystring parameters
|
153
|
+
|
146
154
|
A querystring in the url looks like this
|
147
|
-
|
155
|
+
`(protocol)://(host-name)/(path-name)(/path-name)?(querystring-key)=(querystring-value)&(querystring-key)=(querystring-value)`
|
148
156
|
|
149
157
|
Anything after and including the question mark is a querystring
|
150
158
|
You chain multiple querystring options spaced with '&'
|
@@ -152,11 +160,11 @@ You chain multiple querystring options spaced with '&'
|
|
152
160
|
The API Docs do the string maniplication for you under the hood.
|
153
161
|
|
154
162
|
The options for our API are:
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
163
|
+
|
164
|
+
- include = (include-options-separated-by-a-comma)
|
165
|
+
- where = (where-options-separated-by-a-comma)
|
166
|
+
- like = (like-options-separated-by-a-comma)
|
167
|
+
- order = (order-options-separated-by-a-comma)
|
160
168
|
|
161
169
|
Those options are given in the description for the endpoint you are testing
|
162
170
|
|
@@ -166,28 +174,35 @@ Those options are given in the description for the endpoint you are testing
|
|
166
174
|
- Order will grab the data in the order you request
|
167
175
|
|
168
176
|
### Body parameters
|
177
|
+
|
169
178
|
Body parameters are the key and value pairs you send in a request
|
170
179
|
Those options are available as well
|
171
180
|
Keeping the same key-value pair input UI with different functionality
|
172
181
|
Under the 'Body' title
|
173
182
|
|
174
183
|
### Path parameters
|
184
|
+
|
175
185
|
Path parameters are the key and value pairs you send in a request through the url
|
176
186
|
Keeping the same key-value pair input UI however other the value will be in the url
|
177
187
|
Under the 'Param' title
|
178
188
|
|
179
189
|
### Body Data Type option
|
190
|
+
|
180
191
|
This dropdown is only used for file uploads by default they are set to JSON
|
181
192
|
Use 'Form Data' for file uploads
|
182
193
|
|
194
|
+
[For more details on the generated API Documentation](./docs/API_DOCUMENTATION.md)
|
195
|
+
|
183
196
|
## RSpec Unit Tests
|
184
197
|
|
185
198
|
### Authenicated Routes
|
199
|
+
|
186
200
|
In your support file there is a called auth_helper. auth_helper.rb contains a login method.
|
187
201
|
You can enter your own login endpoint here and pass in any needed params with email and password as an example
|
188
202
|
so you can test authenicated routes with a JSON Web Token in your headers
|
189
203
|
|
190
204
|
### Test Database Seeders
|
205
|
+
|
191
206
|
The database seeders that are generated are a template that work for most types of schemas.
|
192
207
|
For custom schemas that may have unique constraints or unique behaviors. You can set a conditional to
|
193
208
|
search for the unique column name and set a value for it to satsify your unique needs.
|
@@ -195,14 +210,20 @@ search for the unique column name and set a value for it to satsify your unique
|
|
195
210
|
These seeders are only for your test database with randomized data from faker
|
196
211
|
|
197
212
|
### Controller Specs
|
213
|
+
|
198
214
|
The controller spec has tests for the generated controller. After you declare your routes, you can restrict the
|
199
215
|
tests for the routes you declare. The config_routes hash at the top will toggle those tests on or off because on what you set.
|
200
216
|
By default all tests are true.
|
201
217
|
Tests only cover basic CRUD resources: index, show, create, update, and destroy
|
202
218
|
|
203
|
-
|
219
|
+
[For more details on the generated RSpec testing](./docs/RSPEC_CONTROLLER_TESTS.md)
|
220
|
+
|
221
|
+
## Global Controller
|
222
|
+
|
204
223
|
There are many helpful util functions in the global controller at your deposal.
|
205
224
|
You can inherit the GlobalController instead of ApplicationController for your new controllers.
|
206
225
|
This gives you both the default Rails controller functionality and all these utils
|
207
226
|
|
208
|
-
In the autogeneration we utilize inheritance as much as posssible for cleaner controllers
|
227
|
+
In the autogeneration we utilize inheritance as much as posssible for cleaner controllers
|
228
|
+
|
229
|
+
[For more details on the Global Controller](./docs/GLOBAL_CONTROLLER.md)
|
@@ -1,12 +1,14 @@
|
|
1
1
|
require_relative '../../utils/rails_methods.rb'
|
2
2
|
|
3
3
|
SKIP_MODEL = true?(ARGV[0])
|
4
|
-
|
4
|
+
V2_GLOBAL = true?(ARGV[1])
|
5
|
+
MODEL_NAME = ARGV[2]
|
5
6
|
MODEL_PARAMS = ARGV
|
6
|
-
|
7
|
+
3.times { |i| MODEL_PARAMS.shift }
|
7
8
|
|
8
9
|
MODEL_SNAKE_CASE = MODEL_NAME.underscore
|
9
10
|
MODEL_CAMEL_CASE = MODEL_NAME.camelize
|
11
|
+
GLOBAL_CONTROLLER = V2_GLOBAL ? 'V2::GlobalController' : 'GlobalController'
|
10
12
|
|
11
13
|
system("bash #{__dir__}/../bash_commands/generate_model.sh #{MODEL_CAMEL_CASE} #{MODEL_PARAMS.join(' ')}") if !SKIP_MODEL
|
12
14
|
system("bash #{__dir__}/../bash_commands/generate_controller.sh #{MODEL_SNAKE_CASE} --no-assets --no-view-specs --no-helper")
|
@@ -17,5 +19,6 @@ template_path = "#{__dir__}/../generator_templates/controller.txt"
|
|
17
19
|
read_file = File.open(template_path, 'r:UTF-8', &:read)
|
18
20
|
|
19
21
|
read_file = read_file.gsub! '{{ MODEL }}', MODEL_CAMEL_CASE
|
22
|
+
read_file = read_file.gsub! '{{ GLOBAL_CONTROLLER }}', GLOBAL_CONTROLLER
|
20
23
|
|
21
24
|
File.write(controller_path, read_file)
|
@@ -63,7 +63,7 @@ namespace :api_documentation do
|
|
63
63
|
|
64
64
|
var routeName = allData.route.split('/').map(e => paramObject[e] ? paramObject[e] : e).join('/');
|
65
65
|
|
66
|
-
if (allData.method !== 'GET'
|
66
|
+
if (allData.method !== 'GET') {
|
67
67
|
var bodyDataType = document.getElementById('#{camelCased}DataType') && document.getElementById('#{camelCased}DataType').value ? document.getElementById('#{camelCased}DataType').value : false;
|
68
68
|
var formBoolean = bodyDataType === 'Form Data';
|
69
69
|
|
@@ -132,7 +132,7 @@ namespace :api_documentation do
|
|
132
132
|
}
|
133
133
|
}
|
134
134
|
|
135
|
-
var args = allData.method === 'GET'
|
135
|
+
var args = allData.method === 'GET' ? [routeName + querystring, csrfHeader] : [routeName + querystring, bodyObject, csrfHeader];
|
136
136
|
var resultElement = document.getElementById('#{camelCased}-results');
|
137
137
|
|
138
138
|
axios[allData.method.toLowerCase()](...args)
|
@@ -99,7 +99,7 @@ class DocumentationController < ApplicationController
|
|
99
99
|
submitButtonColor: submit_button_color,
|
100
100
|
camelCased: camel_cased,
|
101
101
|
allowParams: temp_route.split(':').length > 1,
|
102
|
-
allowBody: method
|
102
|
+
allowBody: method != 'GET',
|
103
103
|
description: description,
|
104
104
|
}
|
105
105
|
end
|
@@ -36,8 +36,11 @@ List of commands:
|
|
36
36
|
"This command runs the same as 'rails generate model --help'.
|
37
37
|
|
38
38
|
Use the parameters in 'rails generate model' to generate your CRUD operators.
|
39
|
+
AVR only Option:
|
40
|
+
--v2=true => Add GlobalController version v2
|
41
|
+
|
39
42
|
Optional flag options are:
|
40
|
-
--no-model => Do not generate a model in this command
|
43
|
+
--no-model=true => Do not generate a model in this command
|
41
44
|
--skip=<options-separated-by-a-comma-for-multiple-options>
|
42
45
|
Skip Options:
|
43
46
|
#{opts.join("\n")}
|
data/lib/constants/options.rb
CHANGED
data/lib/rails_on_rails.rb
CHANGED
@@ -77,6 +77,7 @@ class Commander < CLIOptions
|
|
77
77
|
all_action_methods = [:generate_test_seeder, :generate_test_rspec]
|
78
78
|
skip_options = options[:skip]
|
79
79
|
no_model = !options[:"no-model"].nil?
|
80
|
+
v2 = !options[:"v2"].nil?
|
80
81
|
skipping = {}
|
81
82
|
if skip_options
|
82
83
|
skipping = skip_options.split(',').flat_map { |e| skip_model_controller_options[e.to_sym] }.select { |e| e.nil? == false }.each_with_object({}) do |e, acc|
|
@@ -86,7 +87,7 @@ class Commander < CLIOptions
|
|
86
87
|
end
|
87
88
|
all_action_methods = all_action_methods.reject { |e| skipping[e].nil? == false }
|
88
89
|
path = __dir__ + '/autogenerators/handlers/controller.rb'
|
89
|
-
system("ruby #{path} #{no_model} #{arguments.join(' ')}")
|
90
|
+
system("ruby #{path} #{no_model} #{v2} #{arguments.join(' ')}")
|
90
91
|
all_action_methods.each { |e| method(e).call(*args) }
|
91
92
|
puts "Finished generating model and controller for #{args[2]}"
|
92
93
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_on_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aidan Miles
|
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
- !ruby/object:Gem::Version
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
|
-
rubygems_version: 3.0.
|
107
|
+
rubygems_version: 3.0.3
|
108
108
|
signing_key:
|
109
109
|
specification_version: 4
|
110
110
|
summary: A scaffolding tool for your Rails projects!
|