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



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

def current
  if File.exist?(current_file)
    find File.read(current_file)
  end
end

.current_fileObject



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

def current_file
  File.join(Evm::LOCAL_PATH, 'current')
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



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

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.exist?(path)
end

#pathObject



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

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

#recipeObject



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

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

#tmp_pathObject



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

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

#to_sObject



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

def to_s
  @name
end

#uninstall!Object



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

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

  if current?
    File.delete(Package.current_file)
  end
end

#use!Object



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

def use!
  File.open(Package.current_file, 'w') do |file|
    file.write(@name)
  end
end