Class: Bundler::AutoUpdate::Gemfile

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

Overview

class GemUpdater

Instance Method Summary collapse

Instance Method Details

#contentString

Returns Gemfile content.

Returns:

  • (String)

    Gemfile content



166
167
168
# File 'lib/bundler_auto_update.rb', line 166

def content
  @content ||= read
end

#gem_line_regex(gem_name = '([\w-]+)') ⇒ RegEx

Regex that matches a gem definition line.

Returns:

  • (RegEx)

    matching [_, name, _, version, _, options]



142
143
144
# File 'lib/bundler_auto_update.rb', line 142

def gem_line_regex(gem_name = '([\w-]+)')
  /^\s*gem\s*['"]#{gem_name}['"]\s*(,\s*['"](.+)['"])?\s*(,\s*(.*))?\n?$/
end

#gemsObject

Note:

This funky code parser could be replaced by a funky dsl re-implementation



147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/bundler_auto_update.rb', line 147

def gems
  gems = []

  content.dup.each_line do |l|
    if match = l.match(gem_line_regex)
      _, name, _, version, _, options = match.to_a
      gems << Dependency.new(name, version, options)
    end
  end

  gems
end

#reload!Object

Reload Gemfile content



171
172
173
# File 'lib/bundler_auto_update.rb', line 171

def reload!
  @content = read
end

#update_gem(gem) ⇒ Object

Update Gemfile and run ‘bundle update’



161
162
163
# File 'lib/bundler_auto_update.rb', line 161

def update_gem(gem)
  update_content(gem) and write and run_bundle_update(gem)
end