ruby_ext 0.4.11 → 0.4.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +6 -6
- data/lib/rake_ext.rb +10 -5
- data/lib/rake_ext/project.rb +31 -16
- data/lib/rspec_ext.rb +82 -19
- data/lib/ruby_ext.rb +1 -52
- data/lib/ruby_ext/core.rb +24 -0
- data/lib/ruby_ext/{array.rb → core/array.rb} +4 -2
- data/lib/ruby_ext/core/basic_object.rb +8 -0
- data/lib/ruby_ext/core/class.rb +0 -0
- data/lib/ruby_ext/{deep_clone.rb → core/deep_clone.rb} +3 -4
- data/lib/ruby_ext/core/enumerable.rb +17 -0
- data/lib/ruby_ext/{file.rb → core/file.rb} +5 -2
- data/lib/ruby_ext/core/hash.rb +23 -0
- data/lib/ruby_ext/{kernel.rb → core/kernel.rb} +0 -0
- data/lib/ruby_ext/{micelaneous.rb → core/micelaneous.rb} +0 -0
- data/lib/ruby_ext/{module.rb → core/module.rb} +13 -2
- data/lib/ruby_ext/{multiple_inheritance.rb → core/multiple_inheritance.rb} +30 -14
- data/lib/ruby_ext/{must.rb → core/must.rb} +30 -27
- data/lib/ruby_ext/{not_defined.rb → core/not_defined.rb} +0 -0
- data/lib/ruby_ext/{object.rb → core/object.rb} +0 -0
- data/lib/ruby_ext/{open_object.rb → core/open_object.rb} +21 -16
- data/lib/ruby_ext/{string.rb → core/string.rb} +27 -0
- data/lib/ruby_ext/{symbol.rb → core/symbol.rb} +0 -0
- data/lib/ruby_ext/fixes.rb +6 -0
- data/lib/ruby_ext/gems.rb +0 -1
- data/lib/ruby_ext/more.rb +11 -0
- data/lib/ruby_ext/more/declarative_cache.rb +96 -0
- data/lib/ruby_ext/more/micelaneous.rb +7 -0
- data/lib/ruby_ext/{observable2.rb → more/observable2.rb} +0 -0
- data/lib/ruby_ext/{open_constructor.rb → more/open_constructor.rb} +2 -2
- data/lib/ruby_ext/more/safe_hash.rb +214 -0
- data/lib/ruby_ext/{synchronize.rb → more/synchronize.rb} +5 -5
- data/lib/ruby_ext/{tuple.rb → more/tuple.rb} +0 -0
- data/lib/yaml_fix.rb +9 -0
- data/readme.md +46 -42
- data/spec/core/array_spec.rb +7 -0
- data/spec/{deep_clone_spec.rb → core/deep_clone_spec.rb} +2 -3
- data/spec/core/enumerable.rb +9 -0
- data/spec/{kernel_spec.rb → core/kernel_spec.rb} +4 -6
- data/spec/{kernel_spec → core/kernel_spec}/TheNamespace/ClassA.rb +0 -0
- data/spec/{kernel_spec → core/kernel_spec}/another_class.rb +0 -0
- data/spec/{kernel_spec → core/kernel_spec}/the_namespace/class_b.rb +0 -0
- data/spec/{module_spec.rb → core/module_spec.rb} +2 -4
- data/spec/{multiple_inheritance_spec.rb → core/multiple_inheritance_spec.rb} +28 -12
- data/spec/core/must_spec.rb +32 -0
- data/spec/{open_object_spec.rb → core/open_object_spec.rb} +6 -7
- data/spec/core/spec_helper.rb +2 -0
- data/spec/{declarative_cache_spec.rb → more/declarative_cache_spec.rb} +35 -8
- data/spec/{observable2_spec.rb → more/observable2_spec.rb} +3 -4
- data/spec/{open_constructor_spec.rb → more/open_constructor_spec.rb} +6 -7
- data/spec/more/safe_hash_spec.rb +133 -0
- data/spec/more/spec_helper.rb +2 -0
- data/spec/{synchronize_spec.rb → more/synchronize_spec.rb} +2 -3
- metadata +67 -100
- data/lib/ruby_ext/basic_object.rb +0 -22
- data/lib/ruby_ext/class.rb +0 -11
- data/lib/ruby_ext/declarative_cache.rb +0 -85
- data/lib/ruby_ext/extra_blank_slate.rb +0 -17
- data/lib/ruby_ext/hash.rb +0 -15
- data/lib/ruby_ext/prepare_arguments.rb +0 -105
- data/lib/ruby_ext/prototype_inheritance.rb +0 -110
- data/lib/ruby_ext/should.rb +0 -166
- data/lib/rubyopt.rb +0 -7
- data/spec/_prototype_inheritance_spec.rb +0 -190
- data/spec/array_spec.rb +0 -8
- data/spec/must_spec.rb +0 -29
- data/spec/prepare_arguments_spec.rb +0 -46
- data/spec/should_spec.rb +0 -24
- data/spec/spec_helper.rb +0 -19
@@ -1,5 +1,4 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "ruby_ext/synchronize"
|
1
|
+
require "more/spec_helper"
|
3
2
|
|
4
3
|
describe "Synchronize" do
|
5
4
|
it "synchronize_method" do
|
@@ -75,6 +74,6 @@ describe "Synchronize" do
|
|
75
74
|
def a; end
|
76
75
|
end
|
77
76
|
SAccount4.synchronize_method :a
|
78
|
-
|
77
|
+
-> {SAccount4.synchronize_method :a}.should raise_error(/twice/)
|
79
78
|
end
|
80
79
|
end
|
metadata
CHANGED
@@ -1,132 +1,99 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_ext
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 4
|
9
|
-
- 11
|
10
|
-
version: 0.4.11
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.12
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Alexey Petrushin
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2010-10-15 00:00:00 +04:00
|
12
|
+
date: 2011-06-12 00:00:00.000000000 +04:00
|
19
13
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
22
|
-
name: facets
|
23
|
-
prerelease: false
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - "="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 43
|
30
|
-
segments:
|
31
|
-
- 2
|
32
|
-
- 9
|
33
|
-
- 0
|
34
|
-
version: 2.9.0
|
35
|
-
type: :runtime
|
36
|
-
version_requirements: *id001
|
14
|
+
dependencies: []
|
37
15
|
description:
|
38
16
|
email:
|
39
17
|
executables: []
|
40
|
-
|
41
18
|
extensions: []
|
42
|
-
|
43
19
|
extra_rdoc_files: []
|
44
|
-
|
45
|
-
files:
|
20
|
+
files:
|
46
21
|
- Rakefile
|
47
22
|
- readme.md
|
48
23
|
- lib/rake_ext/project.rb
|
49
24
|
- lib/rake_ext.rb
|
50
25
|
- lib/rspec_ext.rb
|
51
|
-
- lib/ruby_ext/array.rb
|
52
|
-
- lib/ruby_ext/basic_object.rb
|
53
|
-
- lib/ruby_ext/class.rb
|
54
|
-
- lib/ruby_ext/
|
55
|
-
- lib/ruby_ext/
|
56
|
-
- lib/ruby_ext/
|
57
|
-
- lib/ruby_ext/
|
26
|
+
- lib/ruby_ext/core/array.rb
|
27
|
+
- lib/ruby_ext/core/basic_object.rb
|
28
|
+
- lib/ruby_ext/core/class.rb
|
29
|
+
- lib/ruby_ext/core/deep_clone.rb
|
30
|
+
- lib/ruby_ext/core/enumerable.rb
|
31
|
+
- lib/ruby_ext/core/file.rb
|
32
|
+
- lib/ruby_ext/core/hash.rb
|
33
|
+
- lib/ruby_ext/core/kernel.rb
|
34
|
+
- lib/ruby_ext/core/micelaneous.rb
|
35
|
+
- lib/ruby_ext/core/module.rb
|
36
|
+
- lib/ruby_ext/core/multiple_inheritance.rb
|
37
|
+
- lib/ruby_ext/core/must.rb
|
38
|
+
- lib/ruby_ext/core/not_defined.rb
|
39
|
+
- lib/ruby_ext/core/object.rb
|
40
|
+
- lib/ruby_ext/core/open_object.rb
|
41
|
+
- lib/ruby_ext/core/string.rb
|
42
|
+
- lib/ruby_ext/core/symbol.rb
|
43
|
+
- lib/ruby_ext/core.rb
|
44
|
+
- lib/ruby_ext/fixes.rb
|
58
45
|
- lib/ruby_ext/gems.rb
|
59
|
-
- lib/ruby_ext/
|
60
|
-
- lib/ruby_ext/
|
61
|
-
- lib/ruby_ext/
|
62
|
-
- lib/ruby_ext/
|
63
|
-
- lib/ruby_ext/
|
64
|
-
- lib/ruby_ext/
|
65
|
-
- lib/ruby_ext/
|
66
|
-
- lib/ruby_ext/
|
67
|
-
- lib/ruby_ext/observable2.rb
|
68
|
-
- lib/ruby_ext/open_constructor.rb
|
69
|
-
- lib/ruby_ext/open_object.rb
|
70
|
-
- lib/ruby_ext/prepare_arguments.rb
|
71
|
-
- lib/ruby_ext/prototype_inheritance.rb
|
72
|
-
- lib/ruby_ext/should.rb
|
73
|
-
- lib/ruby_ext/string.rb
|
74
|
-
- lib/ruby_ext/symbol.rb
|
75
|
-
- lib/ruby_ext/synchronize.rb
|
76
|
-
- lib/ruby_ext/tuple.rb
|
46
|
+
- lib/ruby_ext/more/declarative_cache.rb
|
47
|
+
- lib/ruby_ext/more/micelaneous.rb
|
48
|
+
- lib/ruby_ext/more/observable2.rb
|
49
|
+
- lib/ruby_ext/more/open_constructor.rb
|
50
|
+
- lib/ruby_ext/more/safe_hash.rb
|
51
|
+
- lib/ruby_ext/more/synchronize.rb
|
52
|
+
- lib/ruby_ext/more/tuple.rb
|
53
|
+
- lib/ruby_ext/more.rb
|
77
54
|
- lib/ruby_ext.rb
|
78
|
-
- lib/
|
79
|
-
- spec/
|
80
|
-
- spec/
|
81
|
-
- spec/
|
82
|
-
- spec/
|
83
|
-
- spec/kernel_spec/
|
84
|
-
- spec/kernel_spec/
|
85
|
-
- spec/kernel_spec
|
86
|
-
- spec/
|
87
|
-
- spec/
|
88
|
-
- spec/
|
89
|
-
- spec/
|
90
|
-
- spec/
|
91
|
-
- spec/
|
92
|
-
- spec/
|
93
|
-
- spec/
|
94
|
-
- spec/
|
95
|
-
- spec/spec_helper.rb
|
96
|
-
- spec/synchronize_spec.rb
|
55
|
+
- lib/yaml_fix.rb
|
56
|
+
- spec/core/array_spec.rb
|
57
|
+
- spec/core/deep_clone_spec.rb
|
58
|
+
- spec/core/enumerable.rb
|
59
|
+
- spec/core/kernel_spec/another_class.rb
|
60
|
+
- spec/core/kernel_spec/the_namespace/class_b.rb
|
61
|
+
- spec/core/kernel_spec/TheNamespace/ClassA.rb
|
62
|
+
- spec/core/kernel_spec.rb
|
63
|
+
- spec/core/module_spec.rb
|
64
|
+
- spec/core/multiple_inheritance_spec.rb
|
65
|
+
- spec/core/must_spec.rb
|
66
|
+
- spec/core/open_object_spec.rb
|
67
|
+
- spec/core/spec_helper.rb
|
68
|
+
- spec/more/declarative_cache_spec.rb
|
69
|
+
- spec/more/observable2_spec.rb
|
70
|
+
- spec/more/open_constructor_spec.rb
|
71
|
+
- spec/more/safe_hash_spec.rb
|
72
|
+
- spec/more/spec_helper.rb
|
73
|
+
- spec/more/synchronize_spec.rb
|
97
74
|
has_rdoc: true
|
98
75
|
homepage: http://github.com/alexeypetrushin/ruby_ext
|
99
76
|
licenses: []
|
100
|
-
|
101
77
|
post_install_message:
|
102
78
|
rdoc_options: []
|
103
|
-
|
104
|
-
require_paths:
|
79
|
+
require_paths:
|
105
80
|
- lib
|
106
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
82
|
none: false
|
108
|
-
requirements:
|
109
|
-
- -
|
110
|
-
- !ruby/object:Gem::Version
|
111
|
-
|
112
|
-
|
113
|
-
- 0
|
114
|
-
version: "0"
|
115
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
88
|
none: false
|
117
|
-
requirements:
|
118
|
-
- -
|
119
|
-
- !ruby/object:Gem::Version
|
120
|
-
|
121
|
-
segments:
|
122
|
-
- 0
|
123
|
-
version: "0"
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
124
93
|
requirements: []
|
125
|
-
|
126
94
|
rubyforge_project:
|
127
|
-
rubygems_version: 1.
|
95
|
+
rubygems_version: 1.5.1
|
128
96
|
signing_key:
|
129
97
|
specification_version: 3
|
130
|
-
summary: Ruby
|
98
|
+
summary: Ruby Extensions
|
131
99
|
test_files: []
|
132
|
-
|
@@ -1,22 +0,0 @@
|
|
1
|
-
if defined? ::BasicObject
|
2
|
-
# A class with no predefined methods that behaves similarly to Builder's
|
3
|
-
# BlankSlate. Used for proxy classes.
|
4
|
-
class BasicObject < ::BasicObject
|
5
|
-
begin
|
6
|
-
undef_method :==
|
7
|
-
undef_method :equal?
|
8
|
-
rescue
|
9
|
-
end
|
10
|
-
|
11
|
-
# Let ActiveSupport::BasicObject at least raise exceptions.
|
12
|
-
def raise(*args)
|
13
|
-
::Object.send(:raise, *args)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
else
|
17
|
-
class BasicObject #:nodoc:
|
18
|
-
instance_methods.each do |m|
|
19
|
-
undef_method(m) if m.to_s !~ /(?:^__|^nil\?$|^send$|^object_id$)/
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/lib/ruby_ext/class.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'monitor'
|
2
|
-
|
3
|
-
class Module
|
4
|
-
def cache_method *methods
|
5
|
-
DeclarativeCache.cache_method self, *methods
|
6
|
-
end
|
7
|
-
|
8
|
-
def cache_method_with_params *methods
|
9
|
-
DeclarativeCache.cache_method_with_params self, *methods
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class Object
|
14
|
-
def clear_cache_method
|
15
|
-
instance_variables.each do |iv|
|
16
|
-
remove_instance_variable iv if iv =~ /^@cached_/
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
module DeclarativeCache
|
22
|
-
DISABLED = false
|
23
|
-
|
24
|
-
warn "CASHE DISABLED" if DISABLED
|
25
|
-
unless DISABLED
|
26
|
-
class << self
|
27
|
-
|
28
|
-
def cache_method klass, *methods
|
29
|
-
methods.each do |method|
|
30
|
-
klass.class_eval do
|
31
|
-
als = "cached_#{escape_method(method)}"
|
32
|
-
iv_check = "@#{als}_check"
|
33
|
-
iv = "@#{als}"
|
34
|
-
|
35
|
-
raise "Can't cache the #{method} twice!" if instance_methods.include?(als)
|
36
|
-
|
37
|
-
alias_method als, method
|
38
|
-
|
39
|
-
define_method method do |*args|
|
40
|
-
raise "You tried to use cache without params for method with params (use 'cache_method_with_params' instead)!" unless args.empty?
|
41
|
-
unless cached = instance_variable_get(iv)
|
42
|
-
unless check = instance_variable_get(iv_check)
|
43
|
-
cached = send als
|
44
|
-
instance_variable_set iv, cached
|
45
|
-
instance_variable_set iv_check, true
|
46
|
-
end
|
47
|
-
end
|
48
|
-
cached
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def cache_method_with_params klass, *methods
|
55
|
-
methods.each do |method|
|
56
|
-
klass.class_eval do
|
57
|
-
als = "cached_#{escape_method(method)}"
|
58
|
-
iv = "@#{als}"
|
59
|
-
|
60
|
-
raise "Can't cache the '#{method}' twice!" if instance_methods.include?(als)
|
61
|
-
|
62
|
-
alias_method als, method
|
63
|
-
|
64
|
-
define_method method do |*args|
|
65
|
-
unless results = instance_variable_get(iv)
|
66
|
-
results = Hash.new(NotDefined)
|
67
|
-
instance_variable_set iv, results
|
68
|
-
end
|
69
|
-
|
70
|
-
result = results[args]
|
71
|
-
|
72
|
-
if result.equal? NotDefined
|
73
|
-
result = send als, *args
|
74
|
-
results[args] = result
|
75
|
-
end
|
76
|
-
|
77
|
-
result
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
class ExtraBlankSlate
|
2
|
-
PRESERVE_METHODS = %w(object_id)
|
3
|
-
instance_methods.each { |m| undef_method m unless m =~ /^__/ or PRESERVE_METHODS.include?(m.to_s)}
|
4
|
-
|
5
|
-
CUSTOM_UNDEFINE = [:p, :select, :puts]
|
6
|
-
|
7
|
-
undefine = Kernel.instance_methods + Object.instance_methods + CUSTOM_UNDEFINE
|
8
|
-
ExtraBlankSlate.instance_methods.each{|m| undefine.delete m}
|
9
|
-
|
10
|
-
undefine.each do |m|
|
11
|
-
script = %{\
|
12
|
-
def #{m} *p, &b
|
13
|
-
method_missing :#{m}, *p, &b
|
14
|
-
end}
|
15
|
-
class_eval script, __FILE__, __LINE__
|
16
|
-
end
|
17
|
-
end
|
data/lib/ruby_ext/hash.rb
DELETED
@@ -1,105 +0,0 @@
|
|
1
|
-
class ArgumentsParser
|
2
|
-
class << self
|
3
|
-
def register method, arguments
|
4
|
-
# check and prepare metadata
|
5
|
-
arguments.collect!{|meta| meta.is_a?(Hash) ? meta : {:type => meta}}
|
6
|
-
arguments.each{|meta| meta.must.include :type}
|
7
|
-
|
8
|
-
# register
|
9
|
-
@registry ||= {}
|
10
|
-
@registry[method] = arguments
|
11
|
-
end
|
12
|
-
|
13
|
-
def parse_arguments_for method, *args, &block
|
14
|
-
metadata = @registry[method]
|
15
|
-
index = 0
|
16
|
-
parsed_args = metadata.collect do |options|
|
17
|
-
send options[:type], args, block, options, index, (index == metadata.size - 1)
|
18
|
-
end
|
19
|
-
args.must_be.empty
|
20
|
-
return parsed_args
|
21
|
-
end
|
22
|
-
|
23
|
-
protected
|
24
|
-
def string args, block, options, index, last
|
25
|
-
object(args, block, options, index, last) || ""
|
26
|
-
end
|
27
|
-
|
28
|
-
def object args, block, options, index, last
|
29
|
-
a = if range = options[:range]
|
30
|
-
if range == :except_last_hash
|
31
|
-
if args.size == 1 and args.last.is_a? Hash
|
32
|
-
nil
|
33
|
-
else
|
34
|
-
args.shift
|
35
|
-
end
|
36
|
-
else
|
37
|
-
must_be.never_called
|
38
|
-
end
|
39
|
-
else
|
40
|
-
args.shift
|
41
|
-
end
|
42
|
-
|
43
|
-
a = _common_options a, options
|
44
|
-
a
|
45
|
-
end
|
46
|
-
|
47
|
-
def array args, block, options, index, last
|
48
|
-
a = if last
|
49
|
-
args
|
50
|
-
elsif range = options[:range]
|
51
|
-
if range == :except_last_hash
|
52
|
-
if args.last.is_a? Hash
|
53
|
-
tmp = args[0..-2]
|
54
|
-
args[0..-2] = nil
|
55
|
-
tmp
|
56
|
-
else
|
57
|
-
tmp = args[0..-1]
|
58
|
-
args.clear
|
59
|
-
tmp
|
60
|
-
end
|
61
|
-
else
|
62
|
-
must_be.never_called
|
63
|
-
end
|
64
|
-
else
|
65
|
-
args.shift
|
66
|
-
end
|
67
|
-
|
68
|
-
a = _common_options a, options
|
69
|
-
a ||= []
|
70
|
-
a = [a] unless a.is_a?(Array)
|
71
|
-
a
|
72
|
-
end
|
73
|
-
|
74
|
-
def hash args, block, options, index, last
|
75
|
-
a = object(args, block, options, index, last) || {}
|
76
|
-
a.must_be.a Hash
|
77
|
-
a
|
78
|
-
end
|
79
|
-
|
80
|
-
def _common_options a, options
|
81
|
-
a.must_not_be.nil if options[:require]
|
82
|
-
if (default = options[:default]) and a.eql?(nil)
|
83
|
-
a = default
|
84
|
-
end
|
85
|
-
a
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
Module.class_eval do
|
91
|
-
def prepare_arguments_for method, *args
|
92
|
-
# Register parsers
|
93
|
-
ArgumentsParser.register method, args
|
94
|
-
|
95
|
-
# Wrap method
|
96
|
-
old_method = :"#{method}_wparg"
|
97
|
-
alias_method old_method, method
|
98
|
-
code = <<END
|
99
|
-
def #{method} *args, &block
|
100
|
-
#{old_method} *ArgumentsParser.parse_arguments_for(:#{method}, *args), &block
|
101
|
-
end
|
102
|
-
END
|
103
|
-
class_eval code, __FILE__, __LINE__
|
104
|
-
end
|
105
|
-
end
|