monkey-lib 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/spec_helper.rb CHANGED
@@ -1 +1,13 @@
1
- $LOAD_PATH.unshift File.expand_path(__FILE__.sub("spec/spec_helper.rb", "lib"))
1
+ $LOAD_PATH.unshift File.expand_path(__FILE__.sub("spec/spec_helper.rb", "lib"))
2
+ require "monkey"
3
+
4
+ if ENV['BACKEND'] and not ENV['BACKEND'].empty?
5
+ puts "Using #{ENV['BACKEND']} (#{ENV['BACKEND_SETUP']} setup mode)"
6
+ case ENV['BACKEND_SETUP']
7
+ when "autodetect" then require ENV['BACKEND']
8
+ when "explicit" then Monkey.backend = ENV['BACKEND']
9
+ else
10
+ puts "Please set BACKEND_SETUP."
11
+ exit 1
12
+ end
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monkey-lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Haase
@@ -9,20 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-11 00:00:00 +01:00
12
+ date: 2009-12-18 00:00:00 +01:00
13
13
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: extlib
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
25
- description: collection of sane ruby extensions
14
+ dependencies: []
15
+
16
+ description: Making ruby extension frameworks pluggable.
26
17
  email: konstantin.mailinglists@googlemail.com
27
18
  executables: []
28
19
 
@@ -47,8 +38,6 @@ extra_rdoc_files:
47
38
  - lib/monkey/ext/object.rb
48
39
  - lib/monkey/ext/string.rb
49
40
  - lib/monkey/ext.rb
50
- - lib/monkey/string/like_pathname.rb
51
- - lib/monkey/watcher.rb
52
41
  - lib/monkey-lib.rb
53
42
  - lib/monkey.rb
54
43
  files:
@@ -71,15 +60,13 @@ files:
71
60
  - lib/monkey/ext/object.rb
72
61
  - lib/monkey/ext/string.rb
73
62
  - lib/monkey/ext.rb
74
- - lib/monkey/string/like_pathname.rb
75
- - lib/monkey/watcher.rb
76
63
  - lib/monkey-lib.rb
77
64
  - lib/monkey.rb
78
65
  - spec/monkey/engine_spec.rb
79
- - spec/monkey/hash/sub_hash_spec.rb
80
- - spec/monkey/object/backports_spec.rb
81
- - spec/monkey/object/instance_yield_spec.rb
82
- - spec/monkey/string/like_pathname_spec.rb
66
+ - spec/monkey/ext/array_spec.rb
67
+ - spec/monkey/ext/module_spec.rb
68
+ - spec/monkey/ext/object_spec.rb
69
+ - spec/monkey/ext/string_spec.rb
83
70
  - spec/spec_helper.rb
84
71
  has_rdoc: true
85
72
  homepage: http://github.com/rkh/monkey-lib
@@ -108,6 +95,6 @@ rubyforge_project:
108
95
  rubygems_version: 1.3.5
109
96
  signing_key:
110
97
  specification_version: 3
111
- summary: collection of sane ruby extensions
98
+ summary: Making ruby extension frameworks pluggable.
112
99
  test_files: []
113
100
 
@@ -1,38 +0,0 @@
1
- require "pathname"
2
- require "extlib/pathname"
3
-
4
- module Monkey
5
- module String
6
-
7
- # Adds Pathname behaviour to String.
8
- module LikePathname
9
-
10
- ::String.send :include, self
11
-
12
- Pathname.instance_methods(false).each do |m|
13
- # Syntax error in Ruby < 1.9:
14
- # define_method(m) { |*a, &b| ... }
15
- next if "".respond_to? m or m.to_s == "to_path"
16
- class_eval <<-EOS
17
- def #{m}(*a, &b)
18
- result = Pathname(self).#{m}(*a, &b)
19
- return result unless result.is_a? Pathname
20
- result.to_s
21
- end
22
- EOS
23
- end
24
-
25
- #def method_missing(meth, *args, &block)
26
- # pathname = Pathname self
27
- # return super unless pathname.respond_to? meth
28
- # result = pathname.send(meth, *args, &block)
29
- # return result.to_s if result.is_a? Pathname
30
- # result
31
- #end
32
-
33
- alias exists? exist?
34
-
35
- end
36
-
37
- end
38
- end
@@ -1,139 +0,0 @@
1
- module Monkey
2
- # NOTE: Not thread-safe!
3
- module Watcher
4
-
5
- IDENTIFIER = "@__module_detected__"
6
-
7
- class NestedMethodMissingNotHandled < ScriptError
8
- end
9
-
10
- module ObjectWatcher
11
- ::Object.extend self
12
-
13
- def inherited(klass)
14
- Monkey::Watcher.module_defined(klass)
15
- super
16
- end
17
-
18
- end
19
-
20
- module MethodWatcher
21
- ::Module.send :include, self
22
-
23
- def method_added(name)
24
- Monkey::Watcher.method_defined(self, name)
25
- super
26
- end
27
-
28
- def method_missing(name, *args, &block)
29
- if Monkey::Watcher.detected? self
30
- begin
31
- Monkey::Watcher.module_method_missing(self, *args, &block)
32
- rescue Monkey::Watcher::NestedMethodMissingNotHandled
33
- super
34
- end
35
- else
36
- Monkey::Watcher.module_defined self
37
- if Monkey::Watcher.detected? self
38
- __send__(name, *args, &block)
39
- else
40
- super
41
- end
42
- end
43
- end
44
-
45
- end
46
-
47
- module ModuleWatcher
48
- ::Module.extend self
49
-
50
- def new(*what, &ever)
51
- super.tap { |k| Monkey::Watcher.module_defined(klass) }
52
- end
53
-
54
- end
55
-
56
- module NamelessModuleWatcher
57
-
58
- def __watcher_initialize__
59
- @__original_methods__ = {}
60
- if respond_to? :set_name_if_necessary
61
- __watcher_wrap_method__ "set_name_if_necessary"
62
- else
63
- methods.each do |name|
64
- name = name.to_s
65
- next if name =~ /^__/
66
- __watcher_wrap_method__ name
67
- end
68
- end
69
- define_singleton_method("method_addded") do |name|
70
- __watcher_wrap_method__ name unless Monkey::Watcher.detected? self
71
- super
72
- end
73
- end
74
-
75
- def __watcher_wrap_method__(name)
76
- @__original_methods__[name] = method(name)
77
- eval "def self.#{name}(*a, &b); __watcher_wrap_call__(#{name.inspect}, *a, &b); end"
78
- end
79
-
80
- def __watcher_wrap_call__(meth, *args, &block)
81
- Monkey::Watcher.module_defined(klass)
82
- @__original_methods__[meth].call(*args, &block).tap do
83
- next if name.blank?
84
- Monkey::Watcher.module_defined(klass)
85
- methods_names = @__original_methods__.keys
86
- methods_names.each { |m| define_singleton_method(m, &@__original_methods__.delete(m)) }
87
- undef __watcher_initialize__
88
- undef __watcher_wrap_method__
89
- undef __watcher_wrap_call__
90
- end
91
- end
92
-
93
- def self.extended(klass)
94
- klass.__watcher_initialize__
95
- super
96
- end
97
-
98
- end
99
-
100
- def self.module_defined(klass)
101
- return if detected? klass
102
- return nameless_module_defined(klass) unless klass.name
103
- klass.instance_variable_set IDENTIFIER, true
104
- klass.parent.module_added(klass)
105
- klass.constants.each do |name|
106
- mod = klass.const_get name
107
- module_defined mod if mod.is_a? Module
108
- end
109
- end
110
-
111
- def self.nameless_module_defined(klass)
112
- return if hooked? klass
113
- klass.instance_variable_set IDENTIFIER, false
114
- klass.extend NamelessModuleWatcher
115
- end
116
-
117
- def self.method_defined(klass, name)
118
- module_defined(klass)
119
- end
120
-
121
- def self.hooked?(klass)
122
- klass.instance_variable_defined? IDENTIFIER
123
- end
124
-
125
- def self.detected?(klass)
126
- !!klass.instance_variable_get IDENTIFIER
127
- end
128
-
129
- def self.setup
130
- begin
131
- ObjectSpace.each_object(Module) { |klass| module_defined(klass) }
132
- rescue Exception
133
- # Thus we meet at last, JRuby!
134
- module_defined Object
135
- end
136
- end
137
-
138
- end
139
- end
@@ -1,15 +0,0 @@
1
- require __FILE__.sub("monkey/hash/sub_hash_spec.rb", "spec_helper")
2
- require "monkey/hash/sub_hash"
3
-
4
- describe Monkey::Hash::SubHash do
5
-
6
- it "returns a hash with only the key-value-pairs requested for sub_hash" do
7
- {:a => 10, :b => 20}.sub_hash(:a).should == {:a => 10}
8
- {:a => 10, :b => 20}.sub_hash(:a, :b).should == {:a => 10, :b => 20}
9
- end
10
-
11
- it "should ignore keys passed to sub_hash, but not present" do
12
- {:a => 10, :b => 20}.sub_hash(:a, :c).should == {:a => 10}
13
- end
14
-
15
- end
@@ -1,24 +0,0 @@
1
- require __FILE__.sub("monkey/object/backports_spec.rb", "spec_helper")
2
- require "monkey/object/backports"
3
-
4
- describe Monkey::Object::Backports do
5
-
6
- it "returns returns the reciever of #tap" do
7
- obj = Object.new
8
- obj.tap {}.should == obj
9
- "example".tap {}.should == "example"
10
- end
11
-
12
- it "passes the reciever of #tap to the given block" do
13
- "foo".tap { |s| s.replace "bar" }.should == "bar"
14
- end
15
-
16
- it "returns eigenclass for #metaclass" do
17
- obj = Object.new
18
- eigenclass = class << obj
19
- self
20
- end
21
- obj.metaclass.should == eigenclass
22
- end
23
-
24
- end
@@ -1,32 +0,0 @@
1
- require __FILE__.sub("monkey/object/instance_yield_spec.rb", "spec_helper")
2
- require "monkey/object/instance_yield"
3
-
4
- describe Monkey::Object::InstanceYield do
5
-
6
- before do
7
- @obj = Object.new
8
- @obj.stub! :foo
9
- end
10
-
11
- it "calls a block if block takes at least one argument" do
12
- foo = nil
13
- @obj.should_not_receive :foo
14
- @obj.send :instance_yield do |x|
15
- foo
16
- end
17
- end
18
-
19
- it "passes object as first argument to blog" do
20
- @obj.send :instance_yield do |x|
21
- x.should == @obj
22
- end
23
- end
24
-
25
- it "passes the block to instance_eval if block doesn't take arguments" do
26
- @obj.should_receive :foo
27
- @obj.send :instance_yield do
28
- foo
29
- end
30
- end
31
-
32
- end
@@ -1,272 +0,0 @@
1
- require __FILE__.sub("monkey/string/like_pathname_spec.rb", "spec_helper")
2
- require "monkey/string/like_pathname"
3
-
4
- describe Monkey::String::LikePathname do
5
-
6
- before do
7
- @strings = ["/usr/bin/ruby", ".", "..", ENV["HOME"]]
8
- @methods = Pathname.instance_methods(false).reject do |m|
9
- String.methods.include? m or m.to_s == "to_path"
10
- end
11
- end
12
-
13
- it "exposes sub_ext to String if in ruby 1.9" do
14
- @strings.each do |s|
15
- s.sub_ext(".png").should == Pathname(s).sub_ext(".png").to_s
16
- end if RUBY_VERSION >= "1.9"
17
- end
18
-
19
- it "exposes cleanpath to String" do
20
- @strings.each do |s|
21
- s.cleanpath.should == Pathname(s).cleanpath.to_s
22
- end
23
- end
24
-
25
- it "exposes realpath to String" do
26
- @strings.each do |s|
27
- s.realpath.should == Pathname(s).realpath.to_s
28
- end
29
- end
30
-
31
- it "exposes parent to String" do
32
- @strings.each do |s|
33
- s.parent.should == Pathname(s).parent.to_s
34
- end
35
- end
36
-
37
- it "exposes mountpoint? to String" do
38
- @strings.each do |s|
39
- s.mountpoint?.should == Pathname(s).mountpoint?
40
- end
41
- end
42
-
43
- it "exposes root? to String" do
44
- @strings.each do |s|
45
- s.root?.should == Pathname(s).root?
46
- end
47
- end
48
-
49
- it "exposes absolute? to String" do
50
- @strings.each do |s|
51
- s.absolute?.should == Pathname(s).absolute?
52
- end
53
- end
54
-
55
- it "exposes relative? to String" do
56
- @strings.each do |s|
57
- s.relative?.should == Pathname(s).relative?
58
- end
59
- end
60
-
61
- it "exposes each_filename to String if in ruby 1.9" do
62
- @strings.each do |s|
63
- s.each_filename.to_a.should == Pathname(s).each_filename.to_a
64
- end if RUBY_VERSION >= "1.9"
65
- end
66
-
67
- it "exposes join to String" do
68
- @strings.each do |s|
69
- s.join.should == Pathname(s).join.to_s
70
- end
71
- end
72
-
73
- it "exposes children to String" do
74
- @strings.each do |s|
75
- s.children.should == Pathname(s).children if s.directory?
76
- end
77
- end
78
-
79
- it "exposes atime to String" do
80
- @strings.each do |s|
81
- s.atime.should == Pathname(s).atime
82
- end
83
- end
84
-
85
- it "exposes ctime to String" do
86
- @strings.each do |s|
87
- s.ctime.should == Pathname(s).ctime
88
- end
89
- end
90
-
91
- it "exposes mtime to String" do
92
- @strings.each do |s|
93
- s.mtime.should == Pathname(s).mtime
94
- end
95
- end
96
-
97
- it "exposes ftype to String" do
98
- @strings.each do |s|
99
- s.ftype.should == Pathname(s).ftype.to_s
100
- end
101
- end
102
-
103
- it "exposes basename to String" do
104
- @strings.each do |s|
105
- s.basename.should == Pathname(s).basename.to_s
106
- end
107
- end
108
-
109
- it "exposes dirname to String" do
110
- @strings.each do |s|
111
- s.dirname.should == Pathname(s).dirname.to_s
112
- end
113
- end
114
-
115
- it "exposes extname to String" do
116
- @strings.each do |s|
117
- s.extname.should == Pathname(s).extname.to_s
118
- end
119
- end
120
-
121
- it "exposes expand_path to String" do
122
- @strings.each do |s|
123
- s.expand_path.should == Pathname(s).expand_path.to_s
124
- end
125
- end
126
-
127
- it "exposes blockdev? to String" do
128
- @strings.each do |s|
129
- s.blockdev?.should == Pathname(s).blockdev?
130
- end
131
- end
132
-
133
- it "exposes chardev? to String" do
134
- @strings.each do |s|
135
- s.chardev?.should == Pathname(s).chardev?
136
- end
137
- end
138
-
139
- it "exposes executable? to String" do
140
- @strings.each do |s|
141
- s.executable?.should == Pathname(s).executable?
142
- end
143
- end
144
-
145
- it "exposes executable_real? to String" do
146
- @strings.each do |s|
147
- s.executable_real?.should == Pathname(s).executable_real?
148
- end
149
- end
150
-
151
- it "exposes exist? to String" do
152
- @strings.each do |s|
153
- s.exist?.should == Pathname(s).exist?
154
- s.exists?.should == Pathname(s).exist?
155
- end
156
- end
157
-
158
- it "exposes grpowned? to String" do
159
- @strings.each do |s|
160
- s.grpowned?.should == Pathname(s).grpowned?
161
- end
162
- end
163
-
164
- it "exposes directory? to String" do
165
- @strings.each do |s|
166
- s.directory?.should == Pathname(s).directory?
167
- end
168
- end
169
-
170
- it "exposes file? to String" do
171
- @strings.each do |s|
172
- s.file?.should == Pathname(s).file?
173
- end
174
- end
175
-
176
- it "exposes pipe? to String" do
177
- @strings.each do |s|
178
- s.pipe?.should == Pathname(s).pipe?
179
- end
180
- end
181
-
182
- it "exposes socket? to String" do
183
- @strings.each do |s|
184
- s.socket?.should == Pathname(s).socket?
185
- end
186
- end
187
-
188
- it "exposes owned? to String" do
189
- @strings.each do |s|
190
- s.owned?.should == Pathname(s).owned?
191
- end
192
- end
193
-
194
- it "exposes readable? to String" do
195
- @strings.each do |s|
196
- s.readable?.should == Pathname(s).readable?
197
- end
198
- end
199
-
200
- it "exposes world_readable? to String in ruby 1.9" do
201
- @strings.each do |s|
202
- s.world_readable?.should == Pathname(s).world_readable?
203
- end if RUBY_VERSION >= "1.9"
204
- end
205
-
206
- it "exposes readable_real? to String" do
207
- @strings.each do |s|
208
- s.readable_real?.should == Pathname(s).readable_real?
209
- end
210
- end
211
-
212
- it "exposes setuid? to String" do
213
- @strings.each do |s|
214
- s.setuid?.should == Pathname(s).setuid?
215
- end
216
- end
217
-
218
- it "exposes setgid? to String" do
219
- @strings.each do |s|
220
- s.setgid?.should == Pathname(s).setgid?
221
- end
222
- end
223
-
224
- it "exposes size? to String" do
225
- @strings.each do |s|
226
- s.size?.should == Pathname(s).size?
227
- end
228
- end
229
-
230
- it "exposes sticky? to String" do
231
- @strings.each do |s|
232
- s.sticky?.should == Pathname(s).sticky?
233
- end
234
- end
235
-
236
- it "exposes symlink? to String" do
237
- @strings.each do |s|
238
- s.symlink?.should == Pathname(s).symlink?
239
- end
240
- end
241
-
242
- it "exposes writable? to String" do
243
- @strings.each do |s|
244
- s.writable?.should == Pathname(s).writable?
245
- end
246
- end
247
-
248
- it "exposes world_writable? to String in ruby 1.9" do
249
- @strings.each do |s|
250
- s.world_writable?.should == Pathname(s).world_writable?
251
- end if RUBY_VERSION >= "1.9"
252
- end
253
-
254
- it "exposes writable_real? to String" do
255
- @strings.each do |s|
256
- s.writable_real?.should == Pathname(s).writable_real?
257
- end
258
- end
259
-
260
- it "exposes zero? to String" do
261
- @strings.each do |s|
262
- s.zero?.should == Pathname(s).zero?
263
- end
264
- end
265
-
266
- it "exposes entries to String in ruby 1.9" do
267
- @strings.each do |s|
268
- s.entries.should == Pathname(s).entries if s.directory?
269
- end if RUBY_VERSION >= "1.9"
270
- end
271
-
272
- end