Module: KeepUp::GemspecFilter

Defined in:
lib/keep_up/gemspec_filter.rb

Overview

Filter to update dependency information in a Gemspec.

Class Method Summary collapse

Class Method Details

.apply(contents, dependency) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/keep_up/gemspec_filter.rb', line 6

def self.apply(contents, dependency)
  matcher = dependency_matcher(dependency)
  contents.each_line.map do |line|
    if line =~ matcher
      match = Regexp.last_match
      "#{match[1]}#{dependency.version}#{match[2]}"
    else
      line
    end
  end.join
end

.dependency_matcher(dependency) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/keep_up/gemspec_filter.rb', line 18

def self.dependency_matcher(dependency)
  /
    ^(.*_dependency
    \s*(?:\(\s*)?
    (?:['"]|%q.)#{dependency.name}.(?:\.freeze)?,
    \s+\[?['"](?:~>|=)?\ *)
    [^'"]*
    (['"]\]?[^'"]*)$
  /mx
end