rails-interactive 0.1.1 → 0.1.5

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: 50088150a63a91cf9047bca00afd9c07c6457be67f78f8a8b505756aa7beef7e
4
- data.tar.gz: b39b595b7255aee9668aea8e1b9596bd871039f7aa87da18d83db5aed435ad95
3
+ metadata.gz: a1d6d7de1b01f37818e7d8f40a4ea4f70e4f7419e0a9289a09a345f8761728bf
4
+ data.tar.gz: 6eb6ad5b7193fd37f1d8abadc238806e4a37892bc0f422821f2ef2ec62c69726
5
5
  SHA512:
6
- metadata.gz: 627e7dbeaf32ea190062944dac3079090d70bd9d91dfc7974472e22551026ebffc38c7db1d51df34e0188a772c6b1e7ad2a3968b5f42291f588e57ba886cab10
7
- data.tar.gz: 531b13de9240ec1a84416a6d56fbf32e47cd8fd80a4c1d3bc8398289c1febdeb046e07b4df6167d129324fbf9c5fcc57346adf530d55b6ab178b43682449abea
6
+ metadata.gz: aa7219d9f1233d37defe9944d032e5367bdcc0aeda2b4e3e78d8e49b21470f1d4b0f0d39fda2ac87a77782c3801d8e33c450fd3abce5ddcb2c86170735b3ddff
7
+ data.tar.gz: 54af5dfed258953ce0439154e4f2cfbc7d239aecd7f3d4c7a15ae12fbfbffdaa51753f647fab8d275a6b3d8b02bced5c94df83252cafefe3e8a8d142db80cc40
@@ -1,16 +1,57 @@
1
- name: Ruby
2
-
3
- on: [push,pull_request]
4
-
1
+ name: Release and Publish
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
5
6
  jobs:
6
7
  build:
7
8
  runs-on: ubuntu-latest
8
9
  steps:
9
- - uses: actions/checkout@v2
10
- - name: Set up Ruby
11
- uses: ruby/setup-ruby@v1
12
- with:
13
- ruby-version: 3.0.2
14
- bundler-cache: true
15
- - name: Run the default task
16
- run: bundle exec rake
10
+ - name: Wait for tests to succeed
11
+ uses: lewagon/wait-on-check-action@v1.0.0
12
+ with:
13
+ ref: ${{ github.ref }}
14
+ check-name: 'Run tests'
15
+ repo-token: ${{ secrets.GITHUB_TOKEN }}
16
+ wait-interval: 10
17
+ - uses: GoogleCloudPlatform/release-please-action@v2
18
+ id: release
19
+ with:
20
+ release-type: ruby
21
+ package-name: rails-interactive
22
+ version-file: 'lib/rails_interactive/version.rb'
23
+ - uses: actions/checkout@v2
24
+ if: ${{ steps.release.outputs.release_created }}
25
+ - name: Set up Ruby
26
+ uses: ruby/setup-ruby@v1
27
+ if: ${{ steps.release.outputs.release_created }}
28
+ with:
29
+ ruby-version: 3.0.2
30
+ bundler-cache: true
31
+ - name: Bundle Install
32
+ run: bundle install
33
+ if: ${{ steps.release.outputs.release_created }}
34
+ - name: Set Credentials
35
+ run: |
36
+ mkdir -p $HOME/.gem
37
+ touch $HOME/.gem/credentials
38
+ chmod 0600 $HOME/.gem/credentials
39
+ printf -- "---\n:github: Bearer ${GITHUB_TOKEN}\n" > $HOME/.gem/credentials
40
+ printf -- "---\n:rubygems_api_key: ${RUBYGEMS_TOKEN}\n" > $HOME/.gem/credentials
41
+ if: ${{ steps.release.outputs.release_created }}
42
+ env:
43
+ GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
44
+ RUBYGEMS_TOKEN: '${{secrets.RUBYGEMS_TOKEN}}'
45
+ - name: Publish to GitHub Packages
46
+ run: |
47
+ export OWNER=$( echo ${{ github.repository }} | cut -d "/" -f 1 )
48
+ gem build *.gemspec
49
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
50
+ gem push *.gem
51
+ if: ${{ steps.release.outputs.release_created }}
52
+ - name: Publish to RubyGems
53
+ run: |
54
+ gem build *.gemspec
55
+ gem push --host https://rubygems.pkg.github.com/${OWNER} *.gem
56
+ gem push *.gem
57
+ if: ${{ steps.release.outputs.release_created }}
@@ -0,0 +1,17 @@
1
+ name: Run tests
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ name: Run tests
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: actions/checkout@v2
11
+ - name: Set up Ruby
12
+ uses: ruby/setup-ruby@v1
13
+ with:
14
+ ruby-version: 3.0.2
15
+ bundler-cache: true
16
+ - name: Run the default task
17
+ run: bundle exec rake
data/Gemfile CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- # Specify your gem's dependencies in rails-interactive.gemspec
5
+ # Specify your gem's dependencies in rails_interactive.gemspec
6
6
  gemspec
7
7
 
8
8
  gem "rails"
@@ -13,6 +13,4 @@ gem "rspec", "~> 3.0"
13
13
 
14
14
  gem "rubocop", "~> 1.7"
15
15
 
16
- gem "byebug", "~> 11.1.2"
17
-
18
16
  gem "tty-prompt"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails-interactive (0.1.1)
4
+ rails-interactive (0.1.5)
5
5
  tty-prompt
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -12,7 +12,7 @@ $ gem install rails-interactive
12
12
  ## Usage
13
13
 
14
14
  ```bash
15
- $ interactive new
15
+ $ rails-interactive new
16
16
  ```
17
17
 
18
18
  ## Development
data/bin/console CHANGED
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "bundler/setup"
5
- require "interactive"
5
+ require "rails_interactive"
6
6
 
7
7
  # You can add fixtures and/or initialization code here to make experimenting
8
8
  # with your gem easier. You can also use a different console, if you like.
@@ -2,6 +2,6 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "bundler/setup"
5
- require "interactive"
5
+ require "rails_interactive"
6
6
 
7
- Interactive::CLI.new.perform(ARGV.first)
7
+ RailsInteractive::CLI.new.perform(ARGV.first)
data/bin/setup CHANGED
@@ -2,6 +2,6 @@
2
2
  set -euo pipefail
3
3
  IFS=$'\n\t'
4
4
  set -vx
5
- chmod u+x bin/interactive
5
+ chmod u+x bin/rails-interactive
6
6
 
7
7
  bundle install
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "colorize"
4
4
 
5
- module Interactive
5
+ module RailsInteractive
6
6
  # Utils class for the interactive CLI module
7
7
  class Message
8
8
  def self.greet
@@ -32,10 +32,7 @@ module Interactive
32
32
  def self.prepare
33
33
  puts ""
34
34
  puts "Project created successfully ✅".colorize(:green)
35
- puts "Go to your project folder and run :".colorize(:green)
36
- puts "> bundle install && yarn".colorize(:yellow)
37
- puts "After that, ready to go 🎉".colorize(:green)
38
-
35
+ puts "Go to your project folder and ready to go 🎉".colorize(:green)
39
36
  rails_commands
40
37
  end
41
38
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "tty/prompt"
4
4
 
5
- module Interactive
5
+ module RailsInteractive
6
6
  # Prompt class for commands
7
7
  class Prompt
8
8
  # Create a new instance
@@ -30,6 +30,8 @@ module Interactive
30
30
  @prompt.ask(@msg, required: @required)
31
31
  when "select"
32
32
  @prompt.select(@msg, @options, required: @required)
33
+ when "multi_select"
34
+ @prompt.multi_select(@msg, @options)
33
35
  else
34
36
  puts "Invalid parameter"
35
37
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ run "bundle add cancancan"
4
+
5
+ Bundler.with_unbundled_env { run "bundle install" }
6
+
7
+ rails_command "generate cancan:ability"
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ run "bundle add devise"
4
+ Bundler.with_unbundled_env { run "bundle install" }
5
+
6
+ rails_command "generate devise:install"
7
+
8
+ run "rails generate devise User"
9
+ run "rails db:create"
10
+ run "rails db:migrate"
@@ -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,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsInteractive
4
+ VERSION = "0.1.5"
5
+ end
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "interactive/prompt"
4
- require "interactive/message"
3
+ require "rails_interactive/prompt"
4
+ require "rails_interactive/message"
5
+ require "fileutils"
5
6
 
6
- module Interactive
7
+ module RailsInteractive
7
8
  # CLI class for the interactive CLI module
8
9
  class CLI
9
10
  def initialize
@@ -31,6 +32,9 @@ module Interactive
31
32
  database_types = { "PostgreSQL" => "-d postgresql", "MySQL" => "-d mysql", "SQLite" => "" }
32
33
  @inputs[:database] = Prompt.new("Choose project's database: ", "select", database_types, required: true).perform
33
34
 
35
+ features = %w[devise cancancan omniauth pundit]
36
+ @inputs[:features] = Prompt.new("Choose project features: ", "multi_select", features).perform
37
+
34
38
  create
35
39
  end
36
40
 
@@ -39,6 +43,15 @@ module Interactive
39
43
  system("bin/setup")
40
44
  # Create project
41
45
  system(setup)
46
+
47
+ copy_templates_to_project
48
+
49
+ # Move to project folder and install gems
50
+ Dir.chdir "./#{@inputs[:name]}"
51
+ @inputs[:features].each do |feature|
52
+ system("bin/rails app:template LOCATION=templates/setup_#{feature}.rb")
53
+ end
54
+
42
55
  # Prepare project requirements and give instructions
43
56
  Message.prepare
44
57
  end
@@ -51,5 +64,9 @@ module Interactive
51
64
 
52
65
  "#{base} #{cmd}".strip!
53
66
  end
67
+
68
+ def copy_templates_to_project
69
+ FileUtils.cp_r "#{__dir__}/rails_interactive/templates", "./#{@inputs[:name]}"
70
+ end
54
71
  end
55
72
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/interactive/version"
3
+ require_relative "lib/rails_interactive/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "rails-interactive"
7
- spec.version = Interactive::VERSION
7
+ spec.version = RailsInteractive::VERSION
8
8
  spec.authors = ["Oguzhan Ince"]
9
9
  spec.email = ["oguzhan824@gmail.com"]
10
10
 
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.1
4
+ version: 0.1.5
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-03-13 00:00:00.000000000 Z
11
+ date: 2022-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -113,12 +113,13 @@ email:
113
113
  - oguzhan824@gmail.com
114
114
  executables:
115
115
  - console
116
- - interactive
116
+ - rails-interactive
117
117
  - setup
118
118
  extensions: []
119
119
  extra_rdoc_files: []
120
120
  files:
121
121
  - ".github/workflows/main.yml"
122
+ - ".github/workflows/rspec_rubocop.yml"
122
123
  - ".gitignore"
123
124
  - ".rspec"
124
125
  - ".rubocop.yml"
@@ -130,13 +131,16 @@ files:
130
131
  - README.md
131
132
  - Rakefile
132
133
  - bin/console
133
- - bin/interactive
134
+ - bin/rails-interactive
134
135
  - bin/setup
135
- - lib/interactive.rb
136
- - lib/interactive/ascii.txt
137
- - lib/interactive/message.rb
138
- - lib/interactive/prompt.rb
139
- - lib/interactive/version.rb
136
+ - lib/rails_interactive.rb
137
+ - lib/rails_interactive/message.rb
138
+ - lib/rails_interactive/prompt.rb
139
+ - lib/rails_interactive/templates/setup_cancancan.rb
140
+ - lib/rails_interactive/templates/setup_devise.rb
141
+ - lib/rails_interactive/templates/setup_omniauth.rb
142
+ - lib/rails_interactive/templates/setup_pundit.rb
143
+ - lib/rails_interactive/version.rb
140
144
  - rails-interactive.gemspec
141
145
  homepage: https://github.com/oguzsh/rails-interactive
142
146
  licenses:
File without changes
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Interactive
4
- VERSION = "0.1.1"
5
- end