version_compare 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +5 -13
  2. data/.gitignore +11 -0
  3. data/.travis.yml +21 -0
  4. data/CHANGELOG.md +10 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +51 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +84 -63
  9. data/Rakefile +6 -28
  10. data/bin/console +15 -0
  11. data/bin/setup +8 -0
  12. data/lib/version_compare.rb +3 -3
  13. data/lib/version_compare/comparable_version.rb +66 -55
  14. data/lib/version_compare/conversions.rb +34 -32
  15. data/lib/version_compare/version.rb +3 -0
  16. data/version_compare.gemspec +40 -0
  17. metadata +108 -98
  18. data/MIT-LICENSE +0 -20
  19. data/test/comparable_version_test.rb +0 -188
  20. data/test/conversions_test.rb +0 -82
  21. data/test/dummy/README.rdoc +0 -28
  22. data/test/dummy/Rakefile +0 -6
  23. data/test/dummy/app/assets/javascripts/application.js +0 -13
  24. data/test/dummy/app/assets/stylesheets/application.css +0 -13
  25. data/test/dummy/app/controllers/application_controller.rb +0 -5
  26. data/test/dummy/app/helpers/application_helper.rb +0 -2
  27. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  28. data/test/dummy/bin/bundle +0 -3
  29. data/test/dummy/bin/rails +0 -4
  30. data/test/dummy/bin/rake +0 -4
  31. data/test/dummy/config.ru +0 -4
  32. data/test/dummy/config/application.rb +0 -29
  33. data/test/dummy/config/boot.rb +0 -5
  34. data/test/dummy/config/database.yml +0 -25
  35. data/test/dummy/config/environment.rb +0 -5
  36. data/test/dummy/config/environments/development.rb +0 -29
  37. data/test/dummy/config/environments/production.rb +0 -80
  38. data/test/dummy/config/environments/test.rb +0 -36
  39. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  40. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  41. data/test/dummy/config/initializers/inflections.rb +0 -16
  42. data/test/dummy/config/initializers/mime_types.rb +0 -5
  43. data/test/dummy/config/initializers/secret_token.rb +0 -12
  44. data/test/dummy/config/initializers/session_store.rb +0 -3
  45. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  46. data/test/dummy/config/locales/en.yml +0 -23
  47. data/test/dummy/config/routes.rb +0 -56
  48. data/test/dummy/log/test.log +0 -0
  49. data/test/dummy/public/404.html +0 -58
  50. data/test/dummy/public/422.html +0 -58
  51. data/test/dummy/public/500.html +0 -57
  52. data/test/dummy/public/favicon.ico +0 -0
  53. data/test/test_helper.rb +0 -13
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NDgxYzAxZWFkMzA1Mjc1NWIzODA4ZjA2Y2YzMWQ2OGM4ZWZjYjNmNg==
5
- data.tar.gz: !binary |-
6
- ZDYwNWExZDY4NmIyMjFiOWVhMDEyYmViNTNlNmQyYTdjYWVjNjkzNA==
2
+ SHA256:
3
+ metadata.gz: dd6d497116771a495a959a05ac9631cc1f5c2ccfa79dd5b07acb0645dc4aad16
4
+ data.tar.gz: b42d17c0e5b838dbd017238520df113d85f9c1c25edc73a2ae0aa3c7f999055f
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ODRlYjc2YmE3N2RiYWY2NjgzZDYxZTg4MzBkZGIxZjgxNmM2NGY4YzY4MGUz
10
- NDZlMjc0ZDQ5ODU1MjRkMDY2MjJmMDhkMWUwNjVkMzU0YTczMDk2MzlmYmFi
11
- NTY5Mjk1MzY1OTk2YWYxNzZlYTQ4YjJiOGY5OGNjYzVlZGFjNTc=
12
- data.tar.gz: !binary |-
13
- ZjVjZTM2NjJlYTc1M2Q3M2QwNmY0Nzc4NmNmZDAwN2FlM2E4NTE4NmU4NmNl
14
- MTQzZDA0NzExYmVlNzk1YjBkOTVkYWMyOTFjNWZiZjcxMjBiODRiNzAzMjU4
15
- ODBkNzYyODMxM2Q3ZjEwMGEwOWNhYzk1OGNjMDQzNDgxZGRhOTU=
6
+ metadata.gz: 9a0ffe52ba8b4d99e6db7ecdca5cf3d7e4c927e36cd60257182bd1f5d7bdb777517ef30ecf8bc1ac7bee5ddb872746254180c13a8691ea8f625a0bcc8265b8d3
7
+ data.tar.gz: cd20ac6a80d5dd3f30b92b6837d3d3d9f59ba93c91bfefc0df5c1dd965bf342b58ca66e71cf708d8d02070d787da589de76b27416cd362216b6ae8055bee9431
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .byebug_history
10
+ *.gem
11
+ .DS_Store
@@ -0,0 +1,21 @@
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=a8a8d1a4975b389da2409fc5767cf53a7e995e15db36cef9332d9c3f87227abc
4
+ sudo: false
5
+ language: ruby
6
+ rvm:
7
+ - 2.2.10
8
+ - 2.3.7
9
+ - 2.4.4
10
+ - 2.5.1
11
+ - ruby-head
12
+ notifications:
13
+ email: false
14
+ before_install: gem install bundler -v 1.16.1
15
+ cache: bundler
16
+ before_script:
17
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
18
+ - chmod +x ./cc-test-reporter
19
+ - ./cc-test-reporter before-build
20
+ after_script:
21
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -0,0 +1,10 @@
1
+ ### 0.2.0 - 2018-04-15
2
+ - Refresh gem.
3
+ - Add VersionCmopare namespace to Conversions module.
4
+
5
+
6
+ ### 0.1.1 - 2016-07-03
7
+
8
+ - Update: Renamed "Version" to "ComparableVersion" to avoid name conflicts in including projects.
9
+ - Add ability to specify separator character as an initialization option.
10
+ - Add ComparableVersion#inspect for more informative inspect output.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in version_compare.gemspec
6
+ gemspec
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ version_compare (0.2.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ansi (1.5.0)
10
+ builder (3.2.3)
11
+ byebug (10.0.2)
12
+ coderay (1.1.2)
13
+ docile (1.3.0)
14
+ json (2.1.0)
15
+ method_source (0.9.0)
16
+ minitest (5.11.3)
17
+ minitest-reporters (1.2.0)
18
+ ansi
19
+ builder
20
+ minitest (>= 5.0)
21
+ ruby-progressbar
22
+ pry (0.11.3)
23
+ coderay (~> 1.1.0)
24
+ method_source (~> 0.9.0)
25
+ pry-byebug (3.6.0)
26
+ byebug (~> 10.0)
27
+ pry (~> 0.10)
28
+ rake (10.5.0)
29
+ ruby-progressbar (1.9.0)
30
+ simplecov (0.16.1)
31
+ docile (~> 1.1)
32
+ json (>= 1.8, < 3)
33
+ simplecov-html (~> 0.10.0)
34
+ simplecov-html (0.10.2)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ bundler (~> 1.16)
41
+ byebug (~> 10.0)
42
+ minitest (~> 5.0)
43
+ minitest-reporters (~> 1.2)
44
+ pry (~> 0.11)
45
+ pry-byebug (~> 3.6)
46
+ rake (~> 10.0)
47
+ simplecov (~> 0.16)
48
+ version_compare!
49
+
50
+ BUNDLED WITH
51
+ 1.16.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Paul Dobbins
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 CHANGED
@@ -1,13 +1,13 @@
1
1
  # Version Compare
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/version_compare.png)](http://badge.fury.io/rb/version_compare)
3
+ [![Gem Version](https://badge.fury.io/rb/version_compare.svg)](https://badge.fury.io/rb/version_compare)
4
+ [![Build Status](https://travis-ci.org/pdobb/version_compare.svg?branch=master)](https://travis-ci.org/pdobb/version_compare)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/99cb6a37ab03e0aa246e/test_coverage)](https://codeclimate.com/github/pdobb/version_compare/test_coverage)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/99cb6a37ab03e0aa246e/maintainability)](https://codeclimate.com/github/pdobb/version_compare/maintainability)
4
7
 
5
- Version Compare allows you to easily compare if one Version (string) to another
6
- Version (string). It aims to be as light and flexible as possible. Inputs can be
7
- a String, Integer, Float, Array, or any object that defines `#to_comparable_version`.
8
+ VersionCompare simplifies comparison of version numbers with other version numbers. It aims to be as light and flexible as possible. Inputs can be a String, Integer, Float, Array, or any object that defines `#to_comparable_version`.
8
9
 
9
- For simplicity's sake, Version Compare only works with up to four numeric
10
- values:
10
+ For simplicity's sake, Version Compare only works with up to four numeric values.
11
11
 
12
12
  ```ruby
13
13
  "<major>.<minor>.<tiny>.<patch>"
@@ -15,14 +15,6 @@ values:
15
15
  ```
16
16
 
17
17
 
18
- ## Compatibility
19
-
20
- Tested with:
21
-
22
- * Ruby: MRI 1.9.3
23
- * Ruby: MRI 2+
24
-
25
-
26
18
  ## Installation
27
19
 
28
20
  Add this line to your application's Gemfile:
@@ -33,121 +25,150 @@ gem "version_compare"
33
25
 
34
26
  And then execute:
35
27
 
36
- ```ruby
37
- bundle
38
- ```
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install version_compare
33
+
34
+
35
+ ## Compatibility
36
+
37
+ Tested MRI Ruby Versions:
38
+ * 2.2.10
39
+ * 2.3.7
40
+ * 2.4.4
41
+ * 2.5.1
42
+ * edge
43
+
44
+ VersionCompare has no other dependencies.
39
45
 
40
46
 
41
47
  ## Usage
42
48
 
43
49
  To get started, you can either use `ComparableVersion.new(<value>)` or `ComparableVersion(<value>)`.
44
- To get the latter to work, you'll need to call `include ::Conversions` in the
45
- class or context you're wanting to use it at.
50
+ To get the latter to work, you'll need to call `include VersionCompare::Conversions` in the class or context you're wanting to use it at.
46
51
 
47
52
  ```ruby
48
- class MyClass
49
- include Conversions
53
+ class MyObject
54
+ include VersionCompare::Conversions
50
55
 
51
56
  def my_method
52
57
  ComparableVersion(1) > ComparableVersion(2)
53
58
  end
54
59
  end
60
+
61
+ MyObject.new.my_method # => false
55
62
  ```
56
63
 
57
64
  Or, to test on the Rails Console:
58
65
 
59
66
  ```ruby
60
- [1] pry(main)> include ::Conversions
61
- => Object
62
- [2] pry(main)> ComparableVersion(1.0) > ComparableVersion(1)
63
- => false
67
+ [1] pry(main)> include VersionCompare::Conversions # => Object
68
+ [2] pry(main)> ComparableVersion(1.0) > ComparableVersion(1) # => false
64
69
 
65
- # - OR (without using `include ::Conversions`) -
70
+ # - OR (without using `include VersionCompare::Conversions`) -
66
71
 
67
- [1] pry(main)> Conversions.ComparableVersion(1.0) > Conversions.ComparableVersion(1)
68
- => false
72
+ [1] pry(main)> VersionCompare::Conversions.ComparableVersion(1.0) > VersionCompare::Conversions.ComparableVersion(1)
73
+ # => false
69
74
  ```
70
75
 
71
- ComparableVersion Compare uses the `Comparable` mixin for comparisons, so you get all the
72
- usual operators:
76
+ ComparableVersion Compare uses the `Comparable` mix-in for comparisons, so you get all the usual operators:
73
77
 
74
78
  ```ruby
75
- ComparableVersion(2) > ComparableVersion(1) # => true
76
- ComparableVersion(1.2) > ComparableVersion(1.2) # => false
77
- ComparableVersion("1.2.3") >= ComparableVersion("1.2") # => true
78
- ComparableVersion("1.2.3.4") <= ComparableVersion("1.2.3.4") # => true
79
- ComparableVersion([1, 2]) == ComparableVersion(["1", "2"]) # => true
80
- ComparableVersion("1.2.0.0") == ComparableVersion(1.2) # => true
81
- ComparableVersion("1.0.0.0") != ComparableVersion(1) # => false
82
- [ComparableVersion(1), ComparableVersion("1.0.0.1"), ComparableVersion(0.1)].sort # => ["0.1", "1", "1.0.0.1"]
83
- [ComparableVersion(1), ComparableVersion("1.0.0.1"), ComparableVersion(0.1)].sort { |a, b| b <=> a } # => ["1.0.0.1", "1", "0.1"]
79
+ include VersionCompare::Conversions
80
+
81
+ ComparableVersion(2) > ComparableVersion(1) # => true
82
+ ComparableVersion(1.2) > ComparableVersion(1.2) # => false
83
+ ComparableVersion("1.2.3") >= ComparableVersion("1.2") # => true
84
+ ComparableVersion("1.2.3.4") <= ComparableVersion("1.2.3.4") # => true
85
+ ComparableVersion([1, 2]) == ComparableVersion(["1", "2"]) # => true
86
+ ComparableVersion("1.2.0.0") == ComparableVersion(1.2) # => true
87
+ ComparableVersion("1.0.0.0") != ComparableVersion(1) # => false
88
+
89
+ [
90
+ ComparableVersion(1),
91
+ ComparableVersion("1.0.0.1"),
92
+ ComparableVersion(0.1)
93
+ ].sort.map(&:to_s)
94
+ # => ["0.1", "1", "1.0.0.1"]
95
+
96
+ [
97
+ ComparableVersion(1),
98
+ ComparableVersion("1.0.0.1"),
99
+ ComparableVersion(0.1)
100
+ ].sort { |a, b| b <=> a }.map(&:to_s)
101
+ # => ["1.0.0.1", "1", "0.1"]
84
102
  ```
85
103
 
86
104
 
87
105
  ### Wait, so what exactly is this `ComparableVersion` ... constant?
88
106
 
89
- `ComparableVersion()` is actually a conversion function. It follows the Ruby convention of
90
- defining a conversion function that uses the same name as the class it
91
- represents, such as how `Array()` converts inputs to an `Array` object.
92
- Just like the standard Ruby conversion functions, `ComparableVersion()` tries its hardest
93
- to convert any ComparableVersion-like input into a new `ComparableVersion` object. Given a numeric,
94
- string, or array input (which are all obvious conversions to make), `ComparableVersion()`
95
- is essentially the same as `ComparableVersion.new()`. However, `ComparableVersion()` is otherwise a
96
- little more strict in that if you pass in an object that doesn't reasonably look
97
- like a ComparableVersion it will raise a `TypeError` exception. Doing the same for
98
- `ComparableVersion.new()` will ultimately just `#to_s` the input; and since almost
99
- every object responds to `#to_s`, the result is that you may end up with a 0
100
- version. For example:
107
+ `ComparableVersion()` is a conversion function. It follows the Ruby convention of defining a conversion function that uses the same name as the class it represents, such as how `Array()` converts inputs to an `Array` object. Just like the standard Ruby conversion functions, `ComparableVersion()` tries its hardest to convert any ComparableVersion-like input into a new `ComparableVersion` object. Given a numeric, string, or array input (which are all obvious conversions to make), `ComparableVersion()` is essentially the same as `ComparableVersion.new()`. However, `ComparableVersion()` is otherwise a little more strict in that if you pass in an object that doesn't reasonably look like a ComparableVersion it will raise a TypeError. Doing the same for `ComparableVersion.new()` will ultimately just `#to_s` the input and, since almost every object responds to `#to_s`, the result is that you may end up with a 0 version.
101
108
 
102
109
  ```ruby
103
- ComparableVersion.new(OpenStruct.new(a: 1)).to_s # => "0"
110
+ VersionCompare::ComparableVersion.new(OpenStruct.new(a: 1)).to_s # => "0"
104
111
  ```
105
112
 
106
113
 
107
114
  ### Can I pass my own custom objects into `ComparableVersion()`?
108
115
 
109
- Yes! All you have to do is define a `#to_comparable_version` implicit conversion method in
110
- your object that creates a new ComparableVersion object in the usual fashion.
116
+ But of course! All you have to do is define a `#to_comparable_version` implicit conversion method in your object that creates a new ComparableVersion object in the usual fashion.
111
117
 
112
118
  ```ruby
113
119
  class MyObject
114
120
  VERSION = 1.9
121
+
115
122
  def to_comparable_version
116
- ComparableVersion.new(VERSION.to_s)
123
+ VersionCompare::ComparableVersion.new(VERSION.to_s)
117
124
  end
118
125
  end
119
126
 
120
- ComparableVersion(MyObject.new) > ComparableVersion(2.0) # => false
127
+ include VersionCompare::Conversions
128
+
129
+ ComparableVersion(MyObject.new) > ComparableVersion(2.0) # => false
121
130
  ```
122
131
 
123
132
 
124
133
  ### Why do you seem so excited about the custom object thing?
125
134
 
126
- Because, it opens up the world! Here's an example:
135
+ Because, objects should be [open for extension, but closed for modification](https://en.wikipedia.org/wiki/Open/closed_principle).
127
136
 
128
137
  ```ruby
129
138
  # Given a Rails app:
130
139
 
131
140
  # /config/application.rb
132
- module Dummy
141
+ module MyRailsApp
133
142
  class Application < Rails::Application
134
143
  # ...
135
144
 
136
145
  VERSION = "1.2".freeze
137
146
 
138
147
  def to_comparable_version
139
- ComparableVersion.new(VERSION) # Or ComparableVersion.new([1, 2]) or whatever...
148
+ VersionCompare::ComparableVersion.new(VERSION)
140
149
  end
141
150
  end
142
151
  end
143
152
 
144
153
  # Now, from the context of that Rails app you can call:
145
- ComparableVersion(Rails.application) > ComparableVersion(1.0) # => true
154
+ include VersionCompare::Conversions
155
+
156
+ ComparableVersion(Rails.application) > ComparableVersion(1.0) # => true
146
157
  ```
147
158
 
148
- So you see... the sky is the limit!
159
+
160
+ ## Development
161
+
162
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
163
+
164
+ 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).
165
+
166
+
167
+ ## Contributing
168
+
169
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pdobb/version_compare.
149
170
 
150
171
 
151
- ## Author
172
+ ## License
152
173
 
153
- - Paul Dobbins
174
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,32 +1,10 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
- end
6
-
7
- require 'rdoc/task'
8
-
9
- RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'VersionCompare'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.rdoc')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
15
- end
16
-
17
-
18
-
19
-
20
- Bundler::GemHelper.install_tasks
21
-
22
- require 'rake/testtask'
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
23
3
 
24
4
  Rake::TestTask.new(:test) do |t|
25
- t.libs << 'lib'
26
- t.libs << 'test'
27
- t.pattern = 'test/**/*_test.rb'
28
- t.verbose = false
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
29
8
  end
30
9
 
31
-
32
- task default: :test
10
+ task :default => :test
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "version_compare"
5
+ require "ostruct"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ require "pry"
12
+ Pry.start
13
+
14
+ # require "irb"
15
+ # IRB.start(__FILE__)
@@ -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