Skip to content

Commit 7b55f85

Browse files
authored
RailsInteractive::CLI - New Structure (#68)
* init: yaml gem * move: templates moved to new folder * move: current classes moved to new folder * feat: utils class for helper methods * add: pry gem for console * feat: commands class * feat: commands yml file * feat: categories * add: new rubocop rule * add: new utils methods * update: ascii message * update: new structure * update: new rubocop rule * update: path fix * update: cli structure * update: typo * update: friendly_id * update: gemspec structure * update: yml files directory * update: gemfile * remove: ignore version test
1 parent 418a518 commit 7b55f85

38 files changed

+467
-240
lines changed

.rubocop.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ Style/StringLiteralsInInterpolation:
1111

1212
Layout/LineLength:
1313
Max: 120
14+
15+
Style/Documentation:
16+
Enabled: false
17+
18+
Metrics/MethodLength:
19+
Max: 12
20+
21+
Metrics/CyclomaticComplexity:
22+
Max: 25

Gemfile.lock

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ GEM
7575
ast (2.4.2)
7676
builder (3.2.4)
7777
byebug (11.1.3)
78+
coderay (1.1.3)
7879
colorize (0.8.1)
7980
concurrent-ruby (1.1.10)
8081
crass (1.0.6)
@@ -118,8 +119,11 @@ GEM
118119
ast (~> 2.4.1)
119120
pastel (0.8.0)
120121
tty-color (~> 0.5)
122+
pry (0.14.1)
123+
coderay (~> 1.1)
124+
method_source (~> 1.0)
121125
racc (1.6.0)
122-
rack (2.2.3)
126+
rack (2.2.3.1)
123127
rack-test (1.1.0)
124128
rack (>= 1.0, < 3)
125129
rails (7.0.3)
@@ -150,7 +154,7 @@ GEM
150154
zeitwerk (~> 2.5)
151155
rainbow (3.1.1)
152156
rake (13.0.6)
153-
regexp_parser (2.4.0)
157+
regexp_parser (2.5.0)
154158
rexml (3.2.5)
155159
rspec (3.11.0)
156160
rspec-core (~> 3.11.0)
@@ -165,21 +169,21 @@ GEM
165169
diff-lcs (>= 1.2.0, < 2.0)
166170
rspec-support (~> 3.11.0)
167171
rspec-support (3.11.0)
168-
rubocop (1.29.1)
172+
rubocop (1.30.0)
169173
parallel (~> 1.10)
170174
parser (>= 3.1.0.0)
171175
rainbow (>= 2.2.2, < 4.0)
172176
regexp_parser (>= 1.8, < 3.0)
173177
rexml (>= 3.2.5, < 4.0)
174-
rubocop-ast (>= 1.17.0, < 2.0)
178+
rubocop-ast (>= 1.18.0, < 2.0)
175179
ruby-progressbar (~> 1.7)
176180
unicode-display_width (>= 1.4.0, < 3.0)
177181
rubocop-ast (1.18.0)
178182
parser (>= 3.1.1.0)
179183
ruby-progressbar (1.11.0)
180184
strscan (3.0.3)
181185
thor (1.2.1)
182-
timeout (0.2.0)
186+
timeout (0.3.0)
183187
tty-color (0.6.0)
184188
tty-cursor (0.7.1)
185189
tty-prompt (0.23.1)
@@ -197,6 +201,7 @@ GEM
197201
websocket-extensions (>= 0.1.0)
198202
websocket-extensions (0.1.5)
199203
wisper (2.0.1)
204+
yaml (0.2.0)
200205
zeitwerk (2.5.4)
201206

202207
PLATFORMS
@@ -207,12 +212,14 @@ DEPENDENCIES
207212
bundler
208213
byebug (~> 11.1.2)
209214
colorize
215+
pry
210216
rails
211217
rails-interactive!
212218
rake (~> 13.0)
213219
rspec (~> 3.0)
214220
rubocop (~> 1.7)
215221
tty-prompt
222+
yaml
216223

217224
BUNDLED WITH
218225
2.2.22

bin/console

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,5 @@
44
require "bundler/setup"
55
require "rails_interactive"
66

7-
# You can add fixtures and/or initialization code here to make experimenting
8-
# with your gem easier. You can also use a different console, if you like.
9-
10-
# (If you use this, don't forget to add pry to your Gemfile!)
11-
# require "pry"
12-
# Pry.start
13-
14-
require "irb"
15-
IRB.start(__FILE__)
7+
require "pry"
8+
Pry.start

lib/cli/categories.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
require "yaml"
4+
5+
module RailsInteractive
6+
class CLI
7+
# Categories class for the interactive CLI module
8+
class Categories
9+
def initialize
10+
@categories = YAML.load_file("#{__dir__}/config/categories.yml").uniq
11+
end
12+
13+
def all
14+
@categories.sort_by { |category| category["weight"] }
15+
end
16+
end
17+
end
18+
end

lib/cli/commands.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
require "yaml"
4+
5+
module RailsInteractive
6+
class CLI
7+
# Commands class for the interactive CLI module
8+
class Commands
9+
def initialize
10+
@commands = YAML.load_file("#{__dir__}/config/commands.yml").uniq
11+
end
12+
13+
def all
14+
@commands
15+
end
16+
17+
def find_by_identifier(identifier)
18+
@commands.find { |command| command["identifier"] == identifier }
19+
end
20+
end
21+
end
22+
end

lib/cli/config/categories.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
-
3+
name: authentication
4+
weight: 1
5+
type: "multi_select"
6+
required: false
7+
-
8+
name: authorization
9+
weight: 2
10+
type: "select"
11+
required: false
12+
-
13+
name: testing
14+
weight: 3
15+
type: "select"
16+
required: false
17+
-
18+
name: template_engine
19+
weight: 4
20+
type: "select"
21+
required: false
22+
-
23+
name: code_quality
24+
weight: 5
25+
type: "select"
26+
required: false
27+
-
28+
name: background_job
29+
weight: 6
30+
type: "select"
31+
required: false
32+
-
33+
name: security
34+
weight: 7
35+
type: "select"
36+
required: false
37+
-
38+
name: admin_panel
39+
weight: 8
40+
type: "select"
41+
required: false
42+
-
43+
name: features
44+
weight: 9
45+
type: "multi_select"
46+
required: false
47+
-
48+
name: development
49+
weight: 10
50+
type: "multi_select"
51+
required: false

lib/cli/config/commands.yml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
-
3+
identifier: rubocop
4+
name: Rubocop
5+
category: code_quality
6+
description: "A Ruby static code analyzer and formatter, based on the community Ruby style guide. For details: https://github.com/rubocop/rubocop"
7+
dependencies: null
8+
-
9+
identifier: graphql
10+
name: GraphQL
11+
category: features
12+
description: "Ruby implementation of GraphQL. For details: https://github.com/rmosolgo/graphql-ruby"
13+
dependencies: null
14+
-
15+
identifier: avo
16+
name: Avo
17+
category: admin_panel
18+
description: "Configuration-based, no-maintenance, extendable Ruby on Rails admin. For details: https://github.com/avo-hq/avo"
19+
dependencies: null
20+
-
21+
identifier: awesome_print
22+
name: AwesomePrint
23+
category: development
24+
description: "Pretty print your Ruby objects with style. For details: https://github.com/awesome-print/awesome_print"
25+
dependencies: null
26+
-
27+
identifier: better_errors
28+
name: BetterErrors
29+
category: development
30+
description: "Better error page for Rack apps. For details: https://github.com/BetterErrors/better_errors"
31+
dependencies: null
32+
-
33+
identifier: brakeman
34+
name: Brakeman
35+
category: security
36+
description: "A static analysis security vulnerability scanner for Ruby on Rails applications. For details: https://github.com/presidentbeef/brakeman"
37+
dependencies: null
38+
-
39+
identifier: bullet
40+
name: Bullet
41+
category: development
42+
description: "Bullet helps to solve N+1 queries and unused eager loading. For details: https://github.com/flyerhzm/bullet"
43+
dependencies: null
44+
-
45+
identifier: cancancan
46+
name: CanCanCan
47+
category: authorization
48+
description: "CanCanCan is an authorization library for Ruby and Ruby on Rails which restricts what resources a given user is allowed to access. For details: https://github.com/CanCanCommunity/cancancan"
49+
dependencies: null
50+
-
51+
identifier: devise
52+
name: Devise
53+
category: authentication
54+
description: "Flexible authentication solution for Rails with Warden. For details: https://github.com/heartcombo/devise"
55+
dependencies: null
56+
-
57+
identifier: faker
58+
name: Faker
59+
category: development
60+
description: "A library for generating fake data such as names, addresses, and phone numbers. For details: https://github.com/faker-ruby/faker"
61+
dependencies: null
62+
-
63+
identifier: friendly_id
64+
name: FriendlyID
65+
category: development
66+
description: "FriendlyId is the 'Swiss Army bulldozer' of slugging and permalink plugins for Active Record. It lets you create pretty URLs and work with human-friendly strings as if they were numeric ids. For details: https://github.com/norman/friendly_id"
67+
dependencies: null
68+
-
69+
identifier: haml
70+
name: Haml
71+
category: template_engine
72+
description: "HTML Abstraction Markup Language. For details: https://github.com/haml/haml"
73+
dependencies: null
74+
-
75+
identifier: kaminari
76+
name: Kaminari
77+
category: features
78+
description: "A Scope & Engine based, clean, powerful, customizable and sophisticated paginator for Ruby webapps. For details: https://github.com/kaminari/kaminari"
79+
dependencies: null
80+
-
81+
identifier: letter_opener
82+
name: LetterOpener
83+
category: development
84+
description: "Preview email in the default browser instead of sending it on development mode. For details: https://github.com/ryanb/letter_opener"
85+
dependencies: null
86+
-
87+
identifier: omniauth
88+
name: OmniAuth
89+
category: authentication
90+
description: "OmniAuth is a flexible authentication system utilizing Rack middleware. For details: https://github.com/omniauth/omniauth"
91+
dependencies:
92+
- devise
93+
-
94+
identifier: pundit
95+
name: Pundit
96+
category: authorization
97+
description: "Minimal authorization through OO design and pure Ruby classes. For details: https://github.com/varvet/pundit"
98+
dependencies: null
99+
-
100+
identifier: rails_admin
101+
name: RailsAdmin
102+
category: admin_panel
103+
description: "RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data. For details: https://github.com/railsadminteam/rails_admin"
104+
dependencies: null
105+
-
106+
identifier: rspec
107+
name: RSpec
108+
category: testing
109+
description: "A unit test framework for the Ruby programming language. For details: https://github.com/rspec"
110+
dependencies: null
111+
-
112+
identifier: sidekiq
113+
name: Sidekiq
114+
category: background_job
115+
description: "Simple, efficient background processing for Ruby. For details: https://github.com/mperham/sidekiq"
116+
dependencies: null
117+
-
118+
identifier: slim
119+
name: Slim
120+
category: template_engine
121+
description: "Slim is a template language whose goal is to reduce the syntax to the essential parts without becoming cryptic. For details: https://github.com/slim-template/slim"
122+
dependencies: null
123+
-
124+
identifier: standart_rb
125+
name: StandartRB
126+
category: code_quality
127+
description: " Ruby Style Guide, with linter & automatic code fixer. For details: https://github.com/testdouble/standard"
128+
dependencies: null

lib/cli/message.rb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# frozen_string_literal: true
2+
3+
require "colorize"
4+
5+
module RailsInteractive
6+
class CLI
7+
# Utils class for the interactive CLI module
8+
class Message
9+
def self.greet
10+
render_ascii
11+
puts "Welcome to Rails Interactive CLI".colorize(:yellow)
12+
end
13+
14+
def self.help
15+
puts "bin/interactive new - Create a new Rails Project".colorize(:yellow)
16+
puts "bin/interactive help - List all commands".colorize(:yellow)
17+
exit
18+
end
19+
20+
def self.render_ascii
21+
# rubocop:disable Naming/HeredocDelimiterNaming
22+
puts <<-'EOF'
23+
_____ _ _ _____ _ _ _
24+
| __ \ (_) | |_ _| | | | | (_)
25+
| |__) |__ _ _| |___ | | _ __ | |_ ___ _ __ __ _ ___| |_ ___ _____
26+
| _ // _` | | / __| | | | '_ \| __/ _ \ '__/ _` |/ __| __| \ \ / / _ \
27+
| | \ \ (_| | | \__ \_| |_| | | | || __/ | | (_| | (__| |_| |\ V / __/
28+
|_| \_\__,_|_|_|___/_____|_| |_|\__\___|_| \__,_|\___|\__|_| \_/ \___|
29+
30+
EOF
31+
# rubocop:enable Naming/HeredocDelimiterNaming
32+
end
33+
34+
def self.prepare
35+
puts ""
36+
puts "Project created successfully ✅".colorize(:green)
37+
puts "Go to your project folder and ready to go 🎉".colorize(:green)
38+
rails_commands
39+
end
40+
41+
def self.rails_commands
42+
puts "You can run several commands:".colorize(:green)
43+
44+
puts "Starts the webpack development server".colorize(:cyan)
45+
puts "> bin/webpack-dev-server".colorize(:yellow)
46+
47+
puts "Starts the rails server".colorize(:cyan)
48+
puts "> bin/rails s or bin/rails server".colorize(:yellow)
49+
50+
puts "Starts the rails console".colorize(:cyan)
51+
puts "> bin/rails c or bin/rails console".colorize(:yellow)
52+
end
53+
end
54+
end
55+
end

0 commit comments

Comments
 (0)