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) ⇒ Package

Returns a new instance of Package.



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

def initialize(name)
  @name = name
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



89
90
91
92
93
94
# File 'lib/evm/package.rb', line 89

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

.currentObject



71
72
73
74
75
76
77
78
# File 'lib/evm/package.rb', line 71

def current
  if File.symlink?(Evm::EVM_EMACS_PATH)
    current_bin_path = File.readlink(Evm::EVM_EMACS_PATH)
    if (match = Regexp.new("#{Evm::LOCAL_PATH}/?(?<current>[^/]+)/.+").match(current_bin_path))
      find match[:current]
    end
  end
end

.find(package_name) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/evm/package.rb', line 80

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



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

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)


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

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

#install!Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/evm/package.rb', line 32

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)


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

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

#pathObject



62
63
64
# File 'lib/evm/package.rb', line 62

def path
  File.join(Evm::LOCAL_PATH, @name)
end

#recipeObject



58
59
60
# File 'lib/evm/package.rb', line 58

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

#tmp_pathObject



66
67
68
# File 'lib/evm/package.rb', line 66

def tmp_path
  File.join(Evm::LOCAL_PATH, 'tmp')
end

#to_sObject



54
55
56
# File 'lib/evm/package.rb', line 54

def to_s
  @name
end

#uninstall!Object



44
45
46
47
48
49
50
51
52
# File 'lib/evm/package.rb', line 44

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

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

#use!Object



25
26
27
28
29
30
# File 'lib/evm/package.rb', line 25

def use!
  FileUtils.ln_sf(bin, Evm::EVM_EMACS_PATH)
  unless File.symlink?(Evm::EMACS_PATH)
    FileUtils.ln_sf(Evm::EVM_EMACS_PATH, Evm::EMACS_PATH)
  end
end