ruby_ext 0.4.11 → 0.4.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/Rakefile +6 -6
  2. data/lib/rake_ext.rb +10 -5
  3. data/lib/rake_ext/project.rb +31 -16
  4. data/lib/rspec_ext.rb +82 -19
  5. data/lib/ruby_ext.rb +1 -52
  6. data/lib/ruby_ext/core.rb +24 -0
  7. data/lib/ruby_ext/{array.rb → core/array.rb} +4 -2
  8. data/lib/ruby_ext/core/basic_object.rb +8 -0
  9. data/lib/ruby_ext/core/class.rb +0 -0
  10. data/lib/ruby_ext/{deep_clone.rb → core/deep_clone.rb} +3 -4
  11. data/lib/ruby_ext/core/enumerable.rb +17 -0
  12. data/lib/ruby_ext/{file.rb → core/file.rb} +5 -2
  13. data/lib/ruby_ext/core/hash.rb +23 -0
  14. data/lib/ruby_ext/{kernel.rb → core/kernel.rb} +0 -0
  15. data/lib/ruby_ext/{micelaneous.rb → core/micelaneous.rb} +0 -0
  16. data/lib/ruby_ext/{module.rb → core/module.rb} +13 -2
  17. data/lib/ruby_ext/{multiple_inheritance.rb → core/multiple_inheritance.rb} +30 -14
  18. data/lib/ruby_ext/{must.rb → core/must.rb} +30 -27
  19. data/lib/ruby_ext/{not_defined.rb → core/not_defined.rb} +0 -0
  20. data/lib/ruby_ext/{object.rb → core/object.rb} +0 -0
  21. data/lib/ruby_ext/{open_object.rb → core/open_object.rb} +21 -16
  22. data/lib/ruby_ext/{string.rb → core/string.rb} +27 -0
  23. data/lib/ruby_ext/{symbol.rb → core/symbol.rb} +0 -0
  24. data/lib/ruby_ext/fixes.rb +6 -0
  25. data/lib/ruby_ext/gems.rb +0 -1
  26. data/lib/ruby_ext/more.rb +11 -0
  27. data/lib/ruby_ext/more/declarative_cache.rb +96 -0
  28. data/lib/ruby_ext/more/micelaneous.rb +7 -0
  29. data/lib/ruby_ext/{observable2.rb → more/observable2.rb} +0 -0
  30. data/lib/ruby_ext/{open_constructor.rb → more/open_constructor.rb} +2 -2
  31. data/lib/ruby_ext/more/safe_hash.rb +214 -0
  32. data/lib/ruby_ext/{synchronize.rb → more/synchronize.rb} +5 -5
  33. data/lib/ruby_ext/{tuple.rb → more/tuple.rb} +0 -0
  34. data/lib/yaml_fix.rb +9 -0
  35. data/readme.md +46 -42
  36. data/spec/core/array_spec.rb +7 -0
  37. data/spec/{deep_clone_spec.rb → core/deep_clone_spec.rb} +2 -3
  38. data/spec/core/enumerable.rb +9 -0
  39. data/spec/{kernel_spec.rb → core/kernel_spec.rb} +4 -6
  40. data/spec/{kernel_spec → core/kernel_spec}/TheNamespace/ClassA.rb +0 -0
  41. data/spec/{kernel_spec → core/kernel_spec}/another_class.rb +0 -0
  42. data/spec/{kernel_spec → core/kernel_spec}/the_namespace/class_b.rb +0 -0
  43. data/spec/{module_spec.rb → core/module_spec.rb} +2 -4
  44. data/spec/{multiple_inheritance_spec.rb → core/multiple_inheritance_spec.rb} +28 -12
  45. data/spec/core/must_spec.rb +32 -0
  46. data/spec/{open_object_spec.rb → core/open_object_spec.rb} +6 -7
  47. data/spec/core/spec_helper.rb +2 -0
  48. data/spec/{declarative_cache_spec.rb → more/declarative_cache_spec.rb} +35 -8
  49. data/spec/{observable2_spec.rb → more/observable2_spec.rb} +3 -4
  50. data/spec/{open_constructor_spec.rb → more/open_constructor_spec.rb} +6 -7
  51. data/spec/more/safe_hash_spec.rb +133 -0
  52. data/spec/more/spec_helper.rb +2 -0
  53. data/spec/{synchronize_spec.rb → more/synchronize_spec.rb} +2 -3
  54. metadata +67 -100
  55. data/lib/ruby_ext/basic_object.rb +0 -22
  56. data/lib/ruby_ext/class.rb +0 -11
  57. data/lib/ruby_ext/declarative_cache.rb +0 -85
  58. data/lib/ruby_ext/extra_blank_slate.rb +0 -17
  59. data/lib/ruby_ext/hash.rb +0 -15
  60. data/lib/ruby_ext/prepare_arguments.rb +0 -105
  61. data/lib/ruby_ext/prototype_inheritance.rb +0 -110
  62. data/lib/ruby_ext/should.rb +0 -166
  63. data/lib/rubyopt.rb +0 -7
  64. data/spec/_prototype_inheritance_spec.rb +0 -190
  65. data/spec/array_spec.rb +0 -8
  66. data/spec/must_spec.rb +0 -29
  67. data/spec/prepare_arguments_spec.rb +0 -46
  68. data/spec/should_spec.rb +0 -24
  69. data/spec/spec_helper.rb +0 -19
@@ -1,110 +0,0 @@
1
- #
2
- # Fix for ruby's broken include.
3
- # Included modules doesn't propagated to it's children.
4
- #
5
- # Test case:
6
- # module A; end
7
- # module B
8
- # include A
9
- # end
10
- #
11
- # module Plugin; end
12
- # A.send(:include, Plugin)
13
- #
14
- # p "Ancestors of A: " + A.ancestors.join(', ') # => "Ancestors of A: A, Plugin"
15
- # p "Ancestors of B: " + B.ancestors.join(', ') # => "Ancestors of B: B, A" << NO PLUGIN!
16
- #
17
- class Module
18
- def directly_included_by
19
- @directly_included_by ||= Set.new
20
- end
21
-
22
- def fixed_include mod
23
- unless mod.directly_included_by.include? self
24
- mod.directly_included_by.add self
25
- end
26
-
27
- include mod
28
- directly_included_by.each do |child|
29
- child.fixed_include self
30
- end
31
- end
32
- end
33
-
34
-
35
- #
36
- # Prototypes
37
- #
38
- class Class
39
- def prototype
40
- unless @prototype
41
- unless const_defined? :Prototype
42
- class_eval "module Prototype; end", __FILE__, __LINE__
43
- end
44
- @prototype = const_get :Prototype
45
-
46
- fixed_include @prototype
47
- end
48
- @prototype
49
- end
50
-
51
- def class_prototype
52
- unless @class_prototype
53
- unless const_defined? :ClassPrototype
54
- class_eval "module ClassPrototype; end", __FILE__, __LINE__
55
- end
56
- @class_prototype = const_get :ClassPrototype
57
-
58
- (class << self; self end).fixed_include @class_prototype
59
- end
60
- @class_prototype
61
- end
62
- end
63
-
64
-
65
- #
66
- # Inheritance logic
67
- #
68
- class Class
69
- def define_instance_methods &block
70
- prototype.class_eval &block
71
- # self.include prototype
72
- end
73
-
74
- def define_class_methods &block
75
- self.class_prototype.class_eval &block
76
- # self.extend self.class.prototype
77
- end
78
-
79
- def inherit *classes
80
- classes.each do |klass|
81
- raise "You can inherit classes only ('#{klass}')!" unless klass.class == Class
82
-
83
- prototype.fixed_include klass.prototype
84
- # self.include prototype
85
-
86
- class_prototype.fixed_include klass.class_prototype
87
- # (class << self; self end).include class_prototype
88
-
89
- # callback
90
- klass.inherited self if klass.respond_to? :inherited
91
- end
92
- end
93
- end
94
-
95
-
96
- #
97
- # Sugar
98
- #
99
- Class.class_eval do
100
- alias_method :instance_methods_without_prototype, :instance_methods
101
- def instance_methods *args, &block
102
- if block
103
- define_instance_methods &block
104
- else
105
- instance_methods_without_prototype
106
- end
107
- end
108
-
109
- alias_method :class_methods, :define_class_methods
110
- end
@@ -1,166 +0,0 @@
1
- class AssertionError < StandardError; end
2
-
3
- Object.class_eval do
4
- def should_be! method
5
- unless self.send("#{method}?") == true
6
- raise AssertionError, "
7
- ASSERTION FAILED (#{caller[0]}):
8
- #{self.inspect} should be #{method}
9
- ", caller
10
- end
11
-
12
- return self
13
- end
14
- alias_method :should_have!, :should_be!
15
-
16
- def should_not_be! method
17
- unless self.send("#{method}?") == false
18
- raise AssertionError, "
19
- ASSERTION FAILED (#{caller[0]}):
20
- #{self.inspect} should not be #{method}
21
- ", caller
22
- end
23
-
24
- return self
25
- end
26
- alias_method :should_not_have!, :should_not_be!
27
-
28
- def should! cmd, arg = NotDefined
29
- result = case cmd
30
- when :be_never_called then
31
- false
32
-
33
- when :be_nil then
34
- self.equal? nil
35
-
36
- when :be_a
37
- if arg.class == Array
38
- arg.any?{|klass| self.is_a? klass}
39
- else
40
- self.is_a? arg
41
- end
42
-
43
- when :be_an
44
- if arg.class == Array
45
- arg.any?{|klass| self.is_a? klass}
46
- else
47
- self.is_a? arg
48
- end
49
-
50
- when :be
51
- if arg.class == Array
52
- arg.any?{|klass| self.respond_to :is?, klass}
53
- else
54
- self.respond_to :is?, arg
55
- end
56
-
57
- when :include then
58
- self.include? arg
59
-
60
- when :be_in then
61
- arg.include? self
62
-
63
- when :be_true then
64
- self
65
-
66
- when :be_false then
67
- !self
68
-
69
- when :be_empty then
70
- self.empty?
71
-
72
- else
73
- if arg.equal? NotDefined
74
- self.send cmd
75
- else
76
- self.send cmd, arg
77
- end
78
- end
79
-
80
- unless result
81
- unless arg.equal? NotDefined
82
- raise AssertionError, "
83
- ASSERTION FAILED (#{caller[0]}):
84
- #{self.inspect} should #{cmd} #{arg.inspect}
85
- ", caller
86
- else
87
- raise AssertionError, "
88
- ASSERTION FAILED (#{caller[0]}):
89
- #{self.inspect} should #{cmd}
90
- ", caller
91
- end
92
- end
93
-
94
- return self
95
- end
96
-
97
- def should_not! cmd, arg = NotDefined
98
- result =
99
- case cmd
100
- when :be_never_called then
101
- false
102
-
103
- when :be_nil then
104
- self.equal? nil
105
-
106
- when :be_a
107
- if arg.class == Array
108
- arg.any?{|klass| self.is_a? klass}
109
- else
110
- self.is_a? arg
111
- end
112
-
113
- when :be_an
114
- if arg.class == Array
115
- arg.any?{|klass| self.is_a? klass}
116
- else
117
- self.is_a? arg
118
- end
119
-
120
- when :be
121
- if arg.class == Array
122
- arg.any?{|klass| self.respond_to :is?, klass}
123
- else
124
- self.respond_to :is?, arg
125
- end
126
-
127
- when :include then
128
- self.include? arg
129
-
130
- when :be_in then
131
- arg.include? self
132
-
133
- when :be_true then
134
- self
135
-
136
- when :be_false then
137
- !self
138
-
139
- when :be_empty then
140
- self.empty?
141
-
142
- else
143
- if arg.equal? NotDefined
144
- self.send cmd
145
- else
146
- self.send cmd, arg
147
- end
148
- end
149
-
150
- if result
151
- unless arg.equal? NotDefined
152
- raise AssertionError, "
153
- ASSERTION FAILED (#{caller[0]}):
154
- #{self.inspect} should not #{cmd} #{arg.inspect}
155
- ", caller
156
- else
157
- raise AssertionError, "
158
- ASSERTION FAILED (#{caller[0]}):
159
- #{self.inspect} should not #{cmd}
160
- ", caller
161
- end
162
- end
163
-
164
- return self
165
- end
166
- end
data/lib/rubyopt.rb DELETED
@@ -1,7 +0,0 @@
1
- unless defined?(JRuby)
2
- begin
3
- gem 'rush'
4
- autoload :Rush, 'rush'
5
- rescue Exception
6
- end
7
- end
@@ -1,190 +0,0 @@
1
- require "#{File.dirname __FILE__}/helper"
2
- require "ruby_ext/prototype_inheritance"
3
-
4
- describe "Prototype Inheritance" do
5
- after :each do
6
- remove_constants %w(A B C)
7
- end
8
-
9
- it "should define and override methods" do
10
- class A
11
- instance_methods do
12
- def instance_method
13
- 'first version'
14
- end
15
- end
16
- class_methods do
17
- def class_method
18
- 'first version'
19
- end
20
- end
21
- end
22
-
23
- A.new.instance_method.should == "first version"
24
- A.class_method.should == "first version"
25
-
26
-
27
- A.instance_methods do
28
- def instance_method
29
- 'second version'
30
- end
31
- end
32
-
33
- A.class_methods do
34
- def class_method
35
- 'second version'
36
- end
37
- end
38
-
39
- A.new.instance_method.should == "second version"
40
- A.class_method.should == "second version"
41
- end
42
-
43
- it "showcase" do
44
- class A
45
- instance_methods do
46
- def a; end
47
-
48
- def overrided_method
49
- 'a version'
50
- end
51
- end
52
-
53
- class_methods do
54
- def class_a; end
55
- end
56
-
57
- def self.inherited target
58
- target.prototype.send :attr_accessor, :some_accessor
59
- end
60
- end
61
-
62
- class B
63
- instance_methods do
64
- def b; end
65
-
66
- def overrided_method
67
- 'b version'
68
- end
69
- end
70
-
71
- class_methods do
72
- def class_b; end
73
- end
74
- end
75
-
76
- class C
77
- inherit A, B
78
- end
79
-
80
- c = C.new
81
- c.should respond_to(:a)
82
- c.should respond_to(:b)
83
- c.should respond_to(:some_accessor)
84
-
85
- C.should respond_to(:class_a)
86
- C.should respond_to(:class_b)
87
- end
88
-
89
- it "should inherit all ancestors class methods (and take order into account by overriding)" do
90
- class A
91
- instance_methods do
92
- def a; end
93
-
94
- def overrided
95
- 'a'
96
- end
97
- end
98
-
99
- class_methods do
100
- def class_a; end
101
- end
102
- end
103
-
104
- class B
105
- inherit A
106
-
107
- instance_methods do
108
- def b; end
109
-
110
- def overrided
111
- 'b'
112
- end
113
- end
114
-
115
- class_methods do
116
- def class_b; end
117
- end
118
- end
119
-
120
- class C
121
- inherit B
122
- end
123
-
124
- c = C.new
125
- c.should respond_to(:a)
126
- c.should respond_to(:b)
127
- c.overrided.should == 'b'
128
-
129
- C.should respond_to(:class_a)
130
- C.should respond_to(:class_b)
131
-
132
- C.instance_methods do
133
- def overrided
134
- 'c'
135
- end
136
- end
137
- c = C.new
138
- c.overrided.should == 'c'
139
- end
140
-
141
- it "shouldn't redefine ancestors class methods (from error)" do
142
- class A
143
- class_methods do
144
- def class_method; end
145
- end
146
- end
147
-
148
- class B
149
- inherit A
150
-
151
- class_methods do
152
- def class_method2; end
153
- end
154
- end
155
-
156
- A.should_not respond_to(:class_method2)
157
- end
158
-
159
- it "methods defined on base class after inheritance must be propagated to all descendants" do
160
- class A; end
161
-
162
- class B
163
- inherit A
164
- end
165
-
166
- B.instance_methods.should_not include('method_added_after_inheritance')
167
- A.prototype.send(:define_method, :method_added_after_inheritance){}
168
- A.instance_methods.should include('method_added_after_inheritance')
169
- B.instance_methods.should include('method_added_after_inheritance')
170
- end
171
-
172
- it "classes included in base class after inheritance must be propagated to all descendants" do
173
- class A; end
174
-
175
- class B
176
- inherit A
177
- end
178
-
179
- class C
180
- instance_methods do
181
- def module_added_after_inheritance; end
182
- end
183
- end
184
-
185
- A.instance_methods.should_not include('module_added_after_inheritance')
186
- A.inherit C
187
- A.instance_methods.should include('module_added_after_inheritance')
188
- B.instance_methods.should include('module_added_after_inheritance')
189
- end
190
- end