spruz 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -46,7 +46,6 @@ if defined? Gem
46
46
  s.bindir = "bin"
47
47
  s.executables << "enum"
48
48
 
49
- s.has_rdoc = true
50
49
  s.extra_rdoc_files << 'README'
51
50
  s.rdoc_options << '--title' << 'Spruz' << '--main' << 'README'
52
51
  s.test_files.concat Dir['tests/test_*.rb']
@@ -56,6 +55,12 @@ if defined? Gem
56
55
  s.homepage = "http://flori.github.com/spruz"
57
56
  end
58
57
 
58
+ task :gemspec do
59
+ File.open('spruz.gemspec', 'w') do |output|
60
+ output.write spec.to_ruby
61
+ end
62
+ end
63
+
59
64
  Rake::GemPackageTask.new(spec) do |pkg|
60
65
  pkg.need_tar = true
61
66
  pkg.package_files += PKG_FILES
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.6
1
+ 0.2.7
@@ -0,0 +1,26 @@
1
+ module Spruz
2
+ module HashSymbolizeKeysRecursive
3
+ def symbolize_keys_recursive
4
+ inject(self.class.new) do |h,(k, v)|
5
+ k = k.to_s
6
+ k.empty? and next
7
+ case v
8
+ when Hash
9
+ h[k.to_sym] = v.symbolize_keys_recursive
10
+ when Array
11
+ h[k.to_sym] = a = v.dup
12
+ v.each_with_index do |x, i|
13
+ Hash === x and a[i] = x.symbolize_keys_recursive
14
+ end
15
+ else
16
+ h[k.to_sym] = v
17
+ end
18
+ h
19
+ end
20
+ end
21
+
22
+ def symbolize_keys_recursive!
23
+ replace symbolize_keys_recursive
24
+ end
25
+ end
26
+ end
data/lib/spruz/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Spruz
2
2
  # Spruz version
3
- VERSION = '0.2.6'
3
+ VERSION = '0.2.7'
4
4
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -0,0 +1,7 @@
1
+ require 'spruz/hash_symbolize_keys_recursive'
2
+
3
+ module Spruz
4
+ class ::Hash
5
+ include HashSymbolizeKeysRecursive
6
+ end
7
+ end
data/lib/spruz/xt.rb CHANGED
@@ -16,4 +16,5 @@ module Spruz
16
16
  require 'spruz/xt/write'
17
17
  require 'spruz/xt/deep_dup'
18
18
  require 'spruz/xt/attempt'
19
+ require 'spruz/xt/hash_symbolize_keys_recursive'
19
20
  end
data/lib/spruz.rb CHANGED
@@ -22,4 +22,5 @@ module Spruz
22
22
  require 'spruz/write'
23
23
  require 'spruz/deep_dup'
24
24
  require 'spruz/attempt'
25
+ require 'spruz/hash_symbolize_keys_recursive'
25
26
  end
data/spruz.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{spruz}
5
+ s.version = "0.2.7"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Florian Frank"]
9
+ s.date = %q{2011-05-20}
10
+ s.description = %q{All the stuff that isn't good/big enough for a real library.}
11
+ s.email = %q{flori@ping.de}
12
+ s.executables = ["enum"]
13
+ s.extra_rdoc_files = ["README"]
14
+ s.files = ["bin", "bin/enum", "install.rb", "lib", "lib/spruz", "lib/spruz/attempt.rb", "lib/spruz/bijection.rb", "lib/spruz/count_by.rb", "lib/spruz/deep_dup.rb", "lib/spruz/generator.rb", "lib/spruz/go.rb", "lib/spruz/hash_symbolize_keys_recursive.rb", "lib/spruz/hash_union.rb", "lib/spruz/limited.rb", "lib/spruz/memoize.rb", "lib/spruz/minimize.rb", "lib/spruz/module_group.rb", "lib/spruz/null.rb", "lib/spruz/once.rb", "lib/spruz/p.rb", "lib/spruz/partial_application.rb", "lib/spruz/round.rb", "lib/spruz/shuffle.rb", "lib/spruz/subhash.rb", "lib/spruz/time_dummy.rb", "lib/spruz/to_proc.rb", "lib/spruz/uniq_by.rb", "lib/spruz/version.rb", "lib/spruz/write.rb", "lib/spruz/xt", "lib/spruz/xt/attempt.rb", "lib/spruz/xt/blank.rb", "lib/spruz/xt/count_by.rb", "lib/spruz/xt/deep_dup.rb", "lib/spruz/xt/full.rb", "lib/spruz/xt/hash_symbolize_keys_recursive.rb", "lib/spruz/xt/hash_union.rb", "lib/spruz/xt/irb.rb", "lib/spruz/xt/null.rb", "lib/spruz/xt/p.rb", "lib/spruz/xt/partial_application.rb", "lib/spruz/xt/round.rb", "lib/spruz/xt/shuffle.rb", "lib/spruz/xt/subhash.rb", "lib/spruz/xt/symbol_to_proc.rb", "lib/spruz/xt/time_dummy.rb", "lib/spruz/xt/uniq_by.rb", "lib/spruz/xt/write.rb", "lib/spruz/xt.rb", "lib/spruz.rb", "LICENSE", "Rakefile", "README", "tests", "tests/test_spruz.rb", "tests/test_spruz_memoize.rb", "VERSION"]
15
+ s.homepage = %q{http://flori.github.com/spruz}
16
+ s.rdoc_options = ["--title", "Spruz", "--main", "README"]
17
+ s.require_paths = ["lib"]
18
+ s.rubygems_version = %q{1.7.2}
19
+ s.summary = %q{Useful stuff.}
20
+ s.test_files = ["tests/test_spruz.rb", "tests/test_spruz_memoize.rb"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
+ else
27
+ end
28
+ else
29
+ end
30
+ end
data/tests/test_spruz.rb CHANGED
@@ -356,6 +356,26 @@ module Spruz
356
356
  end
357
357
  end
358
358
 
359
+ class HashSymbolizeKeysRecursiveTest < Test::Unit::TestCase
360
+ require 'spruz/xt/hash_symbolize_keys_recursive'
361
+
362
+ def test_symbolize
363
+ hash = {
364
+ 'key' => [
365
+ {
366
+ 'key' => {
367
+ 'key' => true
368
+ }
369
+ }
370
+ ],
371
+ }
372
+ hash2 = hash.symbolize_keys_recursive
373
+ assert hash2[:key][0][:key][:key]
374
+ hash.symbolize_keys_recursive!
375
+ assert hash[:key][0][:key][:key]
376
+ end
377
+ end
378
+
359
379
  class SubhashTest < Test::Unit::TestCase
360
380
  require 'spruz/xt/subhash'
361
381
 
@@ -489,7 +509,7 @@ module Spruz
489
509
  def test_attempt_block_condition
490
510
  assert attempt(:attempts => 1, :exception_class => nil) { |c| c == 1 }
491
511
  assert attempt(:attempts => 3, :exception_class => nil) { |c| c == 1 }
492
- assert_false attempt(:attempts => 3, :exception_class => nil) { |c| c == 4 }
512
+ assert_equal false, attempt(:attempts => 3, :exception_class => nil) { |c| c == 4 }
493
513
  assert_nil attempt(:attempts => 0, :exception_class => nil) { |c| c == 4 }
494
514
  assert_raise(Exception) { attempt(:attempts => 3, :exception_class => nil) { raise Exception } }
495
515
  end
@@ -500,7 +520,7 @@ module Spruz
500
520
  def test_attempt_default_exception
501
521
  assert attempt(1) { |c| c != 1 and raise MyError }
502
522
  assert attempt(3) { |c| c != 1 and raise MyError }
503
- assert_false attempt(3) { |c| c != 4 and raise MyError }
523
+ assert_equal false, attempt(3) { |c| c != 4 and raise MyError }
504
524
  assert_nil attempt(0) { |c| c != 4 and raise MyError }
505
525
  assert_raise(Exception) { attempt(3) { raise Exception } }
506
526
  end
@@ -508,7 +528,7 @@ module Spruz
508
528
  def test_attempt_exception
509
529
  assert attempt(:attempts => 1, :exception_class => MyException) { |c| c != 1 and raise MyException }
510
530
  assert attempt(:attempts => 3, :exception_class => MyException) { |c| c != 1 and raise MyException }
511
- assert_false attempt(:attempts => 3, :exception_class => MyException) { |c| c != 4 and raise MyException }
531
+ assert_equal false, attempt(:attempts => 3, :exception_class => MyException) { |c| c != 4 and raise MyException }
512
532
  assert_nil attempt(:attempts => 0, :exception_class => MyException) { |c| c != 4 and raise MyException }
513
533
  assert_raise(Exception) { attempt(:attempts => 3, :exception_class => MyException) { raise Exception } }
514
534
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spruz
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 6
10
- version: 0.2.6
9
+ - 7
10
+ version: 0.2.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Florian Frank
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-29 00:00:00 Z
18
+ date: 2011-05-20 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: All the stuff that isn't good/big enough for a real library.
@@ -31,7 +31,9 @@ files:
31
31
  - tests/test_spruz.rb
32
32
  - LICENSE
33
33
  - Rakefile
34
+ - spruz.gemspec
34
35
  - lib/spruz.rb
36
+ - lib/spruz/hash_symbolize_keys_recursive.rb
35
37
  - lib/spruz/hash_union.rb
36
38
  - lib/spruz/write.rb
37
39
  - lib/spruz/version.rb
@@ -50,6 +52,7 @@ files:
50
52
  - lib/spruz/null.rb
51
53
  - lib/spruz/xt.rb
52
54
  - lib/spruz/once.rb
55
+ - lib/spruz/xt/hash_symbolize_keys_recursive.rb
53
56
  - lib/spruz/xt/hash_union.rb
54
57
  - lib/spruz/xt/write.rb
55
58
  - lib/spruz/xt/irb.rb