Module: Konjac::Installer

Defined in:
lib/konjac/installer.rb

Overview

A class to help with installing supplementary tools for Konjac

Constant Summary collapse

VIM_GIT =

The location of my Konjac Vim plugin repository

"git://github.com/brymck/konjac_vim.git"
YML_GIT =

The location fo my Konjac supplementary dictionary repository

"git://github.com/brymck/konjac_yml.git"

Class Method Summary collapse

Class Method Details

.install_dictionariesObject

Install the supplementary dictionaries



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/konjac/installer.rb', line 56

def install_dictionaries
  if dictionaries_installed?
    update_dictionaries
  else
    print I18n.t(:installing, :scope => :scripts) % I18n.t(:dictionaries, :scope => :scripts)
    Dir.chdir(konjac_home) do
      g = Git.clone(YML_GIT, ".dictionaries", :name => ".dictionaries",
        :path => konjac_home)
      g.chdir do
        FileUtils.cp_r Dir.glob("*.yml"), konjac_home
      end
    end
    puts I18n.t(:done, :scope => :scripts)
  end
end

.install_vimObject

Install the supplementary Vim plugin



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/konjac/installer.rb', line 35

def install_vim
  return update_vim if has_pathogen? && vim_installed?

  puts I18n.t(:installing, :scope => :scripts) % I18n.t(:vim_script, :scope => :scripts)
  if has_pathogen?
    Dir.chdir(vim_home) do
      system "git submodule add #{VIM_GIT} bundle/konjac_vim"
      system "git submodule init"
      system "git submodule update"
    end
  else
    dir = Dir.mktmpdir
    begin
    ensure
      FileUtils.remove_entry_secure dir
    end
  end
  puts I18n.t(:done, :scope => :scripts).capitalize
end

.run(command, script) ⇒ Object

Parses the provided command and script to install or update plugins and dictionary files



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/konjac/installer.rb', line 14

def run(command, script)
  case script.to_sym
  when :dictionaries, :dict, :dictionary
    script = "dictionaries"
  when :vim
    script = "vim"
  else
    puts I18n.t(:script_not_found, :scope => :scripts) % script
    return 
  end

  case command.to_sym
  when :install, :update
    # Build a command
    __send__ [command, script].join("_")
  else
    puts I18n.t(:command_not_found, :scope => :scripts) % command
  end
end

.updateObject

Update everything



102
103
104
105
# File 'lib/konjac/installer.rb', line 102

def update
  update_dictionaries
  update_vim
end

.update_dictionariesObject

Update the supplementary dictionaries



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/konjac/installer.rb', line 87

def update_dictionaries
  if dictionaries_installed?
    print I18n.t(:installing, :scope => :scripts) % I18n.t(:dictionaries, :scope => :scripts)
    g = Git.open(File.join(konjac_home, ".dictionaries"))
    g.pull
    g.chdir do
      FileUtils.cp_r Dir.glob("*.yml"), konjac_home
    end
    puts I18n.t(:done, :scope => :scripts)
  else
    install_dictionaries
  end
end

.update_vimObject

Update the supplementary Vim plugin



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/konjac/installer.rb', line 73

def update_vim
  if has_pathogen? && vim_installed?
    puts I18n.t(:updating, :scope => :scripts) % I18n.t(:vim_script, :scope => :scripts)
    Dir.chdir(File.join(vim_home, "bundle", "konjac_vim")) do
      system "git pull origin master"
    end
    system File.join(File.dirname(__FILE__), "..", "bash", "update_vim")
    puts I18n.t(:done, :scope => :scripts)
  else
    install_vim
  end
end