Class: Bundleup::Gemfile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = "Gemfile") ⇒ Gemfile

Returns a new instance of Gemfile.



5
6
7
8
# File 'lib/bundleup/gemfile.rb', line 5

def initialize(path="Gemfile")
  @path = path
  @contents = File.read(path)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#gem_commentsObject



10
11
12
13
14
15
# File 'lib/bundleup/gemfile.rb', line 10

def gem_comments
  gem_names.each_with_object({}) do |gem_name, hash|
    comment = inline_comment(gem_name) || prefix_comment(gem_name)
    hash[gem_name] = comment unless comment.nil?
  end
end

#gem_pins_without_commentsObject



17
18
19
20
21
22
23
24
# File 'lib/bundleup/gemfile.rb', line 17

def gem_pins_without_comments
  (gem_names - gem_comments.keys).each_with_object({}) do |gem_name, hash|
    next unless (match = gem_declaration_with_pinned_version_re(gem_name).match(contents))

    version = match[1]
    hash[gem_name] = VersionSpec.parse(version)
  end
end

#relax_gem_pins!(gem_names) ⇒ Object



26
27
28
29
30
# File 'lib/bundleup/gemfile.rb', line 26

def relax_gem_pins!(gem_names)
  gem_names.each do |gem_name|
    rewrite_gem_version!(gem_name, &:relax)
  end
end

#shift_gem_pins!(new_gem_versions) ⇒ Object



32
33
34
35
36
# File 'lib/bundleup/gemfile.rb', line 32

def shift_gem_pins!(new_gem_versions)
  new_gem_versions.each do |gem_name, new_version|
    rewrite_gem_version!(gem_name) { |version_spec| version_spec.shift(new_version) }
  end
end