Class: Bundler::AutoUpdate::Gemfile
- Inherits:
-
Object
- Object
- Bundler::AutoUpdate::Gemfile
- Defined in:
- lib/bundler_auto_update.rb
Overview
class GemUpdater
Instance Method Summary collapse
-
#content ⇒ String
Gemfile content.
-
#gem_line_regex(gem_name = '([\w-]+)') ⇒ RegEx
Regex that matches a gem definition line.
- #gems ⇒ Object
-
#reload! ⇒ Object
Reload Gemfile content.
-
#update_gem(gem) ⇒ Object
Update Gemfile and run ‘bundle update’.
Instance Method Details
#content ⇒ String
Returns 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.
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 |
#gems ⇒ Object
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, _, = match.to_a gems << Dependency.new(name, version, ) 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 |