Class: Evm::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/evm/package.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Package

Returns a new instance of Package.



5
6
7
8
# File 'lib/evm/package.rb', line 5

def initialize(name, options = {})
  @name = name
  @file = options[:file] || File
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/evm/package.rb', line 3

def name
  @name
end

Class Method Details

.allObject



102
103
104
105
106
107
# File 'lib/evm/package.rb', line 102

def all
  recipes = Evm::Recipe.all
  recipes.map do |recipe|
    Package.new(recipe.name)
  end
end

.currentObject



87
88
89
90
91
# File 'lib/evm/package.rb', line 87

def current
  if (name = Evm.config[:current])
    find(name)
  end
end

.find(package_name) ⇒ Object



93
94
95
96
97
98
99
100
# File 'lib/evm/package.rb', line 93

def find(package_name)
  recipe = Evm::Recipe.find(package_name)
  if recipe
    Package.new(package_name)
  else
    raise Evm::Exception.new("No such package: #{package_name}")
  end
end

Instance Method Details

#binObject



18
19
20
21
22
23
24
# File 'lib/evm/package.rb', line 18

def bin
  if Evm::Os.osx? && File.exist?(File.join(path, 'Emacs.app'))
    File.join(path, 'Emacs.app', 'Contents', 'MacOS', 'Emacs')
  else
    File.join(path, 'bin', 'emacs')
  end
end

#current?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/evm/package.rb', line 10

def current?
  Package.current && Package.current.name == @name
end

#disuse!Object



37
38
39
40
# File 'lib/evm/package.rb', line 37

def disuse!
  delete_shims!
  Evm.config[:current] = nil
end

#install!Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/evm/package.rb', line 48

def install!
  unless File.exist?(path)
    Dir.mkdir(path)
  end

  unless File.exist?(tmp_path)
    Dir.mkdir(tmp_path)
  end

  Evm::Builder.new(recipe).build!
end

#installed?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/evm/package.rb', line 14

def installed?
  File.file?(bin) && File.executable?(bin)
end

#pathObject



78
79
80
# File 'lib/evm/package.rb', line 78

def path
  File.join(Evm.config[:path], @name)
end

#recipeObject



74
75
76
# File 'lib/evm/package.rb', line 74

def recipe
  Evm::Recipe.find(@name)
end

#tmp_pathObject



82
83
84
# File 'lib/evm/package.rb', line 82

def tmp_path
  File.join(Evm.config[:path], 'tmp')
end

#to_sObject



70
71
72
# File 'lib/evm/package.rb', line 70

def to_s
  @name
end

#uninstall!Object



60
61
62
63
64
65
66
67
68
# File 'lib/evm/package.rb', line 60

def uninstall!
  if File.exist?(path)
    FileUtils.rm_r(path)
  end

  if current?
    FileUtils.rm(Evm::EVM_EMACS_PATH)
  end
end

#use!Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/evm/package.rb', line 26

def use!
  delete_shims!
  [Evm::EMACS_PATH, Evm::EVM_EMACS_PATH].each do |bin_path|
    @file.open(bin_path, 'w') do |file|
      file.puts("#!/bin/bash\nexec \"#{bin}\" \"$@\"")
    end
    @file.chmod(0755, bin_path)
  end
  Evm.config[:current] = name
end