hash-utils 0.17.0 → 0.17.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
  # Add dependencies required to use your gem here.
3
3
  # Example:
4
- gem "ruby-version", ">= 0.1.0"
5
4
 
6
5
  # Add dependencies to develop your gem here.
7
6
  # Include everything needed to run rake, tests, features, etc.
data/Gemfile.lock CHANGED
@@ -2,7 +2,6 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  git (1.2.5)
5
- hash-utils (0.16.0)
6
5
  jeweler (1.6.2)
7
6
  bundler (~> 1.0)
8
7
  git (>= 1.2.5)
@@ -11,8 +10,6 @@ GEM
11
10
  riot (0.12.4)
12
11
  rr
13
12
  rr (1.0.2)
14
- ruby-version (0.1.0)
15
- hash-utils (>= 0.16.0)
16
13
 
17
14
  PLATFORMS
18
15
  ruby
@@ -21,4 +18,3 @@ DEPENDENCIES
21
18
  bundler (>= 1.0.0)
22
19
  jeweler (>= 1.5.2)
23
20
  riot (>= 0.12.3)
24
- ruby-version (>= 0.1.0)
data/README.md CHANGED
@@ -10,6 +10,7 @@ non-atomic and organized by better way.
10
10
  - `Array` – 12 methods,
11
11
  - `FalseClass` – 3 methods,
12
12
  - `File` – 2 methods,
13
+ - `Gem` – 2 methods,
13
14
  - `Hash` – 38 methods,
14
15
  - `IO` – 1 method,
15
16
  - `Module` – 1 method,
@@ -28,6 +29,11 @@ If you don't want to include whole library, you can include extensions
28
29
  to appropriate type only by including the:
29
30
 
30
31
  require "hash-utils/<lowercase-data-type-name>"
32
+
33
+ ### Special Requirements
34
+
35
+ Some methods are optimized at Ruby 1.8.7 and 1.9 and higher. These
36
+ optimizations requires the [`ruby-version`][2] gem available.
31
37
 
32
38
  Contributing
33
39
  ------------
@@ -47,6 +53,7 @@ Copyright &copy; 2011 [Martin Kozák][10]. See `LICENSE.txt` for
47
53
  further details.
48
54
 
49
55
  [1]: http://rubyworks.github.com/facets/
56
+ [2]: http://github.com/martinkozak/ruby-version
50
57
  [3]: http://rubydoc.info/gems/hash-utils
51
58
  [9]: http://github.com/martinkozak/hash-utils/issues
52
59
  [10]: http://www.martinkozak.net/
data/Rakefile CHANGED
@@ -19,7 +19,8 @@ Jeweler::Tasks.new do |gem|
19
19
  gem.homepage = "http://github.com/martinkozak/hash-utils"
20
20
  gem.license = "MIT"
21
21
  gem.summary = 'Adds more than 125 useful and frequently rather fundamental methods which are missing in Ruby programming language, to Array, File, Hash, Module, Object, String and Symbol classes. It tries to be similar project to Ruby Facets on principle, but less complex, more practical, non-atomic and organized by better way.'
22
- gem.post_install_message = "\nHASH UTILS: Be warn, Hash#all? has been removed since version 0.15.0 because of\nconflict with built-in one with in fact equivalent functionallity. Please, check\nyour code if you can and switch to Ruby's one.\n\n"
22
+ #gem.post_install_message = "\nHASH UTILS: Be warn, Hash#all? has been removed since version 0.15.0 because of\nconflict with built-in one with in fact equivalent functionallity. Please, check\nyour code if you can and switch to Ruby's one.\n\n"
23
+ gem.post_install_message = "\nHASH UTILS: Some methods are optimized at Ruby 1.8.7 and 1.9 or higher, but this feature requires the 'ruby-version' gem.\n\n"
23
24
  gem.email = "martinkozak@martinkozak.net"
24
25
  gem.authors = ["Martin Kozák"]
25
26
  # Include your dependencies below. Runtime dependencies are required when using your gem,
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.17.0
1
+ 0.17.1
data/hash-utils.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{hash-utils}
8
- s.version = "0.17.0"
8
+ s.version = "0.17.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Martin Kozák}]
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "lib/hash-utils/array.rb",
30
30
  "lib/hash-utils/boolean.rb",
31
31
  "lib/hash-utils/file.rb",
32
+ "lib/hash-utils/gem.rb",
32
33
  "lib/hash-utils/hash.rb",
33
34
  "lib/hash-utils/io.rb",
34
35
  "lib/hash-utils/module.rb",
@@ -42,9 +43,7 @@ Gem::Specification.new do |s|
42
43
  s.homepage = %q{http://github.com/martinkozak/hash-utils}
43
44
  s.licenses = [%q{MIT}]
44
45
  s.post_install_message = %q{
45
- HASH UTILS: Be warn, Hash#all? has been removed since version 0.15.0 because of
46
- conflict with built-in one with in fact equivalent functionallity. Please, check
47
- your code if you can and switch to Ruby's one.
46
+ HASH UTILS: Some methods are optimized at Ruby 1.8.7 and 1.9 or higher, but this feature requires the 'ruby-version' gem.
48
47
 
49
48
  }
50
49
  s.require_paths = [%q{lib}]
@@ -55,18 +54,15 @@ your code if you can and switch to Ruby's one.
55
54
  s.specification_version = 3
56
55
 
57
56
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
58
- s.add_runtime_dependency(%q<ruby-version>, [">= 0.1.0"])
59
57
  s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
60
58
  s.add_development_dependency(%q<jeweler>, [">= 1.5.2"])
61
59
  s.add_development_dependency(%q<riot>, [">= 0.12.3"])
62
60
  else
63
- s.add_dependency(%q<ruby-version>, [">= 0.1.0"])
64
61
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
65
62
  s.add_dependency(%q<jeweler>, [">= 1.5.2"])
66
63
  s.add_dependency(%q<riot>, [">= 0.12.3"])
67
64
  end
68
65
  else
69
- s.add_dependency(%q<ruby-version>, [">= 0.1.0"])
70
66
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
71
67
  s.add_dependency(%q<jeweler>, [">= 1.5.2"])
72
68
  s.add_dependency(%q<riot>, [">= 0.12.3"])
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
3
3
 
4
- require "ruby-version"
4
+ require "hash-utils/gem"
5
5
 
6
6
  ##
7
7
  # Array extension.
@@ -43,7 +43,7 @@ class Array
43
43
  # @since 0.2.0
44
44
  #
45
45
 
46
- alias :some? :one?
46
+ alias :"some?" :"one?"
47
47
 
48
48
  ##
49
49
  # Converts array to +Hash+.
@@ -188,7 +188,9 @@ class Array
188
188
  #
189
189
 
190
190
  def sum
191
- if RUBY_VERSION[0..2] == "1.9" or Ruby::Version >= [1, 8, 7]
191
+ if RUBY_VERSION[0..2] == "1.9" \
192
+ or (Gem::require_available("ruby-version") and Ruby::Version >= [1, 8, 7])
193
+
192
194
  self.inject(:+)
193
195
  else
194
196
  first = true
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ # (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
3
+
4
+ require "hash-utils/object"
5
+
6
+ ##
7
+ # +Gem+ extension.
8
+ # @since 0.17.1
9
+ #
10
+
11
+ module Gem
12
+
13
+ ##
14
+ # Indicates, gem is available.
15
+ #
16
+ # @param [String] name gem name
17
+ # @return [Boolean] +true+ if yes, +false+ in otherwise
18
+ # @since 0.17.1
19
+ #
20
+
21
+ def self.available?(name)
22
+ begin
23
+ return Gem::Specification::find_by_name(name.to_s).to_b
24
+ rescue Gem::LoadError
25
+ return false
26
+ end
27
+ end
28
+
29
+ ##
30
+ # Requires available gem. If file isn't set, requires file with same
31
+ # name as gem.
32
+ #
33
+ # @param [String] name gem name
34
+ # @param [String] file file name
35
+ # @return [Boolean] +true+ if it's available, +false+ in otherwise
36
+ # @since 0.17.1
37
+ #
38
+
39
+ def self.require_available(name, file = nil)
40
+ if self.available? name
41
+ require file.nil? ? name : file
42
+ true
43
+ else
44
+ false
45
+ end
46
+ end
47
+
48
+ end
data/test CHANGED
@@ -82,6 +82,25 @@ context "File" do
82
82
  end
83
83
  end
84
84
 
85
+ ## GEM
86
+
87
+ context "Gem" do
88
+ asserts("#available?") do
89
+ Gem::available? "hash-utils" and not Gem::available? "xxxxxxx"
90
+ end
91
+ asserts("#require_available") do
92
+ result = Gem::require_available("hash-utils")
93
+
94
+ begin
95
+ require "hash-utils"
96
+ rescue LoadError
97
+ result = false
98
+ end
99
+
100
+ result and not Gem::require_available("xxxxxxx")
101
+ end
102
+ end
103
+
85
104
  ## HASH
86
105
 
87
106
  context "Hash" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: hash-utils
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.17.0
5
+ version: 0.17.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Martin Koz\xC3\xA1k"
@@ -12,20 +12,9 @@ cert_chain: []
12
12
 
13
13
  date: 2011-06-24 00:00:00 Z
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: ruby-version
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 0.1.0
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: *id001
26
15
  - !ruby/object:Gem::Dependency
27
16
  name: bundler
28
- requirement: &id002 !ruby/object:Gem::Requirement
17
+ requirement: &id001 !ruby/object:Gem::Requirement
29
18
  none: false
30
19
  requirements:
31
20
  - - ">="
@@ -33,10 +22,10 @@ dependencies:
33
22
  version: 1.0.0
34
23
  type: :development
35
24
  prerelease: false
36
- version_requirements: *id002
25
+ version_requirements: *id001
37
26
  - !ruby/object:Gem::Dependency
38
27
  name: jeweler
39
- requirement: &id003 !ruby/object:Gem::Requirement
28
+ requirement: &id002 !ruby/object:Gem::Requirement
40
29
  none: false
41
30
  requirements:
42
31
  - - ">="
@@ -44,10 +33,10 @@ dependencies:
44
33
  version: 1.5.2
45
34
  type: :development
46
35
  prerelease: false
47
- version_requirements: *id003
36
+ version_requirements: *id002
48
37
  - !ruby/object:Gem::Dependency
49
38
  name: riot
50
- requirement: &id004 !ruby/object:Gem::Requirement
39
+ requirement: &id003 !ruby/object:Gem::Requirement
51
40
  none: false
52
41
  requirements:
53
42
  - - ">="
@@ -55,7 +44,7 @@ dependencies:
55
44
  version: 0.12.3
56
45
  type: :development
57
46
  prerelease: false
58
- version_requirements: *id004
47
+ version_requirements: *id003
59
48
  description:
60
49
  email: martinkozak@martinkozak.net
61
50
  executables: []
@@ -79,6 +68,7 @@ files:
79
68
  - lib/hash-utils/array.rb
80
69
  - lib/hash-utils/boolean.rb
81
70
  - lib/hash-utils/file.rb
71
+ - lib/hash-utils/gem.rb
82
72
  - lib/hash-utils/hash.rb
83
73
  - lib/hash-utils/io.rb
84
74
  - lib/hash-utils/module.rb
@@ -92,9 +82,7 @@ homepage: http://github.com/martinkozak/hash-utils
92
82
  licenses:
93
83
  - MIT
94
84
  post_install_message: "\n\
95
- HASH UTILS: Be warn, Hash#all? has been removed since version 0.15.0 because of\n\
96
- conflict with built-in one with in fact equivalent functionallity. Please, check\n\
97
- your code if you can and switch to Ruby's one.\n\n"
85
+ HASH UTILS: Some methods are optimized at Ruby 1.8.7 and 1.9 or higher, but this feature requires the 'ruby-version' gem.\n\n"
98
86
  rdoc_options: []
99
87
 
100
88
  require_paths:
@@ -104,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
92
  requirements:
105
93
  - - ">="
106
94
  - !ruby/object:Gem::Version
107
- hash: 3233431478987707592
95
+ hash: 654808796708422656
108
96
  segments:
109
97
  - 0
110
98
  version: "0"