Skip to content

Commit

Permalink
Merge pull request #376 from guard/fix_version_constraints
Browse files Browse the repository at this point in the history
Use .travis.yml to set gem's dependency on Ruby
  • Loading branch information
e2 committed Apr 26, 2016
2 parents 45f37f9 + 2446102 commit 6276301
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The Listen gem listens to file modifications and notifies you about the changes.
* You can watch multiple directories.
* Regexp-patterns for ignoring paths for more accuracy and speed
* Increased change detection accuracy on OS X HFS and VFAT volumes.
* Tested on MRI Ruby environments (2.2+ only) via [Travis CI](https://travis-ci.org/guard/listen),
* Tested on selected Ruby environments via [Travis CI](https://travis-ci.org/guard/listen). (See [.travis.yml](https:///github.com/guard/listen/master/.travis.yml) for supported/tested Ruby Versions),

## Issues / limitations

Expand Down
25 changes: 24 additions & 1 deletion listen.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@ lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'listen/version'

require 'yaml'

def ruby_version_constraint(filename = '.travis.yml')
yaml = YAML.load(IO.read(filename))
failable = yaml['matrix']['allow_failures'].map(&:values).flatten
versions = yaml['rvm'] - failable

by_major = versions.map do |x|
Gem::Version.new(x).segments[0..2]
end.group_by(&:first)

last_supported_major = by_major.keys.sort.last
selected = by_major[last_supported_major].sort.reverse

lowest = selected.shift
current = lowest[1]
while( lower = selected.shift)
(current -= 1) == lower[1] ? lowest = lower : break
end

["~> #{lowest[0..1].join('.')}", ">= #{lowest.join('.')}"]
end

Gem::Specification.new do |s|
s.name = 'listen'
s.version = Listen::VERSION
Expand All @@ -22,7 +45,7 @@ Gem::Specification.new do |s|
s.executable = 'listen'
s.require_path = 'lib'

s.required_ruby_version = '~> 2.2'
s.required_ruby_version = ruby_version_constraint

s.add_dependency 'rb-fsevent', '>= 0.9.3'
s.add_dependency 'rb-inotify', '>= 0.9.7'
Expand Down

0 comments on commit 6276301

Please sign in to comment.