ruby_dep 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4ff4303cb0495bdf891173620d7f617c38f9bb8c
4
+ data.tar.gz: 495b8ea913a703b6d4cf1a016e7b6cbeed4ef8dd
5
+ SHA512:
6
+ metadata.gz: e14fafce98b25dd34fafb1c429c764aa96717be3975ca64b9f42c64d40f858ffd7184c16313983828cd8c80815217585b34e41b557b71202ba1ab19105a205eb
7
+ data.tar.gz: 8e4fec2237d44ce2a4f6a608f57dc40f061ecde2048a6062ab2482dac96ab7f5438cb6c5aafc64e96c80b6d365d5a121e05f138e999a758b7b681f1f44f8e6ba
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,3 @@
1
+ Style/Documentation:
2
+ Description: Document classes and non-namespace modules.
3
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.4
5
+ before_install: gem install bundler -v 1.12.0.rc.4
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruby_dep.gemspec
4
+ gemspec
5
+
6
+ gem 'rake'
7
+
8
+ group :development do
9
+ gem 'rubocop', '~> 0.39.0'
10
+ gem 'guard-rubocop', '~> 1.2'
11
+ gem 'guard-rspec', '~> 4.6'
12
+ end
13
+
14
+ group :test do
15
+ gem 'rspec', '~> 3.4'
16
+ end
data/Guardfile ADDED
@@ -0,0 +1,77 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ group :specs, halt_on_fail: true do
28
+ guard :rspec, cmd: 'bundle exec rspec', failed_mode: :keep do
29
+ require 'guard/rspec/dsl'
30
+ dsl = Guard::RSpec::Dsl.new(self)
31
+
32
+ # Feel free to open issues for suggestions and improvements
33
+
34
+ # RSpec files
35
+ rspec = dsl.rspec
36
+ watch(rspec.spec_helper) { rspec.spec_dir }
37
+ watch(rspec.spec_support) { rspec.spec_dir }
38
+ watch(rspec.spec_files)
39
+
40
+ # Ruby files
41
+ ruby = dsl.ruby
42
+ dsl.watch_spec_files_for(ruby.lib_files)
43
+
44
+ # Rails files
45
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
46
+ dsl.watch_spec_files_for(rails.app_files)
47
+ dsl.watch_spec_files_for(rails.views)
48
+
49
+ watch(rails.controllers) do |m|
50
+ [
51
+ rspec.spec.call("routing/#{m[1]}_routing"),
52
+ rspec.spec.call("controllers/#{m[1]}_controller"),
53
+ rspec.spec.call("acceptance/#{m[1]}")
54
+ ]
55
+ end
56
+
57
+ # Rails config changes
58
+ watch(rails.spec_helper) { rspec.spec_dir }
59
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
60
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
61
+
62
+ # Capybara features specs
63
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
64
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
65
+
66
+ # Turnip features and steps
67
+ watch(%r{^spec/acceptance/(.+)\.feature$})
68
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
69
+ Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
70
+ end
71
+ end
72
+
73
+ guard :rubocop do
74
+ watch(/.+\.rb$/)
75
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
76
+ end
77
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Cezary Baginski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # RubyDep
2
+
3
+ Helps with various Ruby version management activities, such as:
4
+
5
+ 1. Reading supported Ruby version from a .travis.yml file
6
+ 2. More stuff planned (reading TargetRubyVersion from .rubocop.yml file?)
7
+
8
+ Reason: tests are the best indicator of compatibility.
9
+
10
+ So, it doesn't make mention the supported Ruby version(s) in:
11
+
12
+ 1. your gemspec
13
+ 2. your README
14
+ 3. your .travis.yml file
15
+
16
+ (That breaks the principle of single responsibility).
17
+
18
+ Instead, it's better to:
19
+
20
+ - point to the Travis build in your README (or your gem home page on rubygems.org)
21
+ - extract the supported versions from your .travis.yml
22
+ - set the versions automatically in your Gemspec
23
+
24
+
25
+ ## Installation
26
+
27
+ Add this line to your application's Gemfile:
28
+
29
+ ```ruby
30
+ gem 'ruby_dep'
31
+ ```
32
+
33
+ And then execute:
34
+
35
+ $ bundle
36
+
37
+ Or install it yourself as:
38
+
39
+ $ gem install ruby_dep
40
+
41
+ ## Usage
42
+
43
+ E.g. in your gemspec file:
44
+
45
+ ```ruby
46
+ require 'ruby_dep'
47
+
48
+ # (...)
49
+
50
+ spec.required_ruby_version = RubyDep::Travis.new.version_constraint
51
+ ```
52
+
53
+ ## Development
54
+
55
+ Use `rake` to run tests.
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/e2/ruby_dep.
60
+
61
+ ## License
62
+
63
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |task|
5
+ task.verbose = false
6
+ end
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'ruby_dep'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/ruby_dep.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'ruby_dep/version'
2
+ require 'ruby_dep/travis'
@@ -0,0 +1,54 @@
1
+ require 'yaml'
2
+
3
+ module RubyDep
4
+ class Travis
5
+ def version_constraint(filename = '.travis.yml')
6
+ yaml = YAML.load(IO.read(filename))
7
+ versions = supported_versions(yaml)
8
+
9
+ selected = versions_for_latest_major(versions)
10
+ lowest = lowest_supported(selected)
11
+
12
+ ["~> #{lowest[0..1].join('.')}", ">= #{lowest.join('.')}"]
13
+ end
14
+
15
+ private
16
+
17
+ def versions_for_latest_major(versions)
18
+ by_major = versions.map do |x|
19
+ Gem::Version.new(x).segments[0..2]
20
+ end.group_by(&:first)
21
+
22
+ last_supported_major = by_major.keys.sort.last
23
+ by_major[last_supported_major]
24
+ end
25
+
26
+ def lowest_supported(versions)
27
+ selected = versions.sort.reverse!
28
+ grouped_by_minor = selected.group_by { |x| x[1] }
29
+
30
+ lowest_minor = lowest_minor_without_skipping(grouped_by_minor)
31
+ grouped_by_minor[lowest_minor].sort.first
32
+ end
33
+
34
+ def failable(yaml)
35
+ matrix = yaml.fetch('matrix', {})
36
+ allowed = matrix.fetch('allow_failures', [])
37
+ allowed.map(&:values).flatten
38
+ end
39
+
40
+ def supported_versions(yaml)
41
+ yaml['rvm'] - failable(yaml)
42
+ end
43
+
44
+ def lowest_minor_without_skipping(grouped_by_minor)
45
+ minors = grouped_by_minor.keys.flatten
46
+ lowest = minors.shift
47
+ current = lowest
48
+ while (lower = minors.shift)
49
+ (current -= 1) == lower ? lowest = lower : break
50
+ end
51
+ lowest
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module RubyDep
2
+ VERSION = '1.0.0'.freeze
3
+ end
data/ruby_dep.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruby_dep/version'
5
+
6
+ # Yes, inception: we're using this ourselves
7
+ require 'ruby_dep/travis'
8
+
9
+ Gem::Specification.new do |spec|
10
+ spec.name = 'ruby_dep'
11
+ spec.version = RubyDep::VERSION
12
+ spec.authors = ['Cezary Baginski']
13
+ spec.email = ['cezary@chronomantic.net']
14
+
15
+ spec.summary = 'Extracts supported Ruby versions from Travis file'
16
+ spec.description = 'Creates a version constraint of supported Rubies,' \
17
+ 'suitable for a gemspec file'
18
+ spec.homepage = 'https://github.com/e2/ruby_dep'
19
+ spec.license = 'MIT'
20
+
21
+ spec.required_ruby_version = RubyDep::Travis.new.version_constraint
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
24
+ f.match(%r{^(test|spec|features)/})
25
+ end
26
+
27
+ spec.bindir = 'exe'
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ['lib']
30
+
31
+ spec.add_development_dependency 'bundler', '~> 1.12.a'
32
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_dep
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Cezary Baginski
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.12.a
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.12.a
27
+ description: Creates a version constraint of supported Rubies,suitable for a gemspec
28
+ file
29
+ email:
30
+ - cezary@chronomantic.net
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - ".rspec"
37
+ - ".rubocop.yml"
38
+ - ".travis.yml"
39
+ - Gemfile
40
+ - Guardfile
41
+ - LICENSE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - bin/console
45
+ - bin/setup
46
+ - lib/ruby_dep.rb
47
+ - lib/ruby_dep/travis.rb
48
+ - lib/ruby_dep/version.rb
49
+ - ruby_dep.gemspec
50
+ homepage: https://github.com/e2/ruby_dep
51
+ licenses:
52
+ - MIT
53
+ metadata: {}
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '2.2'
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 2.2.4
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.6.3
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Extracts supported Ruby versions from Travis file
77
+ test_files: []