rails-interactive 0.1.4 → 0.1.7
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/.github/FUNDING.yml +3 -0
- data/Gemfile.lock +3 -3
- data/lib/rails_interactive/templates/setup_avo.rb +10 -0
- data/lib/rails_interactive/templates/setup_brakeman.rb +6 -0
- data/lib/rails_interactive/templates/setup_cancancan.rb +7 -0
- data/lib/rails_interactive/templates/setup_omniauth.rb +61 -0
- data/lib/rails_interactive/templates/setup_pundit.rb +15 -0
- data/lib/rails_interactive/templates/setup_rails_admin.rb +10 -0
- data/lib/rails_interactive/templates/setup_rspec.rb +13 -0
- data/lib/rails_interactive/templates/setup_rubocop.rb +10 -0
- data/lib/rails_interactive/templates/setup_sidekiq.rb +32 -0
- data/lib/rails_interactive/templates/setup_standardrb.rb +10 -0
- data/lib/rails_interactive/version.rb +1 -1
- data/lib/rails_interactive.rb +70 -14
- metadata +13 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6afcb39a24c3349eeb1612c9718ec6eac30719daf817adba40db94cdb75b09f9
|
4
|
+
data.tar.gz: '0981f8d0e62091899e86bc90cefe2bb8bd6ad54830bc46f8ba87e6b85cfd201b'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c000dc682e8459d7909ade1944799cf9106dba51eda6158d1106ff5f065f381ee3633b4521dbc51af949442e334fa289e9199f3d43e72be477cc112259ac0506
|
7
|
+
data.tar.gz: a909ff4109ea75853bfbfb7e4a1343c1812d8c2c4c9accfb92da62fb2dd5fee71d15406879e612a2e433d59bf0b591d726ddeb0a513aa5f9c057d9f95642b477
|
data/.github/FUNDING.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rails-interactive (0.1.
|
4
|
+
rails-interactive (0.1.6)
|
5
5
|
tty-prompt
|
6
6
|
|
7
7
|
GEM
|
@@ -111,9 +111,9 @@ GEM
|
|
111
111
|
net-protocol
|
112
112
|
timeout
|
113
113
|
nio4r (2.5.8)
|
114
|
-
nokogiri (1.13.
|
114
|
+
nokogiri (1.13.4-x86_64-darwin)
|
115
115
|
racc (~> 1.4)
|
116
|
-
nokogiri (1.13.
|
116
|
+
nokogiri (1.13.4-x86_64-linux)
|
117
117
|
racc (~> 1.4)
|
118
118
|
parallel (1.21.0)
|
119
119
|
parser (3.1.1.0)
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
run "rails db:prepare"
|
4
|
+
run "bundle add avo"
|
5
|
+
|
6
|
+
Bundler.with_unbundled_env { run "bundle install" }
|
7
|
+
|
8
|
+
rails_command("generate avo:install")
|
9
|
+
|
10
|
+
puts "Avo is installed! You can go to http://localhost:3000/avo for next steps"
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
run "bundle add omniauth"
|
4
|
+
|
5
|
+
run "bundle install"
|
6
|
+
|
7
|
+
# rubocop:disable Layout/LineLength
|
8
|
+
rails_command "generate model identity user:references provider:string:index uid:string:index token:string:index refresh_token:string:index"
|
9
|
+
# rubocop:enable Layout/LineLength
|
10
|
+
|
11
|
+
rails_command "generate migration AddIdentityToUsers identities_count:integer"
|
12
|
+
|
13
|
+
rails_command "db:migrate"
|
14
|
+
|
15
|
+
inject_into_file "config/routes.rb", after: "devise_for :users\n" do
|
16
|
+
" # devise_for :users, controllers: { omniauth_callbacks: 'omniauth' }"
|
17
|
+
end
|
18
|
+
|
19
|
+
inject_into_file "app/models/user.rb", after: ":database_authenticatable, " do
|
20
|
+
":omniauthable, "
|
21
|
+
end
|
22
|
+
|
23
|
+
inject_into_file "app/models/identity.rb", after: "belongs_to :user" do
|
24
|
+
", counter_cache: true"
|
25
|
+
end
|
26
|
+
|
27
|
+
inject_into_file "app/models/user.rb", after: "class User < ApplicationRecord\n" do
|
28
|
+
# rubocop:disable Naming/HeredocDelimiterNaming
|
29
|
+
<<-EOF
|
30
|
+
has_many :identities, dependent: :destroy
|
31
|
+
|
32
|
+
def self.from_omniauth(auth)
|
33
|
+
if auth.present? && auth.provider.present? && auth.uid.present?
|
34
|
+
identity = Identity.where(provider: auth.provider, uid: auth.uid).first_or_initialize
|
35
|
+
if auth.credentials.present?
|
36
|
+
identity.token = auth.credentials.token
|
37
|
+
identity.refresh_token = auth.credentials.refresh_token
|
38
|
+
end
|
39
|
+
if identity.user.nil? && auth.info.email.present?
|
40
|
+
user = User.where(email: auth.info.email).first_or_initialize
|
41
|
+
user.name = auth.info.name
|
42
|
+
user.password = Devise.friendly_token if user.new_record?
|
43
|
+
user.save!
|
44
|
+
identity.user = user
|
45
|
+
end
|
46
|
+
identity.save!
|
47
|
+
identity.user
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
EOF
|
52
|
+
# rubocop:enable Naming/HeredocDelimiterNaming
|
53
|
+
end
|
54
|
+
|
55
|
+
file "app/controllers/omniauth_controller.rb", <<~CODE
|
56
|
+
class OmniauthController < Devise::OmniauthCallbacksController
|
57
|
+
|
58
|
+
end
|
59
|
+
CODE
|
60
|
+
|
61
|
+
puts "IMPORTANT: Add devise_for :users, controllers: { omniauth_callbacks: 'omniauth' } to your routes.rb"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
run "bundle add pundit"
|
4
|
+
|
5
|
+
puts "Add - Pundit module to Application Controller"
|
6
|
+
puts ""
|
7
|
+
|
8
|
+
inject_into_file "app/controllers/application_controller.rb",
|
9
|
+
after: "class ApplicationController < ActionController::Base\n" do
|
10
|
+
" include Pundit\n"
|
11
|
+
end
|
12
|
+
|
13
|
+
puts "Run - Pundit Generator"
|
14
|
+
|
15
|
+
rails_command("generate pundit:install")
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
run "rails db:prepare"
|
4
|
+
run "bundle add rails_admin"
|
5
|
+
|
6
|
+
Bundler.with_unbundled_env { run "bundle install" }
|
7
|
+
|
8
|
+
rails_command("generate rails_admin:install")
|
9
|
+
|
10
|
+
puts "RailsAdmin is installed! You can go to your admin panel at /admin"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
def file_contains?(filename, string)
|
4
|
+
File.foreach(filename).detect { |line| line.include?(string) }
|
5
|
+
end
|
6
|
+
|
7
|
+
run "bundle add sidekiq"
|
8
|
+
run "bundle add redis" unless file_contains? "Gemfile", "Gem 'redis'"
|
9
|
+
|
10
|
+
Bundler.with_unbundled_env { run "bundle install" }
|
11
|
+
|
12
|
+
# rubocop:disable Naming/HeredocDelimiterNaming
|
13
|
+
application do
|
14
|
+
<<~EOF
|
15
|
+
config.active_job.queue_adapter = :sidekiq
|
16
|
+
EOF
|
17
|
+
end
|
18
|
+
|
19
|
+
inject_into_file "config/routes.rb" do
|
20
|
+
<<~EOF
|
21
|
+
require "sidekiq/web"
|
22
|
+
if Rails.env.production?
|
23
|
+
Sidekiq::Web.use Rack::Auth::Basic do |username, password|
|
24
|
+
ActiveSupport::SecurityUtils.secure_compare(::Digest::SHA256.hexdigest(username), ::Digest::SHA256.hexdigest(ENV["SIDEKIQ_USERNAME"])) &
|
25
|
+
ActiveSupport::SecurityUtils.secure_compare(::Digest::SHA256.hexdigest(password), ::Digest::SHA256.hexdigest(ENV["SIDEKIQ_PASSWORD"]))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
EOF
|
29
|
+
end
|
30
|
+
# rubocop:enable Naming/HeredocDelimiterNaming
|
31
|
+
|
32
|
+
route 'mount Sidekiq::Web => "/sidekiq"'
|
data/lib/rails_interactive.rb
CHANGED
@@ -24,16 +24,13 @@ module RailsInteractive
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def initialize_project
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
features = %w[devise]
|
36
|
-
@inputs[:features] = Prompt.new("Choose project features: ", "multi_select", features).perform
|
27
|
+
name
|
28
|
+
type
|
29
|
+
database
|
30
|
+
features
|
31
|
+
code_quality_tool
|
32
|
+
admin_panel
|
33
|
+
testing_tools
|
37
34
|
|
38
35
|
create
|
39
36
|
end
|
@@ -48,9 +45,18 @@ module RailsInteractive
|
|
48
45
|
|
49
46
|
# Move to project folder and install gems
|
50
47
|
Dir.chdir "./#{@inputs[:name]}"
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
|
49
|
+
# Features Templates
|
50
|
+
handle_multi_options(key: :features)
|
51
|
+
|
52
|
+
# Code Quality Template
|
53
|
+
system("bin/rails app:template LOCATION=templates/setup_#{@inputs[:code_quality_tool]}.rb")
|
54
|
+
|
55
|
+
# Admin Panel Template
|
56
|
+
system("bin/rails app:template LOCATION=templates/setup_#{@inputs[:admin_panel]}.rb")
|
57
|
+
|
58
|
+
# Testing tools Template
|
59
|
+
handle_multi_options(key: :testing_tools)
|
54
60
|
|
55
61
|
# Prepare project requirements and give instructions
|
56
62
|
Message.prepare
|
@@ -60,7 +66,7 @@ module RailsInteractive
|
|
60
66
|
base = "rails new"
|
61
67
|
cmd = ""
|
62
68
|
|
63
|
-
@inputs.each { |_key, value| cmd += "#{value} " }
|
69
|
+
@inputs.first(3).each { |_key, value| cmd += "#{value} " }
|
64
70
|
|
65
71
|
"#{base} #{cmd}".strip!
|
66
72
|
end
|
@@ -68,5 +74,55 @@ module RailsInteractive
|
|
68
74
|
def copy_templates_to_project
|
69
75
|
FileUtils.cp_r "#{__dir__}/rails_interactive/templates", "./#{@inputs[:name]}"
|
70
76
|
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def handle_multi_options(key:)
|
81
|
+
@inputs[key].each do |value|
|
82
|
+
system("bin/rails app:template LOCATION=templates/setup_#{value}.rb")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def name
|
87
|
+
@inputs[:name] = Prompt.new("Enter the name of the project: ", "ask", required: true).perform
|
88
|
+
end
|
89
|
+
|
90
|
+
def type
|
91
|
+
types = { "App" => "", "API" => "--api" }
|
92
|
+
@inputs[:type] = Prompt.new("Choose project type: ", "select", types, required: true).perform
|
93
|
+
end
|
94
|
+
|
95
|
+
def database
|
96
|
+
database_types = { "PostgreSQL" => "-d postgresql", "MySQL" => "-d mysql", "SQLite" => "" }
|
97
|
+
|
98
|
+
@inputs[:database] = Prompt.new("Choose project's database: ", "select", database_types, required: true).perform
|
99
|
+
end
|
100
|
+
|
101
|
+
def features
|
102
|
+
features = %w[devise cancancan omniauth pundit brakeman sidekiq]
|
103
|
+
|
104
|
+
@inputs[:features] = Prompt.new("Choose project features: ", "multi_select", features).perform
|
105
|
+
end
|
106
|
+
|
107
|
+
def code_quality_tool
|
108
|
+
code_quality_tool = { "Rubocop" => "rubocop", "StandardRB" => "standardrb" }
|
109
|
+
|
110
|
+
@inputs[:code_quality_tool] =
|
111
|
+
Prompt.new("Choose project code quality tool: ", "select", code_quality_tool).perform
|
112
|
+
end
|
113
|
+
|
114
|
+
def admin_panel
|
115
|
+
admin_panel = { "RailsAdmin" => "rails_admin", "Avo" => "avo" }
|
116
|
+
|
117
|
+
@inputs[:admin_panel] =
|
118
|
+
Prompt.new("Choose project's admin panel: ", "select", admin_panel).perform
|
119
|
+
end
|
120
|
+
|
121
|
+
def testing_tools
|
122
|
+
testing_tools = %w[rspec]
|
123
|
+
|
124
|
+
@inputs[:testing_tools] =
|
125
|
+
Prompt.new("Choose project's testing tools: ", "multi_select", testing_tools).perform
|
126
|
+
end
|
71
127
|
end
|
72
128
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-interactive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oguzhan Ince
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -118,6 +118,7 @@ executables:
|
|
118
118
|
extensions: []
|
119
119
|
extra_rdoc_files: []
|
120
120
|
files:
|
121
|
+
- ".github/FUNDING.yml"
|
121
122
|
- ".github/workflows/main.yml"
|
122
123
|
- ".github/workflows/rspec_rubocop.yml"
|
123
124
|
- ".gitignore"
|
@@ -136,7 +137,17 @@ files:
|
|
136
137
|
- lib/rails_interactive.rb
|
137
138
|
- lib/rails_interactive/message.rb
|
138
139
|
- lib/rails_interactive/prompt.rb
|
140
|
+
- lib/rails_interactive/templates/setup_avo.rb
|
141
|
+
- lib/rails_interactive/templates/setup_brakeman.rb
|
142
|
+
- lib/rails_interactive/templates/setup_cancancan.rb
|
139
143
|
- lib/rails_interactive/templates/setup_devise.rb
|
144
|
+
- lib/rails_interactive/templates/setup_omniauth.rb
|
145
|
+
- lib/rails_interactive/templates/setup_pundit.rb
|
146
|
+
- lib/rails_interactive/templates/setup_rails_admin.rb
|
147
|
+
- lib/rails_interactive/templates/setup_rspec.rb
|
148
|
+
- lib/rails_interactive/templates/setup_rubocop.rb
|
149
|
+
- lib/rails_interactive/templates/setup_sidekiq.rb
|
150
|
+
- lib/rails_interactive/templates/setup_standardrb.rb
|
140
151
|
- lib/rails_interactive/version.rb
|
141
152
|
- rails-interactive.gemspec
|
142
153
|
homepage: https://github.com/oguzsh/rails-interactive
|