Class: Bundleup::Gemfile
- Inherits:
-
Object
- Object
- Bundleup::Gemfile
- Defined in:
- lib/bundleup/gemfile.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #gem_comments ⇒ Object
- #gem_pins_without_comments ⇒ Object
-
#initialize(path = "Gemfile") ⇒ Gemfile
constructor
A new instance of Gemfile.
- #relax_gem_pins!(gem_names) ⇒ Object
- #shift_gem_pins!(new_gem_versions) ⇒ Object
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
#path ⇒ Object (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_comments ⇒ Object
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_comments ⇒ Object
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 |