rails_steroids 0.3.1 → 0.5.0
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/CHANGELOG.md +9 -0
- data/README.md +10 -6
- data/lib/generators/steroid/controller/USAGE +17 -0
- data/lib/generators/steroid/controller/controller_generator.rb +40 -0
- data/lib/generators/steroid/model/USAGE +22 -0
- data/lib/generators/steroid/model/model_generator.rb +77 -0
- data/lib/generators/steroid/new_project/USAGE +1 -1
- data/lib/generators/steroid/steroid_generator.rb +2 -2
- data/lib/rails_steroids/cli.rb +2 -0
- data/lib/rails_steroids/version.rb +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 575fafaef4cda7385ace12ae8c8c6ba3469ca6a8720eb54692240a79739ca6c1
|
4
|
+
data.tar.gz: 764ba190e5246e78820af6bae9598ab498258133b513f0cc26f7767bd90bb2ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73d18703d85c492632f3348941505cd748ff34855f4b293a8127128a5c278b07e7716b1e5f9754d296560846f0ce0304b23e7d0452a71b60b2f119d375a3453b
|
7
|
+
data.tar.gz: c9e6807f7f94a24e956ba7f1e7c8d0348495168c761f149cb8b573a7882f6bbfd823b90dcde840ffc4fa5ea4a8fea2c801f01d398936b60a5a8a9776fcb06492
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.5.0] - 2024-02-06
|
4
|
+
|
5
|
+
- New steroid recipe: model (Create new model interactively)
|
6
|
+
|
7
|
+
## [0.4.0] - 2024-02-06
|
8
|
+
|
9
|
+
- New steroid recipe: controller (Create new controller interactively)
|
10
|
+
- Documentation improvement
|
11
|
+
|
3
12
|
## [0.3.1] - 2024-02-06
|
4
13
|
|
5
14
|
- Improvement in steroid recipe new_project : Code improvement (variable name for boolean_choices)
|
data/README.md
CHANGED
@@ -11,9 +11,9 @@
|
|
11
11
|
|
12
12
|
Any small idea evolves when it actually starts taking shape. But most of the time, when we think of developing an idea as a POC or hobby project, we end up spending more time in setting up the project and lose the momentum. And you must have realised that many tasks that we do with a new project from scratch are quite repetitive.
|
13
13
|
|
14
|
-
Rails templates and other templating gems are a way of quickly generating an application but when it comes to adding some features in an already generated application then we need some way to do that. We have certain inbuilt generators which can be used for basic components but they need more coding over it.
|
14
|
+
Rails templates and other templating gems are a way of quickly generating an application but when it comes to adding some features in an already generated application then we need some way to do that. We have certain inbuilt generators which can be used for basic components but they need more coding over it. Also remembering options is a also a task or you will have to go through documentation to select options to be provided to generators.
|
15
15
|
|
16
|
-
So here are steroids for your application, which are actually generators with special powers. This gem contains different steroids which will setup commonly used features very quickly and reduce your coding work so that you can focus on your precious idea.
|
16
|
+
So here are steroids for your application, which are actually generators with special powers. This gem contains different steroids which will run generators interactively help you choose options and so you will not have to remember them. Going forward the gem will also contain steroids which will setup commonly used features and functionalities from gems very quickly and reduce your coding work so that you can focus on your precious idea. Using these steroids is also very good for those who are learning Rails newly as you get to use generators interactively
|
17
17
|
|
18
18
|
## Installation
|
19
19
|
|
@@ -33,20 +33,24 @@ gem install rails_steroids
|
|
33
33
|
## Usage
|
34
34
|
|
35
35
|
You can use the gem from command line using gem's CLI.
|
36
|
-
You can inject the steroid into your application using command like:
|
37
|
-
```
|
38
|
-
rails_steroids inject steroid:STEROID_NAME
|
39
|
-
```
|
40
36
|
|
41
37
|
You can check the list of available steroids using command:
|
42
38
|
```
|
43
39
|
rails_steroids list
|
44
40
|
```
|
45
41
|
|
42
|
+
You can inject the steroid into your application using command like:
|
43
|
+
```
|
44
|
+
rails_steroids inject steroid:STEROID_NAME
|
45
|
+
```
|
46
|
+
and then enjoy easily entering or selecting options interactively to the questions asked on terminal.
|
47
|
+
|
46
48
|
## Available Steroids
|
47
49
|
|
48
50
|
| Functionality | Command |
|
49
51
|
|---|---|
|
52
|
+
|model|`rails_steroids inject steroid:model`|
|
53
|
+
|controller|`rails_steroids inject steroid:controller`|
|
50
54
|
|new_project|`rails_steroids inject steroid:new_project`|
|
51
55
|
|
52
56
|
## Development
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Description:
|
2
|
+
`steroid:controller` will create Controller interactively.
|
3
|
+
|
4
|
+
Usage Example:
|
5
|
+
# with installed gem
|
6
|
+
rails_steroids inject steroid:controller
|
7
|
+
# with bundler
|
8
|
+
bin/rails g steroid:controller
|
9
|
+
|
10
|
+
What will this do?:
|
11
|
+
Create new Rails controller with configurations selected interactively.
|
12
|
+
Current options available to customize are:
|
13
|
+
* Controller name
|
14
|
+
* Choose from actions: index, show, new, edit, create, update, destroy
|
15
|
+
* Specify any custom/additional actions
|
16
|
+
* Skip adding routes
|
17
|
+
* Skip creating helper
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tty/prompt'
|
4
|
+
|
5
|
+
module Steroid
|
6
|
+
class ControllerGenerator < Rails::Generators::Base
|
7
|
+
desc "Adds Controller to the application"
|
8
|
+
source_root File.expand_path("templates", __dir__)
|
9
|
+
|
10
|
+
def add_controller
|
11
|
+
say "Injecting steroid: Controller", :green
|
12
|
+
cmd = ["rails generate controller"]
|
13
|
+
prompt = TTY::Prompt.new
|
14
|
+
controller_name = prompt.ask("What is the great name of your controller?") do |q|
|
15
|
+
q.required true
|
16
|
+
q.modify :remove
|
17
|
+
end
|
18
|
+
cmd << controller_name
|
19
|
+
|
20
|
+
actions = prompt.multi_select("Choose actions:", %w(index show new edit create update destroy))
|
21
|
+
cmd += actions
|
22
|
+
|
23
|
+
boolean_choices = [{name: "yes", value: true}, {name: "no", value: false}]
|
24
|
+
|
25
|
+
custom_actions = []
|
26
|
+
while prompt.select("Would you like to add more actions?", boolean_choices)
|
27
|
+
custom_actions << prompt.ask("Specify name of action:") do |q|
|
28
|
+
q.required true
|
29
|
+
q.modify :remove
|
30
|
+
end
|
31
|
+
end
|
32
|
+
cmd += custom_actions
|
33
|
+
|
34
|
+
cmd << "--skip-routes" if prompt.select("Skip routes?", boolean_choices)
|
35
|
+
cmd << "--no-helper" if prompt.select("Skip helper?", boolean_choices)
|
36
|
+
|
37
|
+
run cmd.join(" ")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Description:
|
2
|
+
`steroid:model` will create Model interactively.
|
3
|
+
|
4
|
+
Usage Example:
|
5
|
+
# with installed gem
|
6
|
+
rails_steroids inject steroid:model
|
7
|
+
# with bundler
|
8
|
+
bin/rails g steroid:model
|
9
|
+
|
10
|
+
What will this do?:
|
11
|
+
Create new Rails model with configurations selected interactively.
|
12
|
+
Current options available to customize are:
|
13
|
+
* Model name
|
14
|
+
* Specify columns with column type and some other metadata
|
15
|
+
* Column metadata includes:
|
16
|
+
- limit for integer, string, text, binary
|
17
|
+
- precision and scale for decimal
|
18
|
+
- polymorphic for references
|
19
|
+
- index and unique index
|
20
|
+
* Skip creating migration?
|
21
|
+
* Skip created_at, updated_at timestamps?
|
22
|
+
* Skip indexes?
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tty/prompt'
|
4
|
+
|
5
|
+
module Steroid
|
6
|
+
class ModelGenerator < Rails::Generators::Base
|
7
|
+
desc "Adds Model to the application"
|
8
|
+
source_root File.expand_path("templates", __dir__)
|
9
|
+
|
10
|
+
def add_model
|
11
|
+
say "Injecting steroid: Model", :green
|
12
|
+
cmd = ["rails generate model"]
|
13
|
+
prompt = TTY::Prompt.new
|
14
|
+
model_name = prompt.ask("What is the great name of your model?") do |q|
|
15
|
+
q.required true
|
16
|
+
q.modify :remove
|
17
|
+
end
|
18
|
+
cmd << model_name
|
19
|
+
|
20
|
+
boolean_choices = [{name: "yes", value: true}, {name: "no", value: false}]
|
21
|
+
|
22
|
+
columns = []
|
23
|
+
while prompt.select("Would you like to add model attributes(columns)?", boolean_choices)
|
24
|
+
|
25
|
+
column_name = prompt.ask("Specify name of column:") do |q|
|
26
|
+
q.required true
|
27
|
+
q.modify :remove
|
28
|
+
end
|
29
|
+
|
30
|
+
column_type = prompt.select("Choose type of column:", %w(references integer decimal float boolean binary string text date time datetime primary_key digest token))
|
31
|
+
|
32
|
+
if column_type == 'references'
|
33
|
+
column_type = "#{column_type}{polymorphic}" if prompt.select("Polymorphic association?", boolean_choices)
|
34
|
+
end
|
35
|
+
if %w(integer string text binary).include?(column_type)
|
36
|
+
if prompt.select("Set limit?", boolean_choices)
|
37
|
+
limit = prompt.ask("Specify limit:") do |q|
|
38
|
+
q.required true
|
39
|
+
q.modify :remove
|
40
|
+
q.convert(:int, "Invalid input! Please provide integer value.")
|
41
|
+
end
|
42
|
+
column_type = "#{column_type}{#{limit}}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
if column_type == 'decimal'
|
46
|
+
if prompt.select("Set precision & scale?", boolean_choices)
|
47
|
+
precision = prompt.ask("Specify precision:") do |q|
|
48
|
+
q.required true
|
49
|
+
q.modify :remove
|
50
|
+
q.convert(:int, "Invalid input! Please provide integer value.")
|
51
|
+
end
|
52
|
+
scale = prompt.ask("Specify scale:") do |q|
|
53
|
+
q.required true
|
54
|
+
q.modify :remove
|
55
|
+
q.convert(:int, "Invalid input! Please provide integer value.")
|
56
|
+
end
|
57
|
+
column_type = "'#{column_type}{#{precision},#{scale}}'"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
index_option = nil
|
62
|
+
if prompt.select("Add index?", boolean_choices)
|
63
|
+
index_option = prompt.select("Unique index?", boolean_choices) ? 'uniq' : 'index'
|
64
|
+
end
|
65
|
+
|
66
|
+
columns << [column_name, column_type, index_option].compact.join(':')
|
67
|
+
end
|
68
|
+
cmd += columns
|
69
|
+
|
70
|
+
cmd << "--no-migration" if prompt.select("Skip migration?", boolean_choices)
|
71
|
+
cmd << "--no-timestamps" if prompt.select("Skip created_at, updated_at timestamps?", boolean_choices)
|
72
|
+
cmd << "--no-indexes" if prompt.select("Skip indexes?", boolean_choices)
|
73
|
+
|
74
|
+
run cmd.join(" ")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -28,7 +28,7 @@ class SteroidGenerator < Rails::Generators::NamedBase
|
|
28
28
|
def create_usage_file
|
29
29
|
create_file "lib/generators/steroid/#{name}/USAGE", <<~RUBY
|
30
30
|
Description:
|
31
|
-
`steroid:#{name}` will inject #{name.titlecase} functionality.
|
31
|
+
`steroid:#{name}` will inject #{name.titlecase} functionality interactively.
|
32
32
|
|
33
33
|
Usage Example:
|
34
34
|
# with installed gem
|
@@ -36,7 +36,7 @@ class SteroidGenerator < Rails::Generators::NamedBase
|
|
36
36
|
# with bundler
|
37
37
|
bin/rails g steroid:#{name}
|
38
38
|
|
39
|
-
|
39
|
+
What will this do?:
|
40
40
|
what/will/it/create
|
41
41
|
RUBY
|
42
42
|
end
|
data/lib/rails_steroids/cli.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_steroids
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anand Bait
|
@@ -104,6 +104,10 @@ files:
|
|
104
104
|
- bin/console
|
105
105
|
- bin/rails_steroids
|
106
106
|
- bin/setup
|
107
|
+
- lib/generators/steroid/controller/USAGE
|
108
|
+
- lib/generators/steroid/controller/controller_generator.rb
|
109
|
+
- lib/generators/steroid/model/USAGE
|
110
|
+
- lib/generators/steroid/model/model_generator.rb
|
107
111
|
- lib/generators/steroid/new_project/USAGE
|
108
112
|
- lib/generators/steroid/new_project/new_project_generator.rb
|
109
113
|
- lib/generators/steroid/steroid_generator.rb
|