ruby_version_sorter 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: 60241d50bce547b299cf5b13eb0ed7a90259f0f0
4
+ data.tar.gz: 3cd6e621bbf1f73371506471f99d0fb9d0d39779
5
+ SHA512:
6
+ metadata.gz: df5fda3ae8ff03a6b29185aa94e6eb4267b110905b773c969dd8d0436cb6e5591eeb1c4b8d1527bce22d139734f312c87df4b3a0e1e323ec10e22dd31b569565
7
+ data.tar.gz: ad9978d24bc417735ba31b090e6b7933343c352e9e1258056584f53d117a07c9c50a00a6e79175d8712a8143a1fe6ba6fdaa2e15e8fca1debfab52d95ac0ad52
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/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.3.1
6
+ - 2.3.0
7
+ - 2.2
8
+ - 2.1
9
+ - 2.0
10
+ - ruby-head
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: 2.0
14
+ - rvm: ruby-head
15
+ fast_finish: true
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # CHANGELOG
2
+
3
+ ## Unreleased
4
+
5
+ ## 1.0.0
6
+
7
+ 2016.08.10.
8
+
9
+ Implement ruby_version_sorter.
10
+
11
+ ## 0.1.0
12
+
13
+ 2016.08.09.
14
+
15
+ ruby_version_sorter gem init.
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,19 @@
1
+ # CONTRIBUTING
2
+
3
+ First, thank you for contributing!
4
+
5
+ I love pull requests from everyone.
6
+
7
+ Here are a few technical guidelines to follow:
8
+
9
+ 1. Open an issue to discuss a new feature.
10
+ 1. Write tests.
11
+ 1. Make sure the entire test suite passes locally and on CI.
12
+ 1. Open a Pull Request to receive feedback.
13
+ 1. Party!
14
+
15
+ ## Development
16
+
17
+ After checking out the repo, run `bin/setup` to install dependencies. Run `bundle exec rake spec` to run the tests. You can also run `bin/hack` for an interactive prompt that will allow you to experiment.
18
+
19
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ruby_version_sorter.gemspec
4
+ gemspec
5
+
6
+ gem "bundler"
7
+ gem "rake"
8
+ gem "rspec", "~> 3.5"
9
+ gem "pry"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 JuanitoFatas
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,44 @@
1
+ # RubyVersionSorter
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/ruby_version_sorter.svg)](https://badge.fury.io/rb/ruby_version_sorter)
4
+ [![Build Status](https://travis-ci.org/jollygoodcode/ruby_version_sorter.svg)][travis]
5
+
6
+ [gem]: https://rubygems.org/gems/ruby_version_sorter
7
+ [travis]: https://travis-ci.org/jollygoodcode/ruby_version_sorter
8
+
9
+ Sort Ruby Versions for human! Works for Ruby and JRuby.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'ruby_version_sorter'
17
+
18
+ # or if you prefer double quote:
19
+
20
+ gem "ruby_version_sorter"
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install ruby_version_sorter
30
+
31
+ ## Usage
32
+
33
+ ```ruby
34
+ > RubyVersionSorter.sort ["2.0.0", "2.0.0-rc1", "2.0.0-rc2", "2.0.0-preview1"]
35
+ => ["2.0.0-preview1", "2.0.0-rc1", "2.0.0-rc2", "2.0.0"]
36
+ ```
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/JuanitoFatas/ruby_version_sorter.
41
+
42
+ ## License
43
+
44
+ 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,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/hack ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruby_version_sorter"
5
+
6
+ require "pry"
7
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$"\n\t"
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,3 @@
1
+ class RubyVersionSorter
2
+ VERSION = "1.0.0".freeze
3
+ end
@@ -0,0 +1,67 @@
1
+ require "ruby_version_sorter/version"
2
+
3
+ class RubyVersionSorter
4
+ def self.sort(versions)
5
+ new(versions).send :move_prereleases
6
+ end
7
+
8
+ def initialize(versions)
9
+ pre_releases, @non_pre_releases = versions.sort.partition { |v| v =~ PRERELEASE_REGEXP }
10
+ @pre_release_groups = pre_releases.group_by { |v| node_identifier(v) }
11
+ end
12
+
13
+ private
14
+
15
+ PRERELEASE_REGEXP = /((preview|rc|RC|pre|b)\d{1})/
16
+ IDENTIFIER_REGEXP = /([\d+\.])*/
17
+
18
+ private_constant :PRERELEASE_REGEXP, :IDENTIFIER_REGEXP
19
+
20
+ attr_reader :versions, :non_pre_releases, :pre_release_groups
21
+
22
+ def move_prereleases
23
+ pre_release_groups.each_with_index do |(version_lead, versions), index|
24
+ node_index = version_nodes.index { |node| node[0] == version_lead }
25
+
26
+ insert_index = get_insert_index(node_index)
27
+
28
+ non_pre_releases.insert(insert_index, *versions)
29
+
30
+ version_nodes(true) if !(index == pre_release_group_length - 1)
31
+ end
32
+
33
+ non_pre_releases
34
+ end
35
+
36
+ def pre_release_group_length
37
+ @_pre_release_group_length ||= pre_release_groups.size
38
+ end
39
+
40
+ def get_insert_index(node_index)
41
+ if node_index == 0
42
+ 0
43
+ elsif node_index == nil
44
+ -1
45
+ else
46
+ version_nodes[node_index].last
47
+ end
48
+ end
49
+
50
+ def node_identifier(version)
51
+ version[IDENTIFIER_REGEXP]
52
+ end
53
+
54
+ def version_nodes(recompute = false)
55
+ if recompute
56
+ @_evolve_graph = compute_version_nodes
57
+ else
58
+ @_evolve_graph ||= compute_version_nodes
59
+ end
60
+ end
61
+
62
+ def compute_version_nodes
63
+ non_pre_releases.
64
+ uniq { |version| node_identifier(version) }.
65
+ map.with_index { |version, index| [node_identifier(version), index] }
66
+ end
67
+ end
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ruby_version_sorter/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruby_version_sorter"
8
+ spec.version = RubyVersionSorter::VERSION
9
+ spec.authors = ["JuanitoFatas"]
10
+ spec.email = ["katehuang0320@gmail.com"]
11
+
12
+ spec.summary = %q{Sort Ruby & JRuby versions}
13
+ spec.homepage = "https://github.com/juanitofatas/ruby_version_sorter"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r(^(spec)/)) }
17
+ # spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r(^exe/)) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_version_sorter
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - JuanitoFatas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - katehuang0320@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".travis.yml"
23
+ - CHANGELOG.md
24
+ - CONTRIBUTING.md
25
+ - Gemfile
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - bin/hack
30
+ - bin/setup
31
+ - lib/ruby_version_sorter.rb
32
+ - lib/ruby_version_sorter/version.rb
33
+ - ruby_version_sorter.gemspec
34
+ homepage: https://github.com/juanitofatas/ruby_version_sorter
35
+ licenses:
36
+ - MIT
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.6.4
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Sort Ruby & JRuby versions
58
+ test_files: []
59
+ has_rdoc: