vvm-rb 0.2.2 → 1.0.0

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
  SHA1:
3
- metadata.gz: 3c5ab61d4211e9a7958ac8dda739e0fc334b313f
4
- data.tar.gz: fdeaf8c8d31b478e520884c865e3bdf67b6c2889
3
+ metadata.gz: d205eff702304a8422fee7de8fb6104dcfe8edfb
4
+ data.tar.gz: c60209e5e6328a7a8d33ea581d8fed9336f4fef5
5
5
  SHA512:
6
- metadata.gz: f6c0d21a3d7936a7d00a536f5547a1fb474eb2a60f9e7f705ae5651750e67636061c25f30fc5b1c81646f91cacca2c3a017e07215507bb24a95caf5704742e6d
7
- data.tar.gz: a7a27a9a069e8f664cb092036a96d371d8510cf8c7685fb5a3feb7de55bc5422c933ae95a9c667535bb7f72c51adf63482e733f7bea32083aa1a3c9babd18833
6
+ metadata.gz: 26a043ccc72fdcbd398190ac5ba44be137c149b9b51762d886ef1d39da7686454510a89c1645aeab0bf920e624c9f453d441d4199cab1a62242c5273d596d95f
7
+ data.tar.gz: 78f2b9d88963a33e02f21ac2a66eb2233e9d16e7c52d7291407ac3383e0f5a3aed616ad9016cef3d4c1e4a6c17c31d48aac548ed1635b9e73af0b20b8571f13d
data/.rubocop.yml CHANGED
@@ -1,14 +1,16 @@
1
1
  AllCops:
2
2
  Exclude:
3
- - .bundle/**
4
- - .git/**
5
- - .vvm_cache/**
6
- - coverage/**
7
- - etc/**
8
- - pkg/**
9
- - vendor/**
3
+ - .bundle/**/*
4
+ - .git/**/*
5
+ - .vvm_cache/**/*
6
+ - coverage/**/*
7
+ - etc/**/*
8
+ - pkg/**/*
9
+ - vendor/**/*
10
+ - Rakefile
11
+ - vvm-rb.gemspec
10
12
  LineLength:
11
- Max: 80
13
+ Max: 90
12
14
  MethodLength:
13
15
  Max: 30
14
16
  RedundantReturn:
data/Gemfile CHANGED
@@ -3,10 +3,10 @@ source 'http://rubygems.org'
3
3
  gem 'thor', '~> 0.19.1'
4
4
 
5
5
  group :development do
6
- gem 'rspec', '~> 2.14.1'
7
- gem 'rubocop', '~> 0.21.0'
8
- gem 'rdoc', '~> 4.1.1'
9
- gem 'jeweler', '~> 2.0.1'
10
- gem 'simplecov', '~> 0.8.2'
6
+ gem 'rspec', '~> 3.0'
7
+ gem 'rubocop', '~> 0.25.0'
8
+ gem 'rdoc', '~> 4.1'
9
+ gem 'jeweler', '~> 2.0'
10
+ gem 'simplecov', '~> 0.9.0'
11
11
  gem 'coveralls', '~> 0.7.0', require: false
12
12
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 1.0.0
data/bin/vvm ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'vvm'
5
+ require 'vvm/cli'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'vvm'
9
+ require 'vvm/cli'
10
+ end
11
+
12
+ Vvm::Cli.source_root(File.join(File.dirname(__FILE__), '..'))
13
+ Vvm::Cli.start
@@ -0,0 +1,37 @@
1
+ module Vvm
2
+ module Accessor
3
+ module_function
4
+
5
+ def get_dot_dir
6
+ File.expand_path(ENV['VVMROOT'] || '~/.vvm-rb')
7
+ end
8
+
9
+ def get_etc_dir
10
+ File.join(get_dot_dir, 'etc')
11
+ end
12
+
13
+ def get_repos_dir
14
+ File.join(get_dot_dir, 'repos')
15
+ end
16
+
17
+ def get_src_dir(version = '')
18
+ File.join(get_dot_dir, 'src', version)
19
+ end
20
+
21
+ def get_vims_dir(version = '')
22
+ File.join(get_dot_dir, 'vims', version)
23
+ end
24
+
25
+ def get_vimorg_dir
26
+ File.join(get_repos_dir, 'vimorg')
27
+ end
28
+
29
+ def get_login_file
30
+ File.join(get_etc_dir, 'login')
31
+ end
32
+
33
+ def get_current_dir
34
+ File.join(get_vims_dir, 'current')
35
+ end
36
+ end
37
+ end
data/lib/vvm/cli.rb ADDED
@@ -0,0 +1,78 @@
1
+ require 'thor'
2
+
3
+ module Vvm
4
+ class Cli < Thor
5
+ include Thor::Actions
6
+ include Validator
7
+
8
+ desc 'install [VERSION] [CONFIGURE_OPTS]', 'Install a specific version of Vim'
9
+ method_option :use, type: :boolean, aliases: '-u', banner: 'Use installed vim'
10
+ def install(version, *conf)
11
+ i = Installer.new(Version.format(version), conf)
12
+ i.checkout
13
+ i.configure
14
+ i.make_install
15
+ Installer.cp_etc
16
+
17
+ invoke :use, [version], {} if options[:use]
18
+ i.message
19
+ end
20
+
21
+ desc 'update', 'Update to latest version of Vim'
22
+ def update
23
+ current = Version.current
24
+ if current == 'system'
25
+ run 'vvm install --use latest'
26
+ run 'vvm use system' unless $?.success?
27
+ else
28
+ run 'vvm use system'
29
+ run 'vvm install --use latest'
30
+ action = $?.success? ? 'uninstall' : 'use'
31
+ run "vvm #{action} #{current}"
32
+ end
33
+ end
34
+
35
+ desc 'reinstall [VERSION] [CONFIGURE_OPTS]', 'Reinstall a specific version'
36
+ def reinstall(version, *conf)
37
+ invoke :uninstall, [version]
38
+ invoke :install, [version, *conf]
39
+ end
40
+
41
+ desc 'rebuild [VERSION] [CONFIGURE_OPTS]', 'Rebuild a specific version of Vim'
42
+ def rebuild(version, *conf)
43
+ r = Installer.new(Version.format(version), conf)
44
+ r.make_clean
45
+ r.configure
46
+ r.make_install
47
+ end
48
+
49
+ desc 'use [VERSION]', 'Use a specific version of Vim as the default one.'
50
+ def use(version)
51
+ Switcher.new(Version.format(version)).use
52
+ end
53
+
54
+ desc 'list', 'Look available versions of Vim.'
55
+ def list
56
+ puts Version.list.join("\n")
57
+ end
58
+
59
+ desc 'versions', 'Look installed versions of Vim.'
60
+ def versions
61
+ puts Version.versions.join("\n")
62
+ end
63
+
64
+ desc 'uninstall [VERSION]', 'Uninstall a specific version of Vim.'
65
+ def uninstall(version)
66
+ Uninstaller.new(Version.format(version)).uninstall
67
+ end
68
+
69
+ no_commands do
70
+ def invoke_command(command, *args)
71
+ validate_before_invoke(command.name)
72
+ Installer.pull if %w(install list).include?(command.name)
73
+ Installer.fetch unless File.exist?(get_vimorg_dir)
74
+ super
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,3 @@
1
+ module Vvm
2
+ VIM_URI = 'https://vim.googlecode.com/hg/'
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'mkmf'
2
+
3
+ module MakeMakefile
4
+ module Logging
5
+ @logfile = File::NULL
6
+ @quiet = true
7
+ end
8
+ end
@@ -0,0 +1,83 @@
1
+ require 'fileutils'
2
+
3
+ module Vvm
4
+ class Installer
5
+ def initialize(version, conf, silent = false)
6
+ vvmopt = ENV['VVMOPT']
7
+ @silent = silent ? '> /dev/null 2>&1' : ''
8
+ @version = version
9
+ @conf = conf.flatten.empty? && vvmopt ? vvmopt.split(' ') : conf
10
+ end
11
+
12
+ def self.fetch
13
+ FileUtils.mkdir_p(get_repos_dir)
14
+ repos_dir = get_vimorg_dir
15
+ system("hg -q clone #{VIM_URI} #{repos_dir}") unless File.exist?(repos_dir)
16
+ end
17
+
18
+ def self.pull
19
+ Dir.chdir(get_vimorg_dir) { system('hg -q pull') }
20
+ end
21
+
22
+ def checkout
23
+ src_dir = get_src_dir
24
+ FileUtils.mkdir_p(src_dir)
25
+ return if File.exist?(get_src_dir(@version))
26
+ archive = "hg archive -t tar -r #{@version} -p #{@version} -"
27
+ expand = "(cd #{src_dir} && tar xf -)"
28
+ Dir.chdir get_vimorg_dir do
29
+ system("#{archive} | #{expand} #{@silent}")
30
+ end
31
+ end
32
+
33
+ def configure
34
+ vims_dir = get_vims_dir(@version)
35
+ src_dir = get_src_dir(@version)
36
+ default = "--prefix=#{vims_dir}"
37
+ Dir.chdir src_dir do
38
+ system("./configure #{default} #{@conf.join(' ')} #{@silent}")
39
+ end
40
+ end
41
+
42
+ def make_clean
43
+ src_dir = get_src_dir(@version)
44
+ Dir.chdir src_dir do
45
+ system("make clean #{@silent}")
46
+ end
47
+ end
48
+
49
+ def make_install
50
+ src_dir = get_src_dir(@version)
51
+ Dir.chdir src_dir do
52
+ system("make all install #{@silent}")
53
+ end
54
+ end
55
+
56
+ def self.cp_etc
57
+ current_login = get_login_file
58
+ path = File.join(File.dirname(__FILE__), '..', '..', 'etc', 'login')
59
+ login = File.expand_path(path)
60
+ if !File.exist?(current_login)
61
+ etc_dir = get_etc_dir
62
+ FileUtils.mkdir_p(etc_dir)
63
+ FileUtils.cp(login, etc_dir)
64
+ elsif !FileUtils.compare_file(login, current_login)
65
+ FileUtils.cp(login, get_etc_dir)
66
+ end
67
+ end
68
+
69
+ def message
70
+ return if !$?.success? || @silent.empty?
71
+ print "\e[32m"
72
+ puts <<-EOS
73
+
74
+ Vim is successfully installed. For daily use,
75
+ please add the following line into your ~/.bash_login etc:
76
+
77
+ test -f ~/.vvm-rb/etc/login && source ~/.vvm-rb/etc/login
78
+
79
+ EOS
80
+ print "\e[0m"
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,18 @@
1
+ require 'fileutils'
2
+
3
+ module Vvm
4
+ class Switcher
5
+ def initialize(version)
6
+ @version = version
7
+ end
8
+
9
+ def use
10
+ current = get_current_dir
11
+ FileUtils.rm(current) if File.exist?(current)
12
+ return if @version == 'system'
13
+ vims_dir = get_vims_dir(@version)
14
+ abort "#{@version} is not installed." unless File.exist?(vims_dir)
15
+ FileUtils.ln_s(vims_dir, current)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ require 'fileutils'
2
+
3
+ module Vvm
4
+ class Uninstaller
5
+ def initialize(version)
6
+ @version = version
7
+ end
8
+
9
+ def uninstall
10
+ current = get_current_dir
11
+ vims_dir = get_vims_dir(@version)
12
+ src_dir = get_src_dir(@version)
13
+ if File.exist?(current)
14
+ target = File.readlink(current)
15
+ if target == vims_dir
16
+ abort "#{@version} can not be uninstalled; it is currently used."
17
+ end
18
+ end
19
+ FileUtils.rm_rf(src_dir) if File.exist?(src_dir)
20
+ FileUtils.rm_rf(vims_dir) if File.exist?(vims_dir)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,55 @@
1
+ require 'mkmf'
2
+
3
+ module Vvm
4
+ module Validator
5
+ module_function
6
+
7
+ def validate_before_invoke(command)
8
+ new_version? if command == 'install'
9
+ has_version? if %w(reinstall rebuild use uninstall).include?(command)
10
+ version? if %w(install reinstall rebuild use uninstall).include?(command)
11
+ has_hg? if %w(install reinstall rebuild list).include?(command)
12
+ end
13
+
14
+ def has_hg?
15
+ unless Kernel.find_executable('hg')
16
+ abort 'mercurial is required to install.'
17
+ end
18
+ return true
19
+ end
20
+
21
+ def version?
22
+ if get_version.nil?
23
+ abort 'undefined vim version. please run [ vvm-rb list ].'
24
+ end
25
+ return true
26
+ end
27
+
28
+ def new_version?(version = get_version)
29
+ abort "#{version} is already installed." if version_include?(version)
30
+ return true
31
+ end
32
+
33
+ def has_version?(version = get_version)
34
+ abort "#{version} is not installed." unless version_include?(version)
35
+ return true
36
+ end
37
+
38
+ private
39
+
40
+ def get_version
41
+ version_regex = /\Av7-.+\z|\A(\d\.\d(a|b){0,1}(\.\d+){0,1})\z/
42
+ regex = /(\Astart\z|\Atip\z|\Asystem\z|\Alatest\z|#{version_regex})/
43
+ version = $*.find { |v| v =~ regex }
44
+ return Version.format(version)
45
+ end
46
+
47
+ def version_include?(version)
48
+ return Version.versions.include?(version) || use_system?(version)
49
+ end
50
+
51
+ def use_system?(version)
52
+ return version == 'system' && $*.include?('use')
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,43 @@
1
+ module Vvm
2
+ class Version
3
+ def self.list
4
+ Dir.chdir(get_vimorg_dir) do
5
+ list = `hg tags`.split.reverse
6
+ return list.values_at(* list.each_index.select { |i| i.odd? })
7
+ end
8
+ end
9
+
10
+ def self.versions
11
+ output = []
12
+ vims_dir = get_vims_dir
13
+ return output unless File.exist?(vims_dir)
14
+ Dir.glob(File.join(vims_dir, 'v*')).sort.each do |d|
15
+ output << File.basename(d)
16
+ end
17
+ return output
18
+ end
19
+
20
+ def self.latest
21
+ return list.select { |v| v =~ /\Av7-.+\z/ }.last
22
+ end
23
+
24
+ def self.current
25
+ c = get_current_dir
26
+ return File.exist?(c) ? File.basename(File.readlink(c)) : 'system'
27
+ end
28
+
29
+ def self.convert(version)
30
+ return "v#{version.gsub(/\./, '-')}"
31
+ end
32
+
33
+ def self.format(version)
34
+ case version
35
+ when /\Alatest\z/
36
+ version = latest
37
+ when /\A(\d\.\d(a|b){0,1}(\.\d+){0,1})\z/
38
+ version = convert(version)
39
+ end
40
+ return version
41
+ end
42
+ end
43
+ end
data/lib/vvm.rb ADDED
@@ -0,0 +1,10 @@
1
+ require_relative 'vvm/ext/mkmf'
2
+ require_relative 'vvm/constants'
3
+ require_relative 'vvm/installer'
4
+ require_relative 'vvm/uninstaller'
5
+ require_relative 'vvm/switcher'
6
+ require_relative 'vvm/validator'
7
+ require_relative 'vvm/accessor'
8
+ require_relative 'vvm/version'
9
+
10
+ include Vvm::Accessor
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Accessor' do
4
+ it 'can access vvm-rb home directory' do
5
+ expect(File.exist?(get_dot_dir)).to be_truthy
6
+ end
7
+
8
+ it 'can access etc directory' do
9
+ expect(File.exist?(get_etc_dir)).to be_truthy
10
+ end
11
+
12
+ it 'can access repos directory' do
13
+ expect(File.exist?(get_repos_dir)).to be_truthy
14
+ end
15
+
16
+ it 'can access src directory' do
17
+ expect(File.exist?(get_src_dir)).to be_truthy
18
+ end
19
+
20
+ it 'can access vims directory' do
21
+ expect(File.exist?(get_vims_dir)).to be_truthy
22
+ end
23
+
24
+ it 'can access vimorg directory' do
25
+ expect(File.exist?(get_vimorg_dir)).to be_truthy
26
+ end
27
+
28
+ it 'can access login file' do
29
+ expect(File.exist?(get_login_file)).to be_truthy
30
+ end
31
+
32
+ context 'of current directory' do
33
+ before { Vvm::Switcher.new(VERSION1).use }
34
+ after { Vvm::Switcher.new('system').use }
35
+
36
+ it 'can access current directory' do
37
+ expect(File.exist?(get_current_dir)).to be_truthy
38
+ end
39
+ end
40
+ end
@@ -4,7 +4,7 @@ describe 'Installer', disable_cache: true do
4
4
  before :all do
5
5
  ENV['VVMOPT'] = '--enable-rubyinterp'
6
6
  @version = VERSION1
7
- @installer = Installer.new(@version, [], true)
7
+ @installer = Vvm::Installer.new(@version, [], true)
8
8
  end
9
9
 
10
10
  let(:version_src_dir) { get_src_dir(@version) }
@@ -13,29 +13,29 @@ describe 'Installer', disable_cache: true do
13
13
 
14
14
  describe 'install' do
15
15
  context 'fetch', clean: true do
16
- before(:all) { Installer.fetch }
16
+ before(:all) { Vvm::Installer.fetch }
17
17
 
18
18
  it 'exists vimorg dir' do
19
- expect(File.exist?(get_vimorg_dir)).to be_true
19
+ expect(File.exist?(get_vimorg_dir)).to be_truthy
20
20
  end
21
21
 
22
22
  it 'success to clone' do
23
- expect($?.success?).to be_true
23
+ expect($?.success?).to be_truthy
24
24
  end
25
25
 
26
26
  it 'exists configure file' do
27
- expect(File.exist?(File.join(get_vimorg_dir, 'configure'))).to be_true
27
+ expect(File.exist?(File.join(get_vimorg_dir, 'configure'))).to be_truthy
28
28
  end
29
29
  end
30
30
 
31
31
  context 'pull', clean: true, vimorg: true do
32
32
  before :all do
33
33
  Dir.chdir(get_vimorg_dir) { system('hg rollback') }
34
- Installer.pull
34
+ Vvm::Installer.pull
35
35
  end
36
36
 
37
37
  it 'success to pull' do
38
- expect($?.success?).to be_true
38
+ expect($?.success?).to be_truthy
39
39
  end
40
40
 
41
41
  it 'vim is uptodate' do
@@ -51,11 +51,12 @@ describe 'Installer', disable_cache: true do
51
51
  end
52
52
 
53
53
  it 'exists src dir' do
54
- expect(File.exist?(version_src_dir)).to be_true
54
+ expect(File.exist?(version_src_dir)).to be_truthy
55
55
  end
56
56
 
57
57
  it 'exists configure file' do
58
- expect(File.exist?(File.join(version_src_dir, 'configure'))).to be_true
58
+ configure = File.join(version_src_dir, 'configure')
59
+ expect(File.exist?(configure)).to be_truthy
59
60
  end
60
61
  end
61
62
 
@@ -66,11 +67,11 @@ describe 'Installer', disable_cache: true do
66
67
  end
67
68
 
68
69
  it 'exists vims dir' do
69
- expect(File.exist?(version_vims_dir)).to be_true
70
+ expect(File.exist?(version_vims_dir)).to be_truthy
70
71
  end
71
72
 
72
73
  it 'can execute vim' do
73
- expect(system("#{vim} --version > /dev/null 2>&1")).to be_true
74
+ expect(system("#{vim} --version > /dev/null 2>&1")).to be_truthy
74
75
  end
75
76
 
76
77
  it 'enable rubyinterp' do
@@ -80,27 +81,27 @@ describe 'Installer', disable_cache: true do
80
81
 
81
82
  context 'cp_etc', clean: true do
82
83
  context 'login file not exist' do
83
- before(:all) { Installer.cp_etc }
84
+ before(:all) { Vvm::Installer.cp_etc }
84
85
 
85
86
  it 'exists etc dir' do
86
- expect(File.exist?(get_etc_dir)).to be_true
87
+ expect(File.exist?(get_etc_dir)).to be_truthy
87
88
  end
88
89
 
89
90
  it 'exists login file' do
90
- expect(File.exist?(get_login_file)).to be_true
91
+ expect(File.exist?(get_login_file)).to be_truthy
91
92
  end
92
93
  end
93
94
 
94
95
  context 'login file exists and it is not latest' do
95
- before :all do
96
- FileUtils.stub(:compare_file).and_return(false)
96
+ before do
97
+ allow(FileUtils).to receive(:compare_file).and_return(false)
97
98
  end
98
99
 
99
100
  it 'exists login file' do
100
101
  path = File.join(File.dirname(__FILE__), '..', 'etc', 'login')
101
102
  login = File.expand_path(path)
102
103
  expect(FileUtils).to receive(:cp).with(login, get_etc_dir)
103
- Installer.cp_etc
104
+ Vvm::Installer.cp_etc
104
105
  end
105
106
  end
106
107
  end
@@ -114,7 +115,7 @@ describe 'Installer', disable_cache: true do
114
115
 
115
116
  it 'not exists objects dir' do
116
117
  path = File.join(version_src_dir, 'src', 'objects', '*')
117
- expect(Dir[path].empty?).to be_true
118
+ expect(Dir[path].empty?).to be_truthy
118
119
  end
119
120
  end
120
121
  end
data/spec/spec_helper.rb CHANGED
@@ -14,11 +14,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
14
  require 'rspec'
15
15
  require 'fileutils'
16
16
  require 'tmpdir'
17
- require 'vvm-rb'
18
- include VvmRb
19
-
20
- support = File.join(File.dirname(__FILE__), 'support', '**', '*.rb')
21
- Dir[support].each { |f| require f }
17
+ require 'vvm'
22
18
 
23
19
  VERSION1, VERSION2 = 'v7-4-083', 'v7-4-103'
24
20
 
@@ -30,14 +26,14 @@ RSpec.configure do |config|
30
26
  unless File.exist?(cache_dir)
31
27
  ENV['VVMROOT'] = cache_dir
32
28
  FileUtils.mkdir_p(cache_dir)
33
- Installer.fetch
29
+ Vvm::Installer.fetch
34
30
  [VERSION1, VERSION2].each do |v|
35
31
  i = Installer.new(v, [], true)
36
32
  i.checkout
37
33
  i.configure
38
34
  i.make_install
39
35
  end
40
- Installer.cp_etc
36
+ Vvm::Installer.cp_etc
41
37
  end
42
38
  end
43
39
 
@@ -4,24 +4,24 @@ describe 'Switcher' do
4
4
  describe 'use' do
5
5
  context 'system vim' do
6
6
  before :all do
7
- Switcher.new('system').use
7
+ Vvm::Switcher.new('system').use
8
8
  end
9
9
 
10
10
  it 'delete current' do
11
- expect(File.exist?(get_current_dir)).not_to be_true
11
+ expect(File.exist?(get_current_dir)).not_to be_truthy
12
12
  end
13
13
  end
14
14
 
15
15
  context 'different version' do
16
16
  before :all do
17
17
  version = VERSION1
18
- Switcher.new(version).use
18
+ Vvm::Switcher.new(version).use
19
19
  @vims_dir = get_vims_dir(version)
20
20
  @current = get_current_dir
21
21
  end
22
22
 
23
23
  it 'exist current' do
24
- expect(File.exist?(@current)).to be_true
24
+ expect(File.exist?(@current)).to be_truthy
25
25
  end
26
26
 
27
27
  it 'switch current' do
@@ -31,7 +31,7 @@ describe 'Switcher' do
31
31
 
32
32
  context 'unknown version' do
33
33
  before :all do
34
- @switcher = Switcher.new('v7-5')
34
+ @switcher = Vvm::Switcher.new('v7-5')
35
35
  end
36
36
 
37
37
  it 'raise error' do