Skip to content

Commit 727b05c

Browse files
committed
bug fixes, ruby version 2.3, rubocop and fasterer applied
1 parent aa2a480 commit 727b05c

File tree

14 files changed

+81
-63
lines changed

14 files changed

+81
-63
lines changed

.rubocop.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
AllCops:
2+
TargetRubyVersion: 2.3
3+
4+
Metrics/LineLength:
5+
Max: 99
6+
7+
Style/FrozenStringLiteralComment:
8+
Enabled: false
9+
10+
Style/TrailingCommaInArguments:
11+
EnforcedStyleForMultiline: comma
12+
13+
Style/TrailingCommaInArrayLiteral:
14+
EnforcedStyleForMultiline: comma
15+
16+
Style/TrailingCommaInHashLiteral:
17+
EnforcedStyleForMultiline: comma
18+
19+
Style/Documentation:
20+
Enabled: false

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
source "https://rubygems.org"
1+
source 'https://rubygems.org'
22

3-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
44

55
# Specify your gem's dependencies in vue_cli-rails.gemspec
66
gemspec

Rakefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
require "bundler/gem_tasks"
2-
require "rspec/core/rake_task"
1+
require 'bundler/gem_tasks'
2+
require 'rspec/core/rake_task'
33

44
RSpec::Core::RakeTask.new(:spec)
55

6-
task :default => :spec
6+
task default: :spec

bin/console

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env ruby
22

3-
require "bundler/setup"
4-
require "vue_cli/rails"
3+
require 'bundler/setup'
4+
require 'vue_cli/rails'
55

66
# You can add fixtures and/or initialization code here to make experimenting
77
# with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "vue_cli/rails"
1010
# require "pry"
1111
# Pry.start
1212

13-
require "pry"
13+
require 'pry'
1414
Pry.start(__FILE__)
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
class VueController < ApplicationController
22
layout 'vue'
33

4-
def foo
5-
end
4+
def foo; end
65

7-
def bar
8-
end
6+
def bar; end
97
end

lib/tasks/vue.rake

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace :vue do
44
pm = VueCli::Rails::NodeEnv.new
55
abort('Cannot find node.js') unless pm.node?
66

7-
get_input = ->(message, list = 'Yn') {
7+
get_input = lambda { |message, list = 'Yn'|
88
list = list.chars
99
default = list.find { |c| c.upcase == c }
1010
list = list.map { |c| c == default ? c : c.downcase }.uniq
@@ -15,6 +15,7 @@ namespace :vue do
1515
r = STDIN.gets.chop.downcase
1616
break default if r == ''
1717
break r if list.include?(r)
18+
1819
print " [INVALID!] Please retry: #{valid}:"
1920
end
2021
}
@@ -68,7 +69,7 @@ namespace :vue do
6869
if src.exist? && src.directory?
6970
puts 'Detected `src` folder (should be generated by vue-cli)'
7071
input = get_input.call(' Do you want to delete src folder?')
71-
FileUtils.rm_rf src if input == 'y'
72+
FileUtils.rm_rf(src.to_s) if input == 'y'
7273
end
7374

7475
# 5. copy sample codes
@@ -121,13 +122,13 @@ namespace :vue do
121122
end
122123

123124
desc 'Dump config/vue.yml to_json'
124-
task :json_config => :environment do
125+
task json_config: :environment do
125126
config = VueCli::Rails::Configuration.new
126127
puts config.to_json
127128
end
128129

129130
desc 'Bundle assets for production'
130-
task :compile => :environment do
131+
task compile: :environment do
131132
pm = VueCli::Rails::Configuration.instance.node_env
132133
pm.exec('vue-cli-service build', env: { 'RAILS_ENV' => 'production' })
133134
end

lib/vue_cli/rails.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require "vue_cli/rails/version"
1+
require 'vue_cli/rails/version'
22
require 'vue_cli/rails/configuration'
33
require 'vue_cli/rails/node_env'
44

lib/vue_cli/rails/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def load_config(config)
2525
resolve_config(config, 'manifestOutput')
2626

2727
cfg_alias = config['alias']
28-
cfg_alias.keys.each { |k| resolve_config(cfg_alias, k) }
28+
cfg_alias.each_key { |k| resolve_config(cfg_alias, k) }
2929
dev_server = config['devServer'] || {}
3030
resolve_config(dev_server, 'contentBase')
3131

lib/vue_cli/rails/dev_server_proxy.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def initialize(app)
1212

1313
def perform_request(env)
1414
if env['PATH_INFO'].start_with?(@assets_path)
15-
env["HTTP_HOST"] = env["HTTP_X_FORWARDED_HOST"] = env["HTTP_X_FORWARDED_SERVER"] = @host
16-
env["HTTP_X_FORWARDED_PROTO"] = env["HTTP_X_FORWARDED_SCHEME"] = 'http'
17-
env["SCRIPT_NAME"] = ''
15+
env['HTTP_HOST'] = env['HTTP_X_FORWARDED_HOST'] = env['HTTP_X_FORWARDED_SERVER'] = @host
16+
env['HTTP_X_FORWARDED_PROTO'] = env['HTTP_X_FORWARDED_SCHEME'] = 'http'
17+
env['SCRIPT_NAME'] = ''
1818
super(env)
1919
else
2020
@app.call(env)

lib/vue_cli/rails/node_env.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ def initialize
1818
end
1919
end
2020

21-
def use!(pm)
22-
@pm = pm.to_sym
21+
def use!(manager)
22+
@pm = manager.to_sym
2323
raise(ArgumentError, "Unsupported manager: #{@pm}") unless %i[npm yarn].include?(@pm)
24-
raise(VueCli::Rails::Error, "Not installed: #{@pm}") unless self.try(:"#{@pm}?")
24+
raise(VueCli::Rails::Error, "Not installed: #{@pm}") unless try(:"#{@pm}?")
2525
end
2626

2727
def package_manager
@@ -30,15 +30,15 @@ def package_manager
3030

3131
def exec(command, args = nil, extra = nil, env: {})
3232
cmd = COMMAND_LINE[command.to_sym] || {}
33-
if @pm == :yarn && cmd[:yarn]
34-
cmd = cmd[:yarn]
35-
elsif @pm == :npm && cmd[:npm]
36-
cmd = cmd[:npm]
37-
elsif cmd[:npx]
38-
cmd = @pm == :yarn ? "yarn exec #{cmd[:npx]}" : "npx #{cmd[:npx]}"
39-
else
40-
cmd = @pm == :yarn ? "yarn exec #{command}" : "npx #{command}"
41-
end
33+
cmd = if @pm == :yarn && cmd[:yarn]
34+
cmd[:yarn]
35+
elsif @pm == :npm && cmd[:npm]
36+
cmd[:npm]
37+
elsif cmd[:npx]
38+
@pm == :yarn ? "yarn exec #{cmd[:npx]}" : "npx #{cmd[:npx]}"
39+
else
40+
@pm == :yarn ? "yarn exec #{command}" : "npx #{command}"
41+
end
4242

4343
cmd = "#{cmd} #{args}" if args.present?
4444
cmd = "#{cmd} #{@pm == :yarn ? '-- ' : ''}#{extra}" if extra.present?
@@ -53,7 +53,7 @@ def exec(command, args = nil, extra = nil, env: {})
5353
},
5454
global_add: {
5555
yarn: 'yarn global add',
56-
npm: 'npm i -g'
56+
npm: 'npm i -g',
5757
},
5858
}.freeze
5959

@@ -66,14 +66,14 @@ def method_missing(cmd, *args)
6666
def get_version_of(bin)
6767
return @versions[bin] if @versions.key?(bin)
6868

69-
r = `#{bin} --version`.strip.presence rescue nil
69+
r = begin
70+
`#{bin} --version`.strip.presence
71+
rescue StandardError
72+
nil
73+
end
7074
@versions[bin] = r && r.start_with?('v') ? r[1..-1] : r
7175
@versions[bin]
7276
end
73-
74-
def version_ge?(v1, v2)
75-
Gem::Version.new(v1) >= Gem::Version.new(v2)
76-
end
7777
end
7878
end
7979
end

0 commit comments

Comments
 (0)