noisrev 0.0.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of noisrev might be problematic. Click here for more details.

data/.gitignore ADDED
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ coverage.data
7
+ InstalledFiles
8
+ lib/bundler/man
9
+ pkg
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+
16
+ # bundler
17
+ vendor/
18
+
19
+ # YARD artifacts
20
+ .yardoc
21
+ _yardoc
22
+ doc/
23
+
24
+ # tmp-old
25
+ .old
26
+
27
+ # editor
28
+ *~
29
+ .redcar
30
+
31
+ # other
32
+ *.lock
33
+ *.bak
34
+ tool/
35
+ *\#*
36
+ .rbx/
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+ rvm:
3
+ - ruby-head
4
+ - 1.9.3
5
+ - 1.9.2
6
+ - rbx-19mode
7
+ - jruby-head
8
+ - jruby-19mode
9
+
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: rbx-19mode
13
+ - rvm: jruby-head
14
+ - rvm: jruby-19mode
15
+
16
+ before_install:
17
+ - gem install bundler
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --readme README.md lib/**/*.rb --exclude core_ext - MIT-LICENSE
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'rake'
7
+ end
8
+
9
+ group :development do
10
+ gem 'rake'
11
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT X11 License)
2
+
3
+ Copyright (c) 2012 Kenichi Kamiya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ noisrev
2
+ ========
3
+
4
+ Description
5
+ -----------
6
+
7
+ Version <-> Noisrev
8
+
9
+ Features
10
+ --------
11
+
12
+ * Expression for library versions
13
+ * Keeping compatibility with String
14
+ * Pure Ruby :)
15
+
16
+ Usage
17
+ -----
18
+
19
+ ### Setup
20
+
21
+ ```ruby
22
+ require 'noisrev'
23
+ require 'noisrev/core_ext' #=> Version = Noisrev
24
+ ```
25
+
26
+ ### Keeping comparisons with String
27
+
28
+ ```ruby
29
+ '0.10.0' > '0.2.0') #=> false
30
+ Version(0, 10, 0) > '0.2.0') #=> true
31
+ '0.2.0' > Version(0, 10, 0)) #=> false
32
+ '0.2.0' > Version(0, 1, 0)) #=> true
33
+ ```
34
+
35
+ ### Dependency checker
36
+
37
+ ```ruby
38
+ RUBY_VERSION #=> '1.9.3'
39
+ version = Version.parse '0.0.1'
40
+ version.runnable? #=> true
41
+ version.depend :Ruby, '3.0.1'
42
+ version.runnable? #=> false
43
+ version.depend :Ruby, '1.9.2'..'3.0.2'
44
+ version.runnable? #=> true
45
+ ```
46
+
47
+ Requirements
48
+ -------------
49
+
50
+ * Ruby - [1.9.2 or later](http://travis-ci.org/#!/kachick/noisrev)
51
+ * [striuct](https://github.com/kachick/striuct) - 0.4
52
+
53
+ Build Status
54
+ -------------
55
+
56
+ [![Build Status](https://secure.travis-ci.org/kachick/noisrev.png)](http://travis-ci.org/kachick/noisrev)
57
+
58
+ Install
59
+ -------
60
+
61
+ ```bash
62
+ $ gem install noisrev
63
+ ```
64
+
65
+ Link
66
+ ----
67
+
68
+ * [Home](http://kachick.github.com/noisrev/)
69
+ * [code](https://github.com/kachick/noisrev)
70
+ * [API](http://kachick.github.com/noisrev/yard/frames.html)
71
+ * [issues](https://github.com/kachick/noisrev/issues)
72
+ * [CI](http://travis-ci.org/#!/kachick/noisrev)
73
+ * [gem](https://rubygems.org/gems/noisrev)
74
+
75
+ License
76
+ --------
77
+
78
+ The MIT X11 License
79
+ Copyright (c) 2012 Kenichi Kamiya
80
+ See MIT-LICENSE for further details.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+
4
+ require 'rake/testtask'
5
+
6
+ task default: [:test]
7
+
8
+ Rake::TestTask.new do |tt|
9
+ tt.verbose = true
10
+ end
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/noisrev'
4
+ require_relative '../lib/noisrev/import'
5
+
6
+ p Version.new
7
+
8
+ version = Version 0, 0, 1
9
+
10
+ p version
11
+ p Version.parse '0.0.1'
12
+
13
+ p version.to_s
14
+
15
+ p(version > '0.0.0')
16
+ p(version > '0.0.1')
17
+ p(version == '0.0.1')
18
+ p('0.0.1' == version)
19
+ p version.next.to_s
20
+ p version.next(:major).to_s
21
+
22
+ p('0.10.0' > '0.2.0')
23
+ p(Version.new(0, 10, 0) > '0.2.0')
24
+ p('0.2.0' > Version.new(0, 10, 0))
25
+ p('0.2.0' > Version.new(0, 1, 0))
26
+ p RUBY_VERSION
27
+ p Version::RUBY_VERSION
28
+ p version.runnable?
29
+ version.depend(:Ruby, '3.0.1')
30
+ p version.runnable?
31
+ version.depend(:Ruby, '1.9.2'..'3.0.2')
32
+ p version.runnable?
data/lib/noisrev.rb ADDED
@@ -0,0 +1,137 @@
1
+ # noisrev - Noisrev <-> Version :)
2
+ # Copyright (c) 2012 Kenichi Kamiya
3
+
4
+ require 'striuct'
5
+
6
+ class Noisrev < Striuct
7
+
8
+ include Comparable
9
+
10
+ DELIMITER = '.'.freeze
11
+
12
+ versionable_number = ->v{v.instance_of?(Fixnum) && v >= 0}
13
+ %w[major minor revision].each do |name|
14
+ member name, versionable_number
15
+ default name, 0
16
+ end
17
+
18
+ alias_member :patch, :revision
19
+
20
+ member :optional,
21
+ OR(nil, versionable_number, AND(STRINGABLE?, ->v{! v.empty?}))
22
+ close_member
23
+
24
+ # @param [Array<Integer>] values
25
+ def initialize(*values)
26
+ super(*values)
27
+ @dependencies = {}
28
+ end
29
+
30
+ # @return [Array]
31
+ def valids
32
+ optional ? values : values[0..-2]
33
+ end
34
+
35
+ # @param [Noisrev, String, Fixnum, #to_str] other
36
+ # @return [Fixnum]
37
+ def <=>(other)
38
+ case other
39
+ when self.class
40
+ valids <=> other.valids
41
+ when String
42
+ self <=> self.class.parse(other)
43
+ when Fixnum
44
+ major <=> other
45
+ else
46
+ if other.respond_to?(:to_str)
47
+ self <=> other.to_str
48
+ else
49
+ nil
50
+ end
51
+ end
52
+ end
53
+
54
+ # @return [String]
55
+ def to_s
56
+ valids.join DELIMITER
57
+ end
58
+
59
+ alias_method :to_str, :to_s
60
+
61
+ # @return [self]
62
+ def current
63
+ self
64
+ end
65
+
66
+ # @param [Symbol, String] field
67
+ # @return [Noisrev]
68
+ def succ(field=:revision)
69
+ raise NameError unless member? field
70
+
71
+ self.class.for_pairs({}.tap{|hash|
72
+ each_pair do |name, value|
73
+ hash[name] = name == field ? (value.succ) : value
74
+ break if name == field
75
+ end
76
+ })
77
+ end
78
+
79
+ alias_method :next, :succ
80
+
81
+ # @param [Symbol, String] name
82
+ # @param [Range, Comparable] range
83
+ # @return range
84
+ def depend(name, range)
85
+ name = (
86
+ case name
87
+ when /\Aruby\z/i
88
+ :Ruby
89
+ when /\A[A-Z]/
90
+ name.to_sym
91
+ else
92
+ raise NameError
93
+ end
94
+ )
95
+
96
+ @dependencies[name] = range
97
+ end
98
+
99
+ def runnable?
100
+ @dependencies.all? {|name, range|
101
+ current_version = (
102
+ case name
103
+ when :Ruby
104
+ self.class::RUBY_VERSION
105
+ else
106
+ if (eval "defined? #{name}::VERSION") == 'constant'
107
+ self.class.parse(eval "#{name}::VERSION")
108
+ else
109
+ raise "undefined constant or version for #{name}"
110
+ end
111
+ end
112
+ )
113
+
114
+ case range
115
+ when Range
116
+ range.cover? current_version
117
+ else
118
+ current_version >= range
119
+ end
120
+ }
121
+ end
122
+
123
+ # @return self
124
+ def freeze
125
+ @dependencies.freeze
126
+ super
127
+ end
128
+
129
+ end
130
+
131
+ require_relative 'noisrev/singleton_class'
132
+
133
+ class Noisrev
134
+
135
+ RUBY_VERSION = parse(::RUBY_VERSION).freeze
136
+
137
+ end
@@ -0,0 +1,15 @@
1
+ require_relative '../noisrev'
2
+
3
+ Version = Noisrev
4
+
5
+ module Kernel
6
+
7
+ private
8
+
9
+ def Noisrev(*values)
10
+ ::Noisrev.for_values(*values)
11
+ end
12
+
13
+ alias_method :Version, :Noisrev
14
+
15
+ end
@@ -0,0 +1,31 @@
1
+ class Noisrev
2
+
3
+ class << self
4
+
5
+ # @param [String, #split] str ex: '0.0.1.a'
6
+ # @return [Noisrev]
7
+ def parse(str)
8
+ tokens = str.split(DELIMITER)
9
+ values = tokens.first(3).map{|s|Integer s}
10
+
11
+ case tokens.length
12
+ when 3
13
+ when 4
14
+ values << tokens.last
15
+ else
16
+ raise
17
+ end
18
+
19
+ for_values(*values)
20
+ rescue
21
+ raise 'Unknown format'
22
+ end
23
+
24
+ # @return [Noisrev]
25
+ def first
26
+ for_values 0, 0, 1
27
+ end
28
+
29
+ end
30
+
31
+ end
data/noisrev.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.authors = ['Kenichi Kamiya']
3
+ gem.email = ['kachick1+ruby@gmail.com']
4
+ gem.summary = %q{Noisrev <-> Version}
5
+ gem.description = gem.summary.dup
6
+ gem.homepage = 'http://kachick.github.com/noisrev/'
7
+
8
+ gem.files = `git ls-files`.split($\)
9
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
10
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
11
+ gem.name = 'noisrev'
12
+ gem.require_paths = ['lib']
13
+ gem.version = '0.0.5'
14
+
15
+ gem.required_ruby_version = '>= 1.9.2'
16
+
17
+ gem.add_runtime_dependency 'striuct', '~> 0.4'
18
+
19
+ gem.add_development_dependency 'yard', '>= 0.8'
20
+ end
21
+
data/test/helper.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'test/unit'
2
+
3
+ $VERBOSE = true
4
+
5
+ require_relative'../lib/noisrev'
@@ -0,0 +1,40 @@
1
+ require_relative 'helper'
2
+
3
+ class TestNoisrev < Test::Unit::TestCase
4
+
5
+ VERSION = Noisrev.new 0, 0, 1
6
+
7
+ def test_parse
8
+ assert_equal(VERSION, Noisrev.parse('0.0.1'))
9
+ assert_equal([1, 2, 3, 'a'], Noisrev.parse('1.2.3.a').values)
10
+ end
11
+
12
+ def test_to_s
13
+ assert_equal('0.0.1', VERSION.to_s)
14
+ end
15
+
16
+ def test_compare
17
+ assert_equal(false, (VERSION < '0.0.0'))
18
+ assert_equal(true, (VERSION > '0.0.0'))
19
+ assert_equal(true, (VERSION == '0.0.1'))
20
+ assert_equal(true, (VERSION.next == '0.0.2'))
21
+ assert_equal(true, (VERSION.next(:major) == '1.0.0'))
22
+ assert_equal(true, (VERSION.next(:minor) == '0.1.0'))
23
+ assert_equal(true, (Noisrev.new(0, 10, 0) > '0.2.0'))
24
+ assert_equal(false, ('0.2.0' > Noisrev.new(0, 10, 0)))
25
+ end
26
+
27
+ def test_ruby_version
28
+ assert_equal(::RUBY_VERSION, Noisrev::RUBY_VERSION)
29
+ end
30
+
31
+ def test_depend
32
+ version = VERSION.dup
33
+ assert_equal(true, version.runnable?)
34
+ version.depend(:Ruby, Noisrev::RUBY_VERSION.next)
35
+ assert_equal(false, version.runnable?)
36
+ version.depend(:Ruby, '1.9.2'..Noisrev::RUBY_VERSION.next)
37
+ assert_equal(true, version.runnable?)
38
+ end
39
+
40
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: noisrev
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kenichi Kamiya
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: striuct
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.4'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.4'
30
+ - !ruby/object:Gem::Dependency
31
+ name: yard
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0.8'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0.8'
46
+ description: Noisrev <-> Version
47
+ email:
48
+ - kachick1+ruby@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - .travis.yml
55
+ - .yardopts
56
+ - Gemfile
57
+ - MIT-LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - example/overview.rb
61
+ - lib/noisrev.rb
62
+ - lib/noisrev/core_ext.rb
63
+ - lib/noisrev/singleton_class.rb
64
+ - noisrev.gemspec
65
+ - test/helper.rb
66
+ - test/test_noisrev.rb
67
+ homepage: http://kachick.github.com/noisrev/
68
+ licenses: []
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 1.9.2
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 1.8.24
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Noisrev <-> Version
91
+ test_files:
92
+ - test/helper.rb
93
+ - test/test_noisrev.rb
94
+ has_rdoc: