modalsupport 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -1,5 +1,8 @@
1
1
  require 'active_support'
2
2
  require 'hobosupport'
3
+ require 'modalsupport/ruby_version'
4
+ require 'modalsupport/ruby_platform'
5
+ require 'modalsupport/ruby_engine'
3
6
  require 'modalsupport/string'
4
7
  require 'modalsupport/regexp'
5
8
  require 'modalsupport/enumerable'
@@ -4,7 +4,7 @@ module Enumerable
4
4
  grep(pattern){|str| yield(Regexp.last_match)}
5
5
  end
6
6
 
7
- if RUBY_VERSION < "1.8.7"
7
+ if_ruby_version :<, "1.8.7" do
8
8
  require 'enumerator'
9
9
  alias enumerator_each_slice each_slice
10
10
  def each_slice(n, &blk)
@@ -1,6 +1,6 @@
1
1
  class Regexp
2
2
 
3
- if RUBY_VERSION < "1.9"
3
+ if_ruby_version :<, "1.9.0" do
4
4
  alias match_old match
5
5
  # Modify String#match to work as in Ruby 1.9
6
6
  def match(str, i=0)
@@ -0,0 +1,11 @@
1
+ # Detect Ruby engine:
2
+ # :ruby, :rbx/:rubinius, :jruby/:java, ...
3
+ def ruby_engine_is?(engine) # "ruby" "jruby" "rbx"
4
+ engine = {:rubinius=>:rbx, :java=>:jruby}[engine] || engine
5
+ current_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
6
+ engine.to_s == current_engine
7
+ end
8
+
9
+ def if_ruby_engine_is(engine)
10
+ yield if ruby_engine_is?(engine)
11
+ end
@@ -0,0 +1,33 @@
1
+ # detection of some generic platform families
2
+ # * :unix (UN*X systems) with distinguished subfamilies: :linux, :osx/:darwin, :bsd, :cygwin
3
+ # * :windows with variants :mswin32, :mingw32
4
+ # * :java
5
+ def ruby_platform_is?(platform)
6
+ ruby_platform = ruby_version?(:<,'1.9.0') ? PLATFORM : RUBY_PLATFORM
7
+ case platform
8
+ when :unix
9
+ ruby_platform =~ /linux|darwin|freebsd|netbsd|solaris|aix|hpux|cygwin/
10
+ when :linux
11
+ ruby_platform =~ /linux/
12
+ when :osx, :darwin
13
+ ruby_platform =~ /darwin/
14
+ when :bsd
15
+ ruby_platform =~ /freebsd|netbsd/
16
+ when :cygwin
17
+ ruby_platform =~ /cygwin/
18
+ when :windows
19
+ ruby_platform =~ /mswin32|mingw32/
20
+ when :mswin32
21
+ ruby_platform =~ /mswin32/
22
+ when :mingw32
23
+ ruby_platform =~ /mingw32/
24
+ when :java
25
+ ruby_platform =~ /java/
26
+ else
27
+ raise RuntimeError, "Invalid platform specifier"
28
+ end ? true : false
29
+ end
30
+
31
+ def if_ruby_platform_is(platform)
32
+ yield if platform_is?(platform)
33
+ end
@@ -0,0 +1,45 @@
1
+ # Helpers to detect Ruby versions
2
+
3
+ unless defined? Gem
4
+ require 'rubygems'
5
+ end
6
+
7
+ # Compare the Ruby version with a version string
8
+ def ruby_version?(cmp, v)
9
+ Gem::Version.create(RUBY_VERSION.dup).send(cmp, Gem::Version.create(v))
10
+ end
11
+
12
+ # ruby_version_between?(v1,v2) == ruby_version?(:>=,v1) && ruby_version?(:<=,v2)
13
+ def ruby_version_between?(v1, v2)
14
+ (Gem::Version.create(v1)..Gem::Version.create(v2)).include?(Ger::Version.create(RUBY_VERSION))
15
+ end
16
+
17
+ # ruby_version_between?(v1,v2) == ruby_version?(:>=,v1) && ruby_version?(:<,v2)
18
+ def ruby_version_between_ex?(v1, v2)
19
+ (Gem::Version.create(v1).-.Gem::Version.create(v2)).include?(Ger::Version.create(RUBY_VERSION))
20
+ end
21
+
22
+ # Execute code conditinally on Ruby version:
23
+ # if_ruby_version :>=, '1.9.2' do
24
+ # ...
25
+ # end
26
+ def if_ruby_version(cmp, v)
27
+ yield if ruby_version?(cmp, v)
28
+ end
29
+
30
+ def if_ruby_version_between(v1, v2)
31
+ yield if ruby_version_between?(v1, v2)
32
+ end
33
+
34
+ def if_ruby_version_between_ex(v1, v2)
35
+ yield if ruby_version_between_ex?(v1, v2)
36
+ end
37
+
38
+ def ruby_19(&blk)
39
+ if_ruby_version :>=, '1.9.0', &blk
40
+ end
41
+
42
+ def ruby_18(&blk)
43
+ # if_ruby_version :<, '1.9.0', &blk
44
+ if_ruby_version_between_ex '1.8.0', '1.9.0'
45
+ end
@@ -1,6 +1,6 @@
1
1
  class String
2
2
 
3
- if RUBY_VERSION < "1.9"
3
+ if_ruby_version :<, "1.9" do
4
4
  alias match_old match
5
5
  # Modify String#match to work as in Ruby 1.9
6
6
  def match(re, i=0)
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{modalsupport}
8
- s.version = "0.3.0"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Javier Goizueta"]
@@ -29,6 +29,9 @@ Gem::Specification.new do |s|
29
29
  "lib/modalsupport/mixins/bracket_constructor.rb",
30
30
  "lib/modalsupport/mixins/state_equivalent.rb",
31
31
  "lib/modalsupport/regexp.rb",
32
+ "lib/modalsupport/ruby_engine.rb",
33
+ "lib/modalsupport/ruby_platform.rb",
34
+ "lib/modalsupport/ruby_version.rb",
32
35
  "lib/modalsupport/string.rb",
33
36
  "modalsupport.gemspec",
34
37
  "test/helper.rb",
@@ -45,7 +48,7 @@ Gem::Specification.new do |s|
45
48
  s.homepage = %q{http://github.com/jgoizueta/modalsupport}
46
49
  s.rdoc_options = ["--charset=UTF-8"]
47
50
  s.require_paths = ["lib"]
48
- s.rubygems_version = %q{1.3.7}
51
+ s.rubygems_version = %q{1.3.6}
49
52
  s.summary = %q{simple extensions to core classes}
50
53
  s.test_files = [
51
54
  "test/helper.rb",
@@ -64,7 +67,7 @@ Gem::Specification.new do |s|
64
67
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
65
68
  s.specification_version = 3
66
69
 
67
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
70
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
68
71
  s.add_development_dependency(%q<shoulda>, [">= 0"])
69
72
  s.add_runtime_dependency(%q<hobosupport>, [">= 0"])
70
73
  s.add_runtime_dependency(%q<activesupport>, [">= 0"])
@@ -57,7 +57,9 @@ class TestRelativePaths < Test::Unit::TestCase
57
57
  assert_equal '//aaa/bbb/ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee')
58
58
  assert_equal 'ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee', '//aaa/bbb')
59
59
  assert_equal '//aaa/bbb/ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee','aaa/bbb')
60
- assert_equal '//aaa/bbb/ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee','/aaa/bbb')
60
+ unless ruby_engine_is?(:rbx)
61
+ assert_equal '//aaa/bbb/ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee','/aaa/bbb')
62
+ end
61
63
  assert_equal '//aaa/bbb/ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee','xxx/yyy')
62
64
  assert_equal '//aaa/bbb/ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee','/xxx/yyy')
63
65
  assert_equal '//aaa/bbb/ccc/ddd.eee', File.relative_path('//aaa/bbb/ccc/ddd.eee','//xxx/yyy')
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modalsupport
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
4
  prerelease: false
6
5
  segments:
7
- - 0
8
- - 3
9
- - 0
10
- version: 0.3.0
6
+ - 0
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
11
10
  platform: ruby
12
11
  authors:
13
- - Javier Goizueta
12
+ - Javier Goizueta
14
13
  autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
@@ -18,48 +17,42 @@ cert_chain: []
18
17
  date: 2010-06-09 00:00:00 +02:00
19
18
  default_executable:
20
19
  dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: shoulda
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
33
- type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: hobosupport
37
- prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
47
- type: :runtime
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: activesupport
51
- prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
61
- type: :runtime
62
- version_requirements: *id003
20
+ - !ruby/object:Gem::Dependency
21
+ name: shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: hobosupport
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :runtime
43
+ version_requirements: *id002
44
+ - !ruby/object:Gem::Dependency
45
+ name: activesupport
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ type: :runtime
55
+ version_requirements: *id003
63
56
  description: additional support extensions to ActiveSupport and HoboSupport
64
57
  email: jgoizueta@gmail.com
65
58
  executables: []
@@ -67,75 +60,74 @@ executables: []
67
60
  extensions: []
68
61
 
69
62
  extra_rdoc_files:
70
- - LICENSE
71
- - README.rdoc
63
+ - LICENSE
64
+ - README.rdoc
72
65
  files:
73
- - .document
74
- - .gitignore
75
- - LICENSE
76
- - README.rdoc
77
- - Rakefile
78
- - VERSION
79
- - lib/modalsupport.rb
80
- - lib/modalsupport/enumerable.rb
81
- - lib/modalsupport/file.rb
82
- - lib/modalsupport/mixins/bracket_constructor.rb
83
- - lib/modalsupport/mixins/state_equivalent.rb
84
- - lib/modalsupport/regexp.rb
85
- - lib/modalsupport/string.rb
86
- - modalsupport.gemspec
87
- - test/helper.rb
88
- - test/test_bracket_constructor.rb
89
- - test/test_grep.rb
90
- - test/test_gsub.rb
91
- - test/test_match.rb
92
- - test/test_product.rb
93
- - test/test_relative_path.rb
94
- - test/test_slice.rb
95
- - test/test_state_equivalent.rb
96
- - test/test_unindent.rb
66
+ - .document
67
+ - .gitignore
68
+ - LICENSE
69
+ - README.rdoc
70
+ - Rakefile
71
+ - VERSION
72
+ - lib/modalsupport.rb
73
+ - lib/modalsupport/enumerable.rb
74
+ - lib/modalsupport/file.rb
75
+ - lib/modalsupport/mixins/bracket_constructor.rb
76
+ - lib/modalsupport/mixins/state_equivalent.rb
77
+ - lib/modalsupport/regexp.rb
78
+ - lib/modalsupport/ruby_engine.rb
79
+ - lib/modalsupport/ruby_platform.rb
80
+ - lib/modalsupport/ruby_version.rb
81
+ - lib/modalsupport/string.rb
82
+ - modalsupport.gemspec
83
+ - test/helper.rb
84
+ - test/test_bracket_constructor.rb
85
+ - test/test_grep.rb
86
+ - test/test_gsub.rb
87
+ - test/test_match.rb
88
+ - test/test_product.rb
89
+ - test/test_relative_path.rb
90
+ - test/test_slice.rb
91
+ - test/test_state_equivalent.rb
92
+ - test/test_unindent.rb
97
93
  has_rdoc: true
98
94
  homepage: http://github.com/jgoizueta/modalsupport
99
95
  licenses: []
100
96
 
101
97
  post_install_message:
102
98
  rdoc_options:
103
- - --charset=UTF-8
99
+ - --charset=UTF-8
104
100
  require_paths:
105
- - lib
101
+ - lib
106
102
  required_ruby_version: !ruby/object:Gem::Requirement
107
- none: false
108
103
  requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- hash: 3
112
- segments:
113
- - 0
114
- version: "0"
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ segments:
107
+ - 0
108
+ version: "0"
115
109
  required_rubygems_version: !ruby/object:Gem::Requirement
116
- none: false
117
110
  requirements:
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- hash: 3
121
- segments:
122
- - 0
123
- version: "0"
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ segments:
114
+ - 0
115
+ version: "0"
124
116
  requirements: []
125
117
 
126
118
  rubyforge_project:
127
- rubygems_version: 1.3.7
119
+ rubygems_version: 1.3.6
128
120
  signing_key:
129
121
  specification_version: 3
130
122
  summary: simple extensions to core classes
131
123
  test_files:
132
- - test/helper.rb
133
- - test/test_bracket_constructor.rb
134
- - test/test_grep.rb
135
- - test/test_gsub.rb
136
- - test/test_match.rb
137
- - test/test_product.rb
138
- - test/test_relative_path.rb
139
- - test/test_slice.rb
140
- - test/test_state_equivalent.rb
141
- - test/test_unindent.rb
124
+ - test/helper.rb
125
+ - test/test_bracket_constructor.rb
126
+ - test/test_grep.rb
127
+ - test/test_gsub.rb
128
+ - test/test_match.rb
129
+ - test/test_product.rb
130
+ - test/test_relative_path.rb
131
+ - test/test_slice.rb
132
+ - test/test_state_equivalent.rb
133
+ - test/test_unindent.rb