Class: Dep::List

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = File.join(Dir.pwd, ".gems")) ⇒ List

Returns a new instance of List.



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

def initialize(path = File.join(Dir.pwd, ".gems"))
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#add(lib) ⇒ Object



9
10
11
12
# File 'lib/dep.rb', line 9

def add(lib)
  remove(lib)
  libraries.push(lib)
end

#librariesObject



18
19
20
# File 'lib/dep.rb', line 18

def libraries
  @libraries ||= File.readlines(path).map { |line| Lib[line] }
end

#missing_librariesObject



22
23
24
# File 'lib/dep.rb', line 22

def missing_libraries
  libraries.reject(&:available?)
end

#remove(lib) ⇒ Object



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

def remove(lib)
  libraries.delete_if { |e| e.name == lib.name }
end

#saveObject



26
27
28
29
30
31
32
# File 'lib/dep.rb', line 26

def save
  File.open(path, "w") do |file|
    libraries.each do |lib|
      file.puts lib.to_s
    end
  end
end