Class: UpmSupport::UpfileLock

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ UpfileLock

Returns a new instance of UpfileLock.



10
11
12
13
# File 'lib/upm_support/uplift.rb', line 10

def initialize(path)
  @path = path
  @content = File.read(path).split("\n")
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/upm_support/uplift.rb', line 8

def path
  @path
end

Instance Method Details

#dependenciesObject



15
16
17
18
19
20
21
# File 'lib/upm_support/uplift.rb', line 15

def dependencies
  idx = @content.index('# SOLVED DEPENDENCIES')
  @content[(idx + 1)..].grep(/^[A-z]/).to_h do |l|
    m = l.match(/(.*) \((.*)\)/)
    [m[1], m[2]]
  end
end

#remove_dependency(name, version) ⇒ Object



23
24
25
26
# File 'lib/upm_support/uplift.rb', line 23

def remove_dependency(name, version)
  idx = @content.index('# SOLVED DEPENDENCIES')
  @content = @content.reject.each_with_index { |l, ix| ix > idx and l =~ /^#{name} \(#{version}\)/ }
end

#saveObject



28
29
30
# File 'lib/upm_support/uplift.rb', line 28

def save
  File.write(@path, @content.join("\n"))
end