spruz 0.2.11 → 0.2.12

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
- pkg
2
- Gemfile.lock
3
1
  .*.sw[pon]
2
+ .rvmrc
3
+ Gemfile.lock
4
+ pkg
data/Rakefile CHANGED
@@ -12,10 +12,9 @@ GemHadar do
12
12
  bindir 'bin'
13
13
  executables << 'enum'
14
14
  test_dir 'tests'
15
- ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock'
15
+ ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc'
16
16
  readme 'README.rdoc'
17
17
 
18
-
19
18
  install_library do
20
19
  libdir = CONFIG["sitelibdir"]
21
20
  cd 'lib' do
data/TODO ADDED
@@ -0,0 +1 @@
1
+ - Ruby1.9 has File.write method now, that conflicts with Spruz::Write module's and has to be fixed in some way
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.11
1
+ 0.2.12
data/bin/enum CHANGED
@@ -107,8 +107,8 @@ def execute_command(command, format, tuple)
107
107
  end
108
108
 
109
109
  def usage
110
- puts <<EOT
111
- Usage: #{File.basename($0)} [OPTIONS] RANGES
110
+ puts <<EOT
111
+ Usage: #{File.basename($0)} [OPTIONS] RANGES
112
112
 
113
113
  RANGES has to be a string of the from R1:R2:...Rn, where R1 to Rn are ranges of
114
114
  values for each dimension. A range can be specified like in one of
@@ -20,6 +20,7 @@ module Spruz
20
20
  require 'spruz/to_proc'
21
21
  require 'spruz/uniq_by'
22
22
  require 'spruz/write'
23
+ require 'spruz/secure_write'
23
24
  require 'spruz/deep_dup'
24
25
  require 'spruz/attempt'
25
26
  require 'spruz/hash_symbolize_keys_recursive'
@@ -13,7 +13,7 @@ module Spruz
13
13
  end
14
14
 
15
15
  # Create a partial application of this Proc (or similar object) using
16
- # _args_ as the already applied arguments.
16
+ # _args_ as the already applied arguments.
17
17
  def partial(*args)
18
18
  if args.empty?
19
19
  dup
@@ -26,7 +26,7 @@ module Spruz
26
26
  end
27
27
  if places < 0
28
28
  max_places = -Math.log(self.abs + 1) / Math.log(10)
29
- raise ArgumentError, "places has to be >= #{max_places.ceil}" if max_places > places
29
+ raise ArgumentError, "places has to be >= #{max_places.ceil}" if max_places > places
30
30
  end
31
31
  t = self
32
32
  f = 10.0 ** places
@@ -0,0 +1,23 @@
1
+ module Spruz
2
+ module SecureWrite
3
+ # Write to a file atomically
4
+ def secure_write(filename, content = nil, mode = 'w')
5
+ temp = File.new(filename + ".tmp.#$$.#{Time.now.to_f}", mode)
6
+ if content.nil? and block_given?
7
+ yield temp
8
+ elsif !content.nil?
9
+ temp.write content
10
+ else
11
+ raise ArgumentError, "either content or block argument required"
12
+ end
13
+ temp.fsync
14
+ size = temp.stat.size
15
+ temp.close
16
+ File.rename temp.path, filename
17
+ size
18
+ ensure
19
+ temp and !temp.closed? and temp.close
20
+ File.file?(temp.path) and File.unlink temp.path
21
+ end
22
+ end
23
+ end
@@ -8,7 +8,7 @@ module Spruz
8
8
  self[0].chr.downcase + camelize[1..-1]
9
9
  end
10
10
  end
11
-
11
+
12
12
  alias camelcase camelize
13
13
  end
14
14
  end
@@ -0,0 +1,103 @@
1
+ require 'spruz/xt/symbol_to_proc'
2
+
3
+ module Spruz
4
+ module StringVersion
5
+ class Version
6
+ include Comparable
7
+
8
+ def initialize(string)
9
+ string =~ /\A[\.\d]+\Z/ or raise ArgumentError, "#{string.inspect} isn't a version number"
10
+ @version = string.frozen? ? string.dup : string
11
+ end
12
+
13
+ def major
14
+ self[0]
15
+ end
16
+
17
+ def major=(number)
18
+ self[0] = number
19
+ end
20
+
21
+ def minor
22
+ self[1]
23
+ end
24
+
25
+ def minor=(number)
26
+ self[1] = number
27
+ end
28
+
29
+ def build
30
+ self[2]
31
+ end
32
+
33
+ def build=(number)
34
+ self[2] = number
35
+ end
36
+
37
+ def revision
38
+ self[3]
39
+ end
40
+
41
+ def revision=(number)
42
+ self[3] = number
43
+ end
44
+
45
+ def [](index)
46
+ array[index]
47
+ end
48
+
49
+ def []=(index, value)
50
+ value = value.to_i
51
+ value >= 0 or raise ArgumentError, "version numbers can't contain negative numbers like #{value}"
52
+ a = array
53
+ @array = nil
54
+ a[index] = value
55
+ a.map! { |x| x.nil? ? 0 : x }
56
+ @version.replace a * '.'
57
+ end
58
+
59
+ def succ!
60
+ self[-1] += 1
61
+ end
62
+
63
+ def pred!
64
+ self[-1] -= 1
65
+ end
66
+
67
+ def <=>(other)
68
+ pairs = array.zip(other.array)
69
+ pairs.map! { |a, b| [ a.nil? ? 0 : a, b.nil? ? 0 : b ] }
70
+ a, b = pairs.transpose
71
+ a <=> b
72
+ end
73
+
74
+ def ==(other)
75
+ (self <=> other).zero?
76
+ end
77
+
78
+ def array
79
+ @version.split('.').map(&:to_i)
80
+ end
81
+
82
+ alias to_a array
83
+
84
+ def to_s
85
+ @version
86
+ end
87
+
88
+ alias inspect to_s
89
+
90
+ def version
91
+ self
92
+ end
93
+ end
94
+
95
+ def version
96
+ if frozen?
97
+ Version.new(self)
98
+ else
99
+ @version ||= Version.new(self)
100
+ end
101
+ end
102
+ end
103
+ end
@@ -3,7 +3,7 @@ module Spruz
3
3
  # Create a subhash from this hash, that only contains key-value pairs
4
4
  # matching +patterns+ and return it. +patterns+ can be for example /^foo/
5
5
  # to put 'foobar' and 'foobaz' or 'foo'/:foo to put 'foo' into the subhash.
6
- #
6
+ #
7
7
  # If a block is given this method yields to it after the first pattern
8
8
  # matched with a 3-tuple of +(key, value, match_data)+ using the return
9
9
  # value of the block as the value of the result hash. +match_data+ is a
@@ -17,7 +17,7 @@ module Spruz
17
17
  result =
18
18
  if default_proc
19
19
  self.class.new(&default_proc)
20
- else
20
+ else
21
21
  self.class.new(default)
22
22
  end
23
23
  if block_given?
@@ -1,6 +1,6 @@
1
1
  module Spruz
2
2
  # Spruz version
3
- VERSION = '0.2.11'
3
+ VERSION = '0.2.12'
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:
@@ -1,20 +1,17 @@
1
+ require 'spruz/secure_write'
2
+
1
3
  module Spruz
2
4
  module Write
3
- # Write to a file atomically
4
- def write(filename, content = nil, mode = 'w')
5
- temp = File.new(filename + ".tmp.#$$.#{Time.now.to_f}", mode)
6
- if content.nil? and block_given?
7
- yield temp
8
- elsif !content.nil?
9
- temp.write content
5
+ def self.extended(modul)
6
+ modul.extend SecureWrite
7
+ if modul.respond_to?(:write)
8
+ $DEBUG and warn "Skipping inclusion of Spruz::Write#write method, include Spruz::Write::SecureWrite#secure_write instead"
10
9
  else
11
- raise ArgumentError, "either content or block argument required"
10
+ class << modul; self; end.instance_eval do
11
+ alias_method :write, :secure_write
12
+ end
12
13
  end
13
- temp.close
14
- File.rename temp.path, filename
15
- ensure
16
- temp and !temp.closed? and temp.close
17
- File.file?(temp.path) and File.unlink temp.path
14
+ super
18
15
  end
19
16
  end
20
17
  end
@@ -14,6 +14,7 @@ module Spruz
14
14
  require 'spruz/xt/p'
15
15
  require 'spruz/xt/symbol_to_proc'
16
16
  require 'spruz/xt/write'
17
+ require 'spruz/xt/secure_write'
17
18
  require 'spruz/xt/deep_dup'
18
19
  require 'spruz/xt/attempt'
19
20
  require 'spruz/xt/hash_symbolize_keys_recursive'
@@ -15,7 +15,7 @@ module Spruz
15
15
  # dispatch.found?(self)
16
16
  elsif dispatch
17
17
  obj = __send__(dispatch, *args)
18
- obj = nil if obj.blank?
18
+ obj = nil if obj.blank?
19
19
  else
20
20
  obj = self
21
21
  end
@@ -1,23 +1,25 @@
1
+ require 'spruz/xt/string_version'
2
+
1
3
  class Object
2
- if RUBY_VERSION >= '1.9'
3
- def named(name, method, *args, &named_block)
4
+ if RUBY_VERSION.version >= '1.9'.version
5
+ def named(name, method, *args, &named_block)
4
6
  extend Module.new {
5
7
  define_method(name) do |*rest, &block|
6
8
  block = named_block if named_block
7
- __send__(method, *(args + rest), &block)
9
+ __send__(method, *(args + rest), &block)
8
10
  end
9
11
  }
10
12
  end
11
13
  else
12
- def named(name, method, *args, &block)
14
+ def named(name, method, *args, &block)
13
15
  extend Module.new { define_method(name) { |*rest| __send__(method, *(args + rest), &block) } }
14
16
  end
15
17
  end
16
18
  end
17
19
 
18
20
  class Module
19
- if RUBY_VERSION >= '1.9'
20
- def named(name, method, *args, &named_block)
21
+ if RUBY_VERSION.version >= '1.9'.version
22
+ def named(name, method, *args, &named_block)
21
23
  include Module.new {
22
24
  define_method(name) do |*rest, &block|
23
25
  block = named_block if named_block
@@ -26,7 +28,7 @@ class Module
26
28
  }
27
29
  end
28
30
  else
29
- def named(name, method, *args, &block)
31
+ def named(name, method, *args, &block)
30
32
  include Module.new { define_method(name) { |*rest| __send__(method, *(args + rest), &block) } }
31
33
  end
32
34
  end
@@ -0,0 +1,11 @@
1
+ require 'spruz/secure_write'
2
+
3
+ module Spruz
4
+ #class ::Object
5
+ # include Spruz::SecureWrite
6
+ #end
7
+
8
+ class ::IO
9
+ extend Spruz::SecureWrite
10
+ end
11
+ end
@@ -3,4 +3,5 @@ require 'spruz'
3
3
  module Spruz
4
4
  require 'spruz/xt/string_camelize'
5
5
  require 'spruz/xt/string_underscore'
6
+ require 'spruz/xt/string_version'
6
7
  end
@@ -0,0 +1,9 @@
1
+ require 'spruz'
2
+
3
+ module Spruz
4
+ require 'spruz/string_version'
5
+
6
+ class ::String
7
+ include StringVersion
8
+ end
9
+ end
@@ -2,33 +2,32 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{spruz}
5
- s.version = "0.2.11"
5
+ s.version = "0.2.12"
6
6
 
7
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-07-16}
10
- s.default_executable = %q{enum}
8
+ s.authors = [%q{Florian Frank}]
9
+ s.date = %q{2011-08-05}
11
10
  s.description = %q{All the stuff that isn't good/big enough for a real library.}
12
11
  s.email = %q{flori@ping.de}
13
- s.executables = ["enum"]
14
- s.extra_rdoc_files = ["README.rdoc", "lib/spruz.rb", "lib/spruz/hash_symbolize_keys_recursive.rb", "lib/spruz/string_underscore.rb", "lib/spruz/hash_union.rb", "lib/spruz/write.rb", "lib/spruz/version.rb", "lib/spruz/round.rb", "lib/spruz/go.rb", "lib/spruz/generator.rb", "lib/spruz/string_camelize.rb", "lib/spruz/shuffle.rb", "lib/spruz/deep_dup.rb", "lib/spruz/memoize.rb", "lib/spruz/subhash.rb", "lib/spruz/bijection.rb", "lib/spruz/limited.rb", "lib/spruz/attempt.rb", "lib/spruz/to_proc.rb", "lib/spruz/module_group.rb", "lib/spruz/null.rb", "lib/spruz/xt.rb", "lib/spruz/once.rb", "lib/spruz/xt/named.rb", "lib/spruz/xt/hash_symbolize_keys_recursive.rb", "lib/spruz/xt/string_underscore.rb", "lib/spruz/xt/hash_union.rb", "lib/spruz/xt/write.rb", "lib/spruz/xt/irb.rb", "lib/spruz/xt/round.rb", "lib/spruz/xt/string_camelize.rb", "lib/spruz/xt/shuffle.rb", "lib/spruz/xt/deep_dup.rb", "lib/spruz/xt/symbol_to_proc.rb", "lib/spruz/xt/subhash.rb", "lib/spruz/xt/attempt.rb", "lib/spruz/xt/null.rb", "lib/spruz/xt/p.rb", "lib/spruz/xt/partial_application.rb", "lib/spruz/xt/time_dummy.rb", "lib/spruz/xt/string.rb", "lib/spruz/xt/full.rb", "lib/spruz/xt/range_plus.rb", "lib/spruz/xt/count_by.rb", "lib/spruz/xt/blank.rb", "lib/spruz/xt/uniq_by.rb", "lib/spruz/p.rb", "lib/spruz/minimize.rb", "lib/spruz/partial_application.rb", "lib/spruz/time_dummy.rb", "lib/spruz/range_plus.rb", "lib/spruz/count_by.rb", "lib/spruz/uniq_by.rb"]
15
- s.files = [".gitignore", ".travis.yml", "Gemfile", "LICENSE", "README.rdoc", "Rakefile", "VERSION", "bin/enum", "lib/spruz.rb", "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/range_plus.rb", "lib/spruz/round.rb", "lib/spruz/shuffle.rb", "lib/spruz/string_camelize.rb", "lib/spruz/string_underscore.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.rb", "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/named.rb", "lib/spruz/xt/null.rb", "lib/spruz/xt/p.rb", "lib/spruz/xt/partial_application.rb", "lib/spruz/xt/range_plus.rb", "lib/spruz/xt/round.rb", "lib/spruz/xt/shuffle.rb", "lib/spruz/xt/string.rb", "lib/spruz/xt/string_camelize.rb", "lib/spruz/xt/string_underscore.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", "spruz.gemspec", "tests/test_spruz.rb", "tests/test_spruz_memoize.rb"]
12
+ s.executables = [%q{enum}]
13
+ s.extra_rdoc_files = [%q{README.rdoc}, %q{lib/spruz.rb}, %q{lib/spruz/hash_symbolize_keys_recursive.rb}, %q{lib/spruz/string_underscore.rb}, %q{lib/spruz/hash_union.rb}, %q{lib/spruz/write.rb}, %q{lib/spruz/version.rb}, %q{lib/spruz/round.rb}, %q{lib/spruz/go.rb}, %q{lib/spruz/generator.rb}, %q{lib/spruz/string_camelize.rb}, %q{lib/spruz/shuffle.rb}, %q{lib/spruz/deep_dup.rb}, %q{lib/spruz/memoize.rb}, %q{lib/spruz/subhash.rb}, %q{lib/spruz/bijection.rb}, %q{lib/spruz/limited.rb}, %q{lib/spruz/attempt.rb}, %q{lib/spruz/to_proc.rb}, %q{lib/spruz/module_group.rb}, %q{lib/spruz/null.rb}, %q{lib/spruz/secure_write.rb}, %q{lib/spruz/xt.rb}, %q{lib/spruz/string_version.rb}, %q{lib/spruz/once.rb}, %q{lib/spruz/xt/named.rb}, %q{lib/spruz/xt/hash_symbolize_keys_recursive.rb}, %q{lib/spruz/xt/string_underscore.rb}, %q{lib/spruz/xt/hash_union.rb}, %q{lib/spruz/xt/write.rb}, %q{lib/spruz/xt/irb.rb}, %q{lib/spruz/xt/round.rb}, %q{lib/spruz/xt/string_camelize.rb}, %q{lib/spruz/xt/shuffle.rb}, %q{lib/spruz/xt/deep_dup.rb}, %q{lib/spruz/xt/symbol_to_proc.rb}, %q{lib/spruz/xt/subhash.rb}, %q{lib/spruz/xt/attempt.rb}, %q{lib/spruz/xt/null.rb}, %q{lib/spruz/xt/secure_write.rb}, %q{lib/spruz/xt/string_version.rb}, %q{lib/spruz/xt/p.rb}, %q{lib/spruz/xt/partial_application.rb}, %q{lib/spruz/xt/time_dummy.rb}, %q{lib/spruz/xt/string.rb}, %q{lib/spruz/xt/full.rb}, %q{lib/spruz/xt/range_plus.rb}, %q{lib/spruz/xt/count_by.rb}, %q{lib/spruz/xt/blank.rb}, %q{lib/spruz/xt/uniq_by.rb}, %q{lib/spruz/p.rb}, %q{lib/spruz/minimize.rb}, %q{lib/spruz/partial_application.rb}, %q{lib/spruz/time_dummy.rb}, %q{lib/spruz/range_plus.rb}, %q{lib/spruz/count_by.rb}, %q{lib/spruz/uniq_by.rb}]
14
+ s.files = [%q{.gitignore}, %q{.travis.yml}, %q{Gemfile}, %q{LICENSE}, %q{README.rdoc}, %q{Rakefile}, %q{TODO}, %q{VERSION}, %q{bin/enum}, %q{lib/spruz.rb}, %q{lib/spruz/attempt.rb}, %q{lib/spruz/bijection.rb}, %q{lib/spruz/count_by.rb}, %q{lib/spruz/deep_dup.rb}, %q{lib/spruz/generator.rb}, %q{lib/spruz/go.rb}, %q{lib/spruz/hash_symbolize_keys_recursive.rb}, %q{lib/spruz/hash_union.rb}, %q{lib/spruz/limited.rb}, %q{lib/spruz/memoize.rb}, %q{lib/spruz/minimize.rb}, %q{lib/spruz/module_group.rb}, %q{lib/spruz/null.rb}, %q{lib/spruz/once.rb}, %q{lib/spruz/p.rb}, %q{lib/spruz/partial_application.rb}, %q{lib/spruz/range_plus.rb}, %q{lib/spruz/round.rb}, %q{lib/spruz/secure_write.rb}, %q{lib/spruz/shuffle.rb}, %q{lib/spruz/string_camelize.rb}, %q{lib/spruz/string_underscore.rb}, %q{lib/spruz/string_version.rb}, %q{lib/spruz/subhash.rb}, %q{lib/spruz/time_dummy.rb}, %q{lib/spruz/to_proc.rb}, %q{lib/spruz/uniq_by.rb}, %q{lib/spruz/version.rb}, %q{lib/spruz/write.rb}, %q{lib/spruz/xt.rb}, %q{lib/spruz/xt/attempt.rb}, %q{lib/spruz/xt/blank.rb}, %q{lib/spruz/xt/count_by.rb}, %q{lib/spruz/xt/deep_dup.rb}, %q{lib/spruz/xt/full.rb}, %q{lib/spruz/xt/hash_symbolize_keys_recursive.rb}, %q{lib/spruz/xt/hash_union.rb}, %q{lib/spruz/xt/irb.rb}, %q{lib/spruz/xt/named.rb}, %q{lib/spruz/xt/null.rb}, %q{lib/spruz/xt/p.rb}, %q{lib/spruz/xt/partial_application.rb}, %q{lib/spruz/xt/range_plus.rb}, %q{lib/spruz/xt/round.rb}, %q{lib/spruz/xt/secure_write.rb}, %q{lib/spruz/xt/shuffle.rb}, %q{lib/spruz/xt/string.rb}, %q{lib/spruz/xt/string_camelize.rb}, %q{lib/spruz/xt/string_underscore.rb}, %q{lib/spruz/xt/string_version.rb}, %q{lib/spruz/xt/subhash.rb}, %q{lib/spruz/xt/symbol_to_proc.rb}, %q{lib/spruz/xt/time_dummy.rb}, %q{lib/spruz/xt/uniq_by.rb}, %q{lib/spruz/xt/write.rb}, %q{spruz.gemspec}, %q{tests/spruz_memoize_test.rb}, %q{tests/spruz_secure_write_test.rb}, %q{tests/spruz_test.rb}]
16
15
  s.homepage = %q{http://flori.github.com/spruz}
17
- s.rdoc_options = ["--title", "Spruz - Useful stuff.", "--main", "README.rdoc"]
18
- s.require_paths = ["lib"]
19
- s.rubygems_version = %q{1.6.2}
16
+ s.rdoc_options = [%q{--title}, %q{Spruz - Useful stuff.}, %q{--main}, %q{README.rdoc}]
17
+ s.require_paths = [%q{lib}]
18
+ s.rubygems_version = %q{1.8.6}
20
19
  s.summary = %q{Useful stuff.}
21
- s.test_files = ["tests/test_spruz_memoize.rb", "tests/test_spruz.rb"]
20
+ s.test_files = [%q{tests/spruz_secure_write_test.rb}, %q{tests/spruz_test.rb}, %q{tests/spruz_memoize_test.rb}]
22
21
 
23
22
  if s.respond_to? :specification_version then
24
23
  s.specification_version = 3
25
24
 
26
25
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
- s.add_development_dependency(%q<gem_hadar>, ["~> 0.0.4"])
26
+ s.add_development_dependency(%q<gem_hadar>, ["~> 0.0.9"])
28
27
  else
29
- s.add_dependency(%q<gem_hadar>, ["~> 0.0.4"])
28
+ s.add_dependency(%q<gem_hadar>, ["~> 0.0.9"])
30
29
  end
31
30
  else
32
- s.add_dependency(%q<gem_hadar>, ["~> 0.0.4"])
31
+ s.add_dependency(%q<gem_hadar>, ["~> 0.0.9"])
33
32
  end
34
33
  end
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'tempfile'
5
+ require 'spruz'
6
+
7
+ module Spruz
8
+ class SpruzSecureWriteTest < Test::Unit::TestCase
9
+ module A
10
+ extend SecureWrite
11
+ end
12
+
13
+ def test_secure_write
14
+ assert_equal 4, A.secure_write(fn = File.join(Dir.tmpdir, "A_file.#$$"), 'test')
15
+ assert_equal 4, A.secure_write(fn = File.join(Dir.tmpdir, "A_file.#$$")) { |f| f.write('test') }
16
+ assert_equal 'test', File.read(fn)
17
+ assert_raise(ArgumentError) { A.secure_write }
18
+ end
19
+
20
+ module B
21
+ extend Write
22
+ end
23
+
24
+ module C
25
+ def self.write(*args)
26
+ args
27
+ end
28
+ extend Write
29
+ end
30
+
31
+ class ::IO
32
+ extend Write
33
+ end
34
+
35
+ def test_write
36
+ assert_equal 4, B.write(fn = File.join(Dir.tmpdir, "B_file.#$$"), 'test')
37
+ assert_equal 4, B.write(fn = File.join(Dir.tmpdir, "B_file.#$$")) { |f| f.write('test') }
38
+ assert_equal 4, IO.write(fn = File.join(Dir.tmpdir, "IO_file.#$$"), 'test')
39
+ assert_equal 'test', File.read(fn)
40
+ result = C.write(fn = File.join(Dir.tmpdir, "C_file.#$$"), 'test')
41
+ assert_equal [ fn, 'test' ], result
42
+ end
43
+ end
44
+ end
@@ -502,7 +502,7 @@ module Spruz
502
502
  end
503
503
  end
504
504
  end
505
-
505
+
506
506
  class TryTest < Test::Unit::TestCase
507
507
  require 'spruz/xt/attempt'
508
508
 
@@ -598,4 +598,31 @@ module Spruz
598
598
  assert_equal 'foo/bar', 'Foo::Bar'.underscore
599
599
  end
600
600
  end
601
+
602
+ class StringVersionTest < Test::Unit::TestCase
603
+ def test_comparison
604
+ assert_operator '1.2'.version, :<, '1.3'.version
605
+ assert_operator '1.3'.version, :>, '1.2'.version
606
+ assert_operator '1.2'.version, :<=, '1.2'.version
607
+ assert_operator '1.2'.version, :>=, '1.2'.version
608
+ assert_operator '1.2'.version, :==, '1.2'.version
609
+ end
610
+
611
+ def test_change
612
+ s = '1.2'
613
+ s.version.revision = 1
614
+ assert_equal '1.2.0.1', s
615
+ s.version.revision += 1
616
+ assert_equal '1.2.0.2', s
617
+ s.version.succ!
618
+ assert_equal '1.2.0.3', s
619
+ s.version.pred!
620
+ assert_equal '1.2.0.2', s
621
+ assert_raise(ArgumentError) { s.version.build -= 1 }
622
+ s.version.major = 2
623
+ assert_equal '2.2.0.2', s
624
+ s.version.minor = 1
625
+ assert_equal '2.1.0.2', s
626
+ end
627
+ end
601
628
  end
metadata CHANGED
@@ -1,46 +1,33 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: spruz
3
- version: !ruby/object:Gem::Version
4
- hash: 1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.12
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 11
10
- version: 0.2.11
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Florian Frank
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-07-16 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2011-08-05 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: gem_hadar
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2157109200 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
18
+ requirements:
27
19
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 23
30
- segments:
31
- - 0
32
- - 0
33
- - 4
34
- version: 0.0.4
20
+ - !ruby/object:Gem::Version
21
+ version: 0.0.9
35
22
  type: :development
36
- version_requirements: *id001
23
+ prerelease: false
24
+ version_requirements: *2157109200
37
25
  description: All the stuff that isn't good/big enough for a real library.
38
26
  email: flori@ping.de
39
- executables:
27
+ executables:
40
28
  - enum
41
29
  extensions: []
42
-
43
- extra_rdoc_files:
30
+ extra_rdoc_files:
44
31
  - README.rdoc
45
32
  - lib/spruz.rb
46
33
  - lib/spruz/hash_symbolize_keys_recursive.rb
@@ -62,7 +49,9 @@ extra_rdoc_files:
62
49
  - lib/spruz/to_proc.rb
63
50
  - lib/spruz/module_group.rb
64
51
  - lib/spruz/null.rb
52
+ - lib/spruz/secure_write.rb
65
53
  - lib/spruz/xt.rb
54
+ - lib/spruz/string_version.rb
66
55
  - lib/spruz/once.rb
67
56
  - lib/spruz/xt/named.rb
68
57
  - lib/spruz/xt/hash_symbolize_keys_recursive.rb
@@ -78,6 +67,8 @@ extra_rdoc_files:
78
67
  - lib/spruz/xt/subhash.rb
79
68
  - lib/spruz/xt/attempt.rb
80
69
  - lib/spruz/xt/null.rb
70
+ - lib/spruz/xt/secure_write.rb
71
+ - lib/spruz/xt/string_version.rb
81
72
  - lib/spruz/xt/p.rb
82
73
  - lib/spruz/xt/partial_application.rb
83
74
  - lib/spruz/xt/time_dummy.rb
@@ -94,13 +85,14 @@ extra_rdoc_files:
94
85
  - lib/spruz/range_plus.rb
95
86
  - lib/spruz/count_by.rb
96
87
  - lib/spruz/uniq_by.rb
97
- files:
88
+ files:
98
89
  - .gitignore
99
90
  - .travis.yml
100
91
  - Gemfile
101
92
  - LICENSE
102
93
  - README.rdoc
103
94
  - Rakefile
95
+ - TODO
104
96
  - VERSION
105
97
  - bin/enum
106
98
  - lib/spruz.rb
@@ -122,9 +114,11 @@ files:
122
114
  - lib/spruz/partial_application.rb
123
115
  - lib/spruz/range_plus.rb
124
116
  - lib/spruz/round.rb
117
+ - lib/spruz/secure_write.rb
125
118
  - lib/spruz/shuffle.rb
126
119
  - lib/spruz/string_camelize.rb
127
120
  - lib/spruz/string_underscore.rb
121
+ - lib/spruz/string_version.rb
128
122
  - lib/spruz/subhash.rb
129
123
  - lib/spruz/time_dummy.rb
130
124
  - lib/spruz/to_proc.rb
@@ -146,55 +140,50 @@ files:
146
140
  - lib/spruz/xt/partial_application.rb
147
141
  - lib/spruz/xt/range_plus.rb
148
142
  - lib/spruz/xt/round.rb
143
+ - lib/spruz/xt/secure_write.rb
149
144
  - lib/spruz/xt/shuffle.rb
150
145
  - lib/spruz/xt/string.rb
151
146
  - lib/spruz/xt/string_camelize.rb
152
147
  - lib/spruz/xt/string_underscore.rb
148
+ - lib/spruz/xt/string_version.rb
153
149
  - lib/spruz/xt/subhash.rb
154
150
  - lib/spruz/xt/symbol_to_proc.rb
155
151
  - lib/spruz/xt/time_dummy.rb
156
152
  - lib/spruz/xt/uniq_by.rb
157
153
  - lib/spruz/xt/write.rb
158
154
  - spruz.gemspec
159
- - tests/test_spruz.rb
160
- - tests/test_spruz_memoize.rb
161
- has_rdoc: true
155
+ - tests/spruz_memoize_test.rb
156
+ - tests/spruz_secure_write_test.rb
157
+ - tests/spruz_test.rb
162
158
  homepage: http://flori.github.com/spruz
163
159
  licenses: []
164
-
165
160
  post_install_message:
166
- rdoc_options:
161
+ rdoc_options:
167
162
  - --title
168
163
  - Spruz - Useful stuff.
169
164
  - --main
170
165
  - README.rdoc
171
- require_paths:
166
+ require_paths:
172
167
  - lib
173
- required_ruby_version: !ruby/object:Gem::Requirement
168
+ required_ruby_version: !ruby/object:Gem::Requirement
174
169
  none: false
175
- requirements:
176
- - - ">="
177
- - !ruby/object:Gem::Version
178
- hash: 3
179
- segments:
180
- - 0
181
- version: "0"
182
- required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
175
  none: false
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- hash: 3
188
- segments:
189
- - 0
190
- version: "0"
176
+ requirements:
177
+ - - ! '>='
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
191
180
  requirements: []
192
-
193
181
  rubyforge_project:
194
- rubygems_version: 1.6.2
182
+ rubygems_version: 1.8.6
195
183
  signing_key:
196
184
  specification_version: 3
197
185
  summary: Useful stuff.
198
- test_files:
199
- - tests/test_spruz_memoize.rb
200
- - tests/test_spruz.rb
186
+ test_files:
187
+ - tests/spruz_secure_write_test.rb
188
+ - tests/spruz_test.rb
189
+ - tests/spruz_memoize_test.rb