rails-interactive 2.0.0 → 2.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bbe64281e0e3224cf7ca9a041eb42c42c7e69028406b7e10d3e60a9efbae743
4
- data.tar.gz: b69196bc79adb05559963c6f1cfee8fc2dda46fe795bf4c5449c35673080fa19
3
+ metadata.gz: d5f8f264844d295476f2a3a1b5321d4a24efd197385a3e46476b9e6912fdd35d
4
+ data.tar.gz: 0a305f3ddd4307d3380034b784d5a2e8f2e708c65be9039b5603e479a0e29fbd
5
5
  SHA512:
6
- metadata.gz: f72def1e7699e42baa285164308ef728d5c118bf7611972441242486c442d154d3ee00a8c3cf05a29c3eeb6aa453bb61a05f60c406880aa4942c8c64858593d5
7
- data.tar.gz: d53e7c764ca1ecbee3378a4304070ced64c18825b7f2ef7b53700612c442fced35128b05f8c4be6cbe12090a08784a5d9b747a0f0be4cf83f29412b30b604b8e
6
+ metadata.gz: 11ba30482ac8c3892b7c103fd2e11e4e92fe6cf9fad851f264e526d2af50c2e2203240aabe18b4fcdccf0846a6f5d9fbe5773990d11fef9100d2d40875346f64
7
+ data.tar.gz: e3b1de0b4b081528d4a0260531e0ec30814d55da0b5e543e0b4dcece30954a3376593be483f14ddb191c52cb4f0a7ea8da940acb008c3a21ccbee68b8e5454f6
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ mkmf.log
16
16
  *.gem
17
17
  # rspec failure tracking
18
18
  .rspec_status
19
+ .idea
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails-interactive (2.0.0)
4
+ rails-interactive (2.1.2)
5
5
  tty-prompt
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ![render1647134864886](https://user-images.githubusercontent.com/15168877/158041125-2ba863cf-ab17-4c8e-a603-7ccb0494938b.gif)
1
+ [![asciicast](https://asciinema.org/a/mFutWNTzym5aZPqK7AgBSMjLE.svg)](https://asciinema.org/a/mFutWNTzym5aZPqK7AgBSMjLE)
2
2
 
3
3
  # Rails::Interactive
4
4
  [![Gem Version](https://badge.fury.io/rb/rails-interactive.svg)](https://badge.fury.io/rb/rails-interactive)
@@ -5,7 +5,7 @@ require "yaml"
5
5
  module RailsInteractive
6
6
  class CLI
7
7
  # Categories class for the interactive CLI module
8
- class Categories
8
+ class Category
9
9
  def initialize
10
10
  @categories = YAML.load_file("#{__dir__}/config/categories.yml").uniq
11
11
  end
@@ -5,7 +5,7 @@ require "yaml"
5
5
  module RailsInteractive
6
6
  class CLI
7
7
  # Commands class for the interactive CLI module
8
- class Commands
8
+ class Command
9
9
  def initialize
10
10
  @commands = YAML.load_file("#{__dir__}/config/commands.yml").uniq
11
11
  end
@@ -17,6 +17,13 @@ module RailsInteractive
17
17
  def find_by_identifier(identifier)
18
18
  @commands.find { |command| command["identifier"] == identifier }
19
19
  end
20
+
21
+ def dependencies(identifier)
22
+ identifier = identifier.is_a?(Array) ? identifier.join("") : identifier
23
+ command ||= find_by_identifier(identifier)
24
+
25
+ command["dependencies"]
26
+ end
20
27
  end
21
28
  end
22
29
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cli/command"
4
+ require "yaml"
5
+
6
+ module RailsInteractive
7
+ class CLI
8
+ # Commands class for the interactive CLI module
9
+ class CommandHandler
10
+ def initialize
11
+ @commands = Command.new.all
12
+ @installed_commands = []
13
+ @installed_dependencies = []
14
+ end
15
+
16
+ def handle_multi_options(options, dependencies = nil)
17
+ handle_dependencies(dependencies)
18
+
19
+ options.each do |option|
20
+ @installed_commands << option
21
+ system("bin/rails app:template LOCATION=templates/setup_#{option}.rb")
22
+ end
23
+ end
24
+
25
+ def handle_option(option, dependencies = nil)
26
+ @installed_commands << option
27
+ handle_dependencies(dependencies)
28
+
29
+ system("bin/rails app:template LOCATION=templates/setup_#{option}.rb")
30
+ end
31
+
32
+ def handle_dependencies(dependencies)
33
+ dependencies&.each do |dependency|
34
+ next if duplicated_gem?(dependency)
35
+
36
+ puts ">> Dependency Detected: #{dependency} "
37
+ @installed_dependencies << dependency
38
+
39
+ system("bin/rails app:template LOCATION=templates/setup_#{dependency}.rb")
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def duplicated_gem?(option)
46
+ @installed_commands.include?(option) || @installed_dependencies.include?(option)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -15,37 +15,42 @@
15
15
  type: "select"
16
16
  required: false
17
17
  -
18
- name: template_engine
18
+ name: end_to_end_testing
19
19
  weight: 4
20
20
  type: "select"
21
21
  required: false
22
22
  -
23
- name: code_quality
23
+ name: template_engine
24
24
  weight: 5
25
25
  type: "select"
26
26
  required: false
27
27
  -
28
- name: background_job
28
+ name: code_quality
29
29
  weight: 6
30
30
  type: "select"
31
31
  required: false
32
32
  -
33
- name: security
33
+ name: background_job
34
34
  weight: 7
35
35
  type: "select"
36
36
  required: false
37
37
  -
38
- name: admin_panel
38
+ name: security
39
39
  weight: 8
40
40
  type: "select"
41
41
  required: false
42
42
  -
43
- name: features
43
+ name: admin_panel
44
44
  weight: 9
45
+ type: "select"
46
+ required: false
47
+ -
48
+ name: features
49
+ weight: 10
45
50
  type: "multi_select"
46
51
  required: false
47
52
  -
48
53
  name: development
49
- weight: 10
54
+ weight: 11
50
55
  type: "multi_select"
51
56
  required: false
@@ -125,4 +125,30 @@
125
125
  name: StandartRB
126
126
  category: code_quality
127
127
  description: " Ruby Style Guide, with linter & automatic code fixer. For details: https://github.com/testdouble/standard"
128
+ dependencies: null
129
+ -
130
+ identifier: sassc_rails
131
+ name: Saasc Rails
132
+ category: development
133
+ description: "Integrate SassC-Ruby with Rails! For details: https://github.com/sass/sassc-rails"
134
+ dependencies: null
135
+ -
136
+ identifier: active_admin
137
+ name: ActiveAdmin
138
+ category: admin_panel
139
+ description: "The administration framework for Ruby on Rails applications. For details: https://github.com/activeadmin/activeadmin"
140
+ dependencies:
141
+ - sassc_rails
142
+ - devise
143
+ -
144
+ identifier: minitest
145
+ name: MiniTest ( Default )
146
+ category: testing
147
+ description: "minitest provides a complete suite of testing facilities supporting TDD, BDD, mocking, and benchmarking. For details: https://github.com/minitest/minitest"
148
+ dependencies: null
149
+ -
150
+ identifier: capybara
151
+ name: Capybara
152
+ category: end_to_end_testing
153
+ description: "Acceptance test framework for web applications. For details: https://github.com/teamcapybara/capybara"
128
154
  dependencies: null
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ run "bundle add activeadmin"
4
+ run "bundle add bcrypt"
5
+ Bundler.with_unbundled_env { run "bundle" }
6
+
7
+ rails_command "generate active_admin:install"
8
+ rails_command "db:migrate"
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ gem_group :development, :test do
4
+ gem "capybara"
5
+ end
6
+
7
+ Bundler.with_unbundled_env { run "bundle install" }
8
+
9
+ if defined? RSpec
10
+ inject_into_file "spec/spec_helper.rb", before: "RSpec.configure do |config|" do
11
+ <<~RB
12
+ require 'capybara/rspec'
13
+ RB
14
+ end
15
+ elsif defined? MiniTest && !defined? RSpec
16
+ inject_into_file "test/test_helper.rb", before: "class ActiveSupport::TestCase" do
17
+ <<~RB
18
+ require 'capybara/rails'
19
+ require 'capybara/minitest'
20
+ RB
21
+ end
22
+ else
23
+ puts "No test framework detected or related test framework does not exist in RailsInteractive"
24
+ end
@@ -5,6 +5,11 @@ Bundler.with_unbundled_env { run "bundle install" }
5
5
 
6
6
  rails_command "generate devise:install"
7
7
 
8
- run "rails generate devise User"
9
- run "rails db:create"
8
+ model_name = ask("What do you want to call your Devise model?")
9
+ model_name = model_name.empty? ? "user" : model_name
10
+
11
+ File.open("devise-model.txt", "w") { |f| f.write(model_name) }
12
+
13
+ run "rails generate devise #{model_name.capitalize}"
14
+ run "rails db:prepare"
10
15
  run "rails db:migrate"
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ run "bundle add minitest"
4
+
5
+ Bundler.with_unbundled_env { run "bundle install" }
@@ -1,30 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "fileutils"
4
+
3
5
  run "bundle add omniauth"
4
6
 
5
7
  run "bundle install"
6
8
 
9
+ devise_model_name = File.read("devise-model.txt")
10
+ FileUtils.rm("devise-model.txt")
11
+
7
12
  # 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"
13
+ rails_command "generate model identity #{devise_model_name}:references provider:string:index uid:string:index token:string:index refresh_token:string:index"
9
14
  # rubocop:enable Layout/LineLength
10
15
 
11
- rails_command "generate migration AddIdentityToUsers identities_count:integer"
16
+ rails_command "generate migration AddIdentityTo#{devise_model_name.capitalize}s identities_count:integer"
12
17
 
13
18
  rails_command "db:migrate"
14
19
 
15
- inject_into_file "config/routes.rb", after: "devise_for :users\n" do
16
- " # devise_for :users, controllers: { omniauth_callbacks: 'omniauth' }"
20
+ inject_into_file "config/routes.rb", after: "devise_for :#{devise_model_name}s\n" do
21
+ " # devise_for :#{devise_model_name}s, controllers: { omniauth_callbacks: 'omniauth' }"
17
22
  end
18
23
 
19
- inject_into_file "app/models/user.rb", after: ":database_authenticatable, " do
24
+ inject_into_file "app/models/#{devise_model_name}.rb", after: ":database_authenticatable, " do
20
25
  ":omniauthable, "
21
26
  end
22
27
 
23
- inject_into_file "app/models/identity.rb", after: "belongs_to :user" do
28
+ inject_into_file "app/models/identity.rb", after: "belongs_to :#{devise_model_name}" do
24
29
  ", counter_cache: true"
25
30
  end
26
31
 
27
- inject_into_file "app/models/user.rb", after: "class User < ApplicationRecord\n" do
32
+ inject_into_file "app/models/#{devise_model_name}.rb",
33
+ after: "class #{devise_model_name.capitalize} < ApplicationRecord\n" do
28
34
  # rubocop:disable Naming/HeredocDelimiterNaming
29
35
  <<-EOF
30
36
  has_many :identities, dependent: :destroy
@@ -36,15 +42,15 @@ inject_into_file "app/models/user.rb", after: "class User < ApplicationRecord\n"
36
42
  identity.token = auth.credentials.token
37
43
  identity.refresh_token = auth.credentials.refresh_token
38
44
  end
39
- if identity.user.nil? && auth.info.email.present?
40
- user = User.where(email: auth.info.email).first_or_initialize
45
+ if identity.#{devise_model_name}.nil? && auth.info.email.present?
46
+ user = #{devise_model_name}.where(email: auth.info.email).first_or_initialize
41
47
  user.name = auth.info.name
42
48
  user.password = Devise.friendly_token if user.new_record?
43
49
  user.save!
44
- identity.user = user
50
+ identity.#{devise_model_name} = user
45
51
  end
46
52
  identity.save!
47
- identity.user
53
+ identity.#{devise_model_name}
48
54
  end
49
55
  end
50
56
 
@@ -57,5 +63,6 @@ file "app/controllers/omniauth_controller.rb", <<~CODE
57
63
 
58
64
  end
59
65
  CODE
60
-
61
- puts "IMPORTANT: Add devise_for :users, controllers: { omniauth_callbacks: 'omniauth' } to your routes.rb"
66
+ # rubocop:disable Layout/LineLength
67
+ puts "IMPORTANT: Add devise_for :#{devise_model_name}s, controllers: { omniauth_callbacks: 'omniauth' } to your routes.rb"
68
+ # rubocop:enable Layout/LineLength
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ run "bundle add sassc-rails"
4
+ Bundler.with_unbundled_env { run "bundle" }
data/lib/cli/utils.rb CHANGED
@@ -28,16 +28,6 @@ module RailsInteractive
28
28
  go_to_project_directory(project_name)
29
29
  end
30
30
 
31
- def self.handle_multi_options(multi_options)
32
- multi_options.each do |value|
33
- system("bin/rails app:template LOCATION=templates/setup_#{value}.rb")
34
- end
35
- end
36
-
37
- def self.handle_option(option)
38
- system("bin/rails app:template LOCATION=templates/setup_#{option}.rb")
39
- end
40
-
41
31
  def self.sign_project
42
32
  file = "README.md"
43
33
  msg = "\n> This project was generated by [Rails Interactive CLI](https://github.com/oguzsh/rails-interactive)"
data/lib/cli/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RailsInteractive
4
4
  class CLI
5
- VERSION = "2.0.0"
5
+ VERSION = "2.1.2"
6
6
  end
7
7
  end
@@ -2,17 +2,19 @@
2
2
 
3
3
  require "cli/prompt"
4
4
  require "cli/message"
5
- require "cli/commands"
6
- require "cli/categories"
5
+ require "cli/command"
6
+ require "cli/category"
7
7
  require "cli/utils"
8
+ require "cli/command_handler"
8
9
 
9
10
  module RailsInteractive
10
11
  # CLI class for the interactive CLI module
11
12
  class CLI
12
13
  def initialize
13
14
  @inputs = {}
14
- @commands = Commands.new
15
- @categories = Categories.new
15
+ @commands = Command.new
16
+ @categories = Category.new
17
+ @handler = CommandHandler.new
16
18
  end
17
19
 
18
20
  def perform(key)
@@ -100,8 +102,10 @@ module RailsInteractive
100
102
  @inputs.each do |key, value|
101
103
  next if %i[name type database].include?(key) || value.is_a?(Array) && value.empty? || value.nil?
102
104
 
103
- Utils.handle_multi_options(value) if value.is_a?(Array)
104
- Utils.handle_option(value) if value.is_a?(String)
105
+ dependencies = @commands.dependencies(value)
106
+
107
+ @handler.handle_multi_options(value, dependencies) if value.is_a?(Array)
108
+ @handler.handle_option(value, dependencies) if value.is_a?(String)
105
109
  end
106
110
 
107
111
  # Remove templates folder from project folder
@@ -122,5 +126,12 @@ module RailsInteractive
122
126
 
123
127
  @inputs[:database] = Prompt.new("Database: ", "select", database_types, required: true).perform
124
128
  end
129
+
130
+ def admin_panel
131
+ admin_panel = { "ActiveAdmin" => "active_admin" }
132
+
133
+ @inputs[:admin_panel] =
134
+ Prompt.new("Choose project admin panel: ", "select", admin_panel).perform
135
+ end
125
136
  end
126
137
  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: 2.0.0
4
+ version: 2.1.2
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-05-29 00:00:00.000000000 Z
11
+ date: 2022-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -163,18 +163,21 @@ files:
163
163
  - bin/console
164
164
  - bin/rails-interactive
165
165
  - bin/setup
166
- - lib/cli/categories.rb
167
- - lib/cli/commands.rb
166
+ - lib/cli/category.rb
167
+ - lib/cli/command.rb
168
+ - lib/cli/command_handler.rb
168
169
  - lib/cli/config/categories.yml
169
170
  - lib/cli/config/commands.yml
170
171
  - lib/cli/message.rb
171
172
  - lib/cli/prompt.rb
173
+ - lib/cli/templates/setup_active_admin.rb
172
174
  - lib/cli/templates/setup_avo.rb
173
175
  - lib/cli/templates/setup_awesome_print.rb
174
176
  - lib/cli/templates/setup_better_errors.rb
175
177
  - lib/cli/templates/setup_brakeman.rb
176
178
  - lib/cli/templates/setup_bullet.rb
177
179
  - lib/cli/templates/setup_cancancan.rb
180
+ - lib/cli/templates/setup_capybara.rb
178
181
  - lib/cli/templates/setup_devise.rb
179
182
  - lib/cli/templates/setup_faker.rb
180
183
  - lib/cli/templates/setup_friendly_id.rb
@@ -182,11 +185,13 @@ files:
182
185
  - lib/cli/templates/setup_haml.rb
183
186
  - lib/cli/templates/setup_kaminari.rb
184
187
  - lib/cli/templates/setup_letter_opener.rb
188
+ - lib/cli/templates/setup_minitest.rb
185
189
  - lib/cli/templates/setup_omniauth.rb
186
190
  - lib/cli/templates/setup_pundit.rb
187
191
  - lib/cli/templates/setup_rails_admin.rb
188
192
  - lib/cli/templates/setup_rspec.rb
189
193
  - lib/cli/templates/setup_rubocop.rb
194
+ - lib/cli/templates/setup_sassc_rails.rb
190
195
  - lib/cli/templates/setup_sidekiq.rb
191
196
  - lib/cli/templates/setup_slim.rb
192
197
  - lib/cli/templates/setup_standardrb.rb