monkey-lib 0.4.0.a → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +8 -8
- data/Rakefile +3 -3
- data/lib/monkey.rb +46 -5
- data/lib/monkey/autoloader.rb +4 -5
- data/lib/monkey/backend.rb +34 -6
- data/lib/monkey/backend/active_support.rb +13 -3
- data/lib/monkey/backend/backports.rb +2 -2
- data/lib/monkey/backend/common/parent.rb +1 -1
- data/lib/monkey/backend/common/{metaclass.rb → singleton_class.rb} +2 -2
- data/lib/monkey/backend/extlib.rb +2 -2
- data/lib/monkey/backend/facets.rb +4 -1
- data/lib/monkey/ext.rb +27 -18
- data/lib/monkey/ext/module.rb +21 -1
- data/lib/monkey/ext/object.rb +21 -9
- data/lib/monkey/ext/pathname.rb +1 -1
- data/lib/monkey/hash_fix.rb +2 -0
- data/spec/monkey/backend_spec.rb +7 -0
- data/spec/monkey/ext/module_spec.rb +17 -1
- data/spec/monkey/ext/object_spec.rb +3 -3
- data/spec/monkey/ext_spec.rb +50 -0
- data/spec/monkey_spec.rb +25 -0
- data/spec/spec_helper.rb +12 -5
- metadata +34 -12
- data/spec/monkey/version_spec.rb +0 -0
data/README.rdoc
CHANGED
@@ -9,20 +9,20 @@ Version number will soon be synchronized with BigBand.
|
|
9
9
|
|
10
10
|
== Backends
|
11
11
|
Those libraries are supported as backends out of the box:
|
12
|
-
* ActiveSupport (tested with 2.3.2 to 3.0.
|
13
|
-
* Backports (tested with 1.11.1 to 1.
|
12
|
+
* ActiveSupport (tested with 2.3.2 to 3.0.beta)
|
13
|
+
* Backports (tested with 1.11.1 to 1.15.0, >= 1.13.1 required for Rubinius)
|
14
14
|
* Extlib (tested with 0.9.13 and 0.9.14)
|
15
|
-
* Facets (tested with 2.8.0
|
15
|
+
* Facets (tested with 2.8.0 to 2.8.2)
|
16
16
|
|
17
17
|
== Ruby versions
|
18
18
|
MonkeyLib has been tested and is known to work with the following Ruby implementations:
|
19
19
|
|
20
|
-
* Ruby (MRI) 1.8.6, 1.8.7, 1.9.1, 1.9.2-preview1
|
20
|
+
* Ruby (MRI) 1.8.6, 1.8.7, 1.9.1, 1.9.2-preview1, also tested with trunk on regular basis
|
21
21
|
* Ruby Enterprise Edition 2009.10, 2010.01
|
22
|
-
* Rubinius 1.0.0-rc2
|
22
|
+
* Rubinius 1.0.0-rc2 to 1.0.0-rc4, also tested with master branch on regular basis
|
23
23
|
* JRuby 1.3.1, 1.4.0
|
24
|
-
* MagLev 22780
|
25
|
-
* IronRuby 0.9.3 (only Extlib and Backports)
|
24
|
+
* MagLev 22780 to 23191 (Backports backend recommended, but all expectations pass on all backends)
|
25
|
+
* IronRuby 0.9.3, 1.0-rc2 (only Extlib and Backports)
|
26
26
|
|
27
27
|
Currently it does *not* run on MacRuby, but I'm working on it.
|
28
28
|
|
@@ -38,7 +38,7 @@ Run specs with backports and using mspec instead of rspec (so it might work on i
|
|
38
38
|
SPEC_RUNNER=mspec rake spec:backports
|
39
39
|
|
40
40
|
Sometimes there are issues with running rake from the ruby implementation (maybe rake is not fully supported, or the backend detection messes
|
41
|
-
with your ruby). You can use one ruby implementation to run the specs on another one.
|
41
|
+
with your ruby). You can use one ruby implementation to run the specs on another one. For instance, I use rvm to manage my rubies:
|
42
42
|
|
43
43
|
rvm install macruby-0.5
|
44
44
|
rvm use macruby-0.5
|
data/Rakefile
CHANGED
@@ -13,7 +13,7 @@ setup_rspec = proc do
|
|
13
13
|
SPEC_RUNNER = "mspec"
|
14
14
|
def define_spec_task(name, ruby_cmd, pattern)
|
15
15
|
Spec::Rake::SpecTask.new name do |t|
|
16
|
-
t.spec_opts
|
16
|
+
t.spec_opts += %w[-b -c --format progress --loadby mtime --reverse]
|
17
17
|
t.ruby_cmd = ruby_cmd
|
18
18
|
t.pattern = pattern
|
19
19
|
end
|
@@ -49,10 +49,10 @@ end
|
|
49
49
|
def spec_task(name, backend = nil, mode = nil)
|
50
50
|
desc "runs specs #{"with backend #{backend} " if backend}#{"(#{mode} mode)" if mode}"
|
51
51
|
if backend_available? backend
|
52
|
-
define_spec_task(name, "BACKEND=#{backend.to_s.inspect} BACKEND_SETUP=#{mode.to_s.inspect} #{ENV['RUBY'] || RUBY}", "spec
|
52
|
+
define_spec_task(name, "BACKEND=#{backend.to_s.inspect} BACKEND_SETUP=#{mode.to_s.inspect} #{ENV['RUBY'] || RUBY}", "spec/**/*_spec.rb")
|
53
53
|
else
|
54
54
|
task(name) do
|
55
|
-
puts "", "could not load #{backend.inspect}, skipping specs."
|
55
|
+
puts "", "could not load #{backend.inspect}, skipping specs.", ""
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
data/lib/monkey.rb
CHANGED
@@ -1,10 +1,5 @@
|
|
1
1
|
module Monkey
|
2
2
|
|
3
|
-
Dir[File.dirname(__FILE__) + "/monkey/*.rb"].sort.each do |path|
|
4
|
-
filename = File.basename(path, '.rb')
|
5
|
-
require "monkey/#{filename}"
|
6
|
-
end
|
7
|
-
|
8
3
|
def self.backend=(backend)
|
9
4
|
Backend.setup! backend
|
10
5
|
backend
|
@@ -14,4 +9,50 @@ module Monkey
|
|
14
9
|
Backend.backend
|
15
10
|
end
|
16
11
|
|
12
|
+
def self.invisible(*from)
|
13
|
+
yield
|
14
|
+
rescue Exception => error
|
15
|
+
unless show_invisibles?
|
16
|
+
from << caller.first[/^[^:]*/] if from.empty?
|
17
|
+
from << __FILE__
|
18
|
+
delete_from_backtrace(error) { |l| from.any? { |f| l.include? f } }
|
19
|
+
end
|
20
|
+
raise error
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.show_invisibles?
|
24
|
+
!!@show_invisibles
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.show_invisibles!(show = true)
|
28
|
+
return @show_invisibles = show unless block_given?
|
29
|
+
# actually, that is not thread-safe. but that's no issue, as
|
30
|
+
# it is quite unlikely and does not cause any harm.
|
31
|
+
show_invisibles_was, @show_invisibles = @show_invisibles, show
|
32
|
+
result = yield
|
33
|
+
@show_invisibles = show_invisibles_was
|
34
|
+
result
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.hide_invisibles!(&block)
|
38
|
+
show_invisibles!(false, &block)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.delete_from_backtrace(error, &block)
|
42
|
+
if error.respond_to? :awesome_backtrace
|
43
|
+
# HACK: we rely on the internal data structure, btw
|
44
|
+
locations = error.instance_variable_get :@locations
|
45
|
+
return unless locations
|
46
|
+
locations.reject! { |l| yield l.position }
|
47
|
+
error.instance_variable_set :@backtrace, nil
|
48
|
+
else
|
49
|
+
error.backtrace.reject!(&block)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
Dir[File.dirname(__FILE__) + "/monkey/*.rb"].sort.each do |path|
|
54
|
+
filename = File.basename(path, '.rb')
|
55
|
+
require "monkey/#{filename}"
|
56
|
+
end
|
57
|
+
|
17
58
|
end
|
data/lib/monkey/autoloader.rb
CHANGED
@@ -4,18 +4,17 @@ Module.class_eval do
|
|
4
4
|
alias const_missing_without_detection const_missing
|
5
5
|
|
6
6
|
def const_missing(const_name)
|
7
|
-
if parent.autoloader? and not is_a? Monkey::Autoloader
|
7
|
+
if respond_to? :parent and parent.autoloader? and not is_a? Monkey::Autoloader
|
8
8
|
extend Monkey::Autoloader
|
9
9
|
const_missing const_name
|
10
10
|
else
|
11
|
-
const_missing_without_detection const_name
|
11
|
+
Monkey.invisible(__FILE__) { const_missing_without_detection const_name }
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
def autoloader?
|
16
|
-
is_a? Monkey::Autoloader or (parent != self and parent.autoloader?)
|
16
|
+
is_a? Monkey::Autoloader or (respond_to? :parent and parent != self and parent.autoloader?)
|
17
17
|
end
|
18
|
-
|
19
18
|
end
|
20
19
|
|
21
20
|
module Monkey
|
@@ -35,7 +34,7 @@ module Monkey
|
|
35
34
|
end
|
36
35
|
rescue LoadError => error
|
37
36
|
begin
|
38
|
-
return parent.const_get(const_name) if parent != self
|
37
|
+
return parent.const_get(const_name) if respond_to? :parent and parent != self
|
39
38
|
rescue NameError
|
40
39
|
end
|
41
40
|
warn "tried to load #{file}: #{error.message}"
|
data/lib/monkey/backend.rb
CHANGED
@@ -11,7 +11,10 @@ module Monkey
|
|
11
11
|
attr_accessor :backend_name, :backend_path
|
12
12
|
|
13
13
|
def available?
|
14
|
-
Object.const_defined? backend_name
|
14
|
+
return true if Object.const_defined? backend_name
|
15
|
+
$LOADED_FEATURES.any? do |f|
|
16
|
+
f =~ /^(.*lib\/)?#{backend_path}|#{backend_path}(-[^\/]+)?\/lib/
|
17
|
+
end
|
15
18
|
end
|
16
19
|
|
17
20
|
def setup_complete
|
@@ -48,6 +51,27 @@ module Monkey
|
|
48
51
|
end
|
49
52
|
end
|
50
53
|
|
54
|
+
def version(default = "0")
|
55
|
+
return version(nil) || default unless default.nil?
|
56
|
+
return @version if @version
|
57
|
+
return unless defined? Gem
|
58
|
+
Gem.send :attr_accessor, :loaded_specs
|
59
|
+
return unless Gem.loaded_specs.respond_to? :[]
|
60
|
+
@version = Gem.loaded_specs[gem_name].version.to_s if Gem.loaded_specs.include? gem_name
|
61
|
+
end
|
62
|
+
|
63
|
+
def version!
|
64
|
+
version(nil) or raise RuntimeError, "unable to determine backend version"
|
65
|
+
end
|
66
|
+
|
67
|
+
def version?
|
68
|
+
!!version(false)
|
69
|
+
end
|
70
|
+
|
71
|
+
def gem_name
|
72
|
+
@gem_name ||= name[/[^:]*$/].downcase
|
73
|
+
end
|
74
|
+
|
51
75
|
end
|
52
76
|
|
53
77
|
def self.new(backend_name, backend_path = nil, &block)
|
@@ -56,7 +80,11 @@ module Monkey
|
|
56
80
|
backend_path ||= backend_name.to_s.downcase
|
57
81
|
mod.backend_name, mod.backend_path = backend_name.to_s, backend_path.to_s
|
58
82
|
available_backends << mod
|
59
|
-
|
83
|
+
if block
|
84
|
+
eigenclass = class << mod; self; end
|
85
|
+
eigenclass.class_eval(&block)
|
86
|
+
end
|
87
|
+
mod
|
60
88
|
end
|
61
89
|
|
62
90
|
def self.preferred_backend
|
@@ -103,10 +131,10 @@ module Monkey
|
|
103
131
|
detected
|
104
132
|
end
|
105
133
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
134
|
+
require "monkey/backend/backports"
|
135
|
+
require "monkey/backend/active_support"
|
136
|
+
require "monkey/backend/facets"
|
137
|
+
require "monkey/backend/extlib"
|
110
138
|
|
111
139
|
end
|
112
140
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
Monkey::Backend.new :ActiveSupport, :active_support do
|
2
|
-
def
|
2
|
+
def setup
|
3
3
|
load_lib :version
|
4
|
-
expects_module "::ActiveSupport::CoreExtensions::String::Inflections" if
|
4
|
+
expects_module "::ActiveSupport::CoreExtensions::String::Inflections" if version < "3"
|
5
5
|
load_libs "core_ext/object" => [:metaclass, :misc], :core_ext => %w[array/extract_options string/inflections module/introspection]
|
6
|
-
if
|
6
|
+
if version < "3"
|
7
7
|
::Array.send :include, ::ActiveSupport::CoreExtensions::Array::ExtractOptions
|
8
8
|
::Module.send :include, ::ActiveSupport::CoreExtensions::Module
|
9
9
|
end
|
@@ -11,5 +11,15 @@ Monkey::Backend.new :ActiveSupport, :active_support do
|
|
11
11
|
alias to_const_string camelcase
|
12
12
|
alias to_const_path underscore
|
13
13
|
end
|
14
|
+
::Object.class_eval do
|
15
|
+
alias singleton_class metaclass unless respond_to? :singleton_class
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def version(default = "0")
|
20
|
+
load_lib :version
|
21
|
+
@version ||= ActiveSupport::VERSION::STRING or super
|
22
|
+
rescue NameError
|
23
|
+
super
|
14
24
|
end
|
15
25
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Monkey::Backend.new :Backports do
|
2
|
-
def
|
2
|
+
def setup
|
3
3
|
load_libs "tools", "1.8.7/kernel", :rails => [:array, :string]
|
4
|
-
missing :parent, :
|
4
|
+
missing :parent, :singleton_class
|
5
5
|
::String.class_eval do
|
6
6
|
alias camelcase camelize
|
7
7
|
alias to_const_string camelize
|
@@ -1,8 +1,8 @@
|
|
1
1
|
Monkey::Backend.new :Extlib do
|
2
|
-
def
|
2
|
+
def setup
|
3
3
|
load_libs :object, :string, :inflection
|
4
4
|
missing :parent, :extract_options, :tap
|
5
|
-
::Object.class_eval { alias
|
5
|
+
::Object.class_eval { alias singleton_class meta_class }
|
6
6
|
::String.class_eval do
|
7
7
|
alias camelcase to_const_string
|
8
8
|
alias underscore to_const_path
|
@@ -1,5 +1,5 @@
|
|
1
1
|
Monkey::Backend.new :Facets do
|
2
|
-
def
|
2
|
+
def setup
|
3
3
|
load_libs :kernel => [:meta_class, :constant], :string => [:camelcase, :snakecase]
|
4
4
|
# Actually, facets has Kernel#tap, but it behaves different if the block takes no argument.
|
5
5
|
missing :tap, :extract_options, :parent
|
@@ -11,5 +11,8 @@ Monkey::Backend.new :Facets do
|
|
11
11
|
alias to_const_path snakecase
|
12
12
|
alias underscore snakecase
|
13
13
|
end
|
14
|
+
::Object.class_eval do
|
15
|
+
alias singleton_class meta_class unless respond_to? :singleton_class
|
16
|
+
end
|
14
17
|
end
|
15
18
|
end
|
data/lib/monkey/ext.rb
CHANGED
@@ -5,11 +5,20 @@ module Monkey
|
|
5
5
|
|
6
6
|
module ExtDSL
|
7
7
|
|
8
|
+
module ClassDsl
|
9
|
+
include ExtDSL
|
10
|
+
def core_class(klass = nil)
|
11
|
+
klass ? @core_class = klass : @core_class
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
8
15
|
def core_class(klass = nil)
|
9
16
|
if klass
|
10
17
|
@core_class = klass
|
11
18
|
klass.send :include, self
|
12
|
-
|
19
|
+
self::ClassMethods.extend ClassDsl
|
20
|
+
self::ClassMethods.core_class core_class
|
21
|
+
klass.extend self::ClassMethods
|
13
22
|
@core_class.class_eval <<-EOS
|
14
23
|
def method_missing(meth, *args, &blk)
|
15
24
|
return super if Monkey::Backend.setup?
|
@@ -20,22 +29,17 @@ module Monkey
|
|
20
29
|
end
|
21
30
|
return @core_class
|
22
31
|
end
|
23
|
-
|
32
|
+
|
24
33
|
def rename_core_method(old_name, new_name)
|
25
|
-
|
26
|
-
core_class.class_eval do
|
27
|
-
alias_method new_name, old_name
|
28
|
-
undef_method old_name
|
29
|
-
end
|
34
|
+
core_class.send :undef_method, alias_core_method(old_name, new_name)
|
30
35
|
end
|
31
|
-
|
32
|
-
def
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
36
|
+
|
37
|
+
def alias_core_method(old_name, new_name)
|
38
|
+
new_name = new_name % old_name if new_name.is_a? String
|
39
|
+
core_class.send :alias_method, new_name, old_name
|
40
|
+
old_name
|
37
41
|
end
|
38
|
-
|
42
|
+
|
39
43
|
def feature(name, mode = :instance, &block)
|
40
44
|
case mode
|
41
45
|
when :instance then block.call
|
@@ -46,9 +50,9 @@ module Monkey
|
|
46
50
|
else raise ArgumentError, "unkown mode #{mode.inspect}"
|
47
51
|
end
|
48
52
|
end
|
49
|
-
|
53
|
+
|
50
54
|
def class_methods(&block)
|
51
|
-
|
55
|
+
self::ClassMethods.class_eval(&block)
|
52
56
|
end
|
53
57
|
|
54
58
|
def expects(*list)
|
@@ -66,9 +70,14 @@ module Monkey
|
|
66
70
|
Dir[::File.dirname(__FILE__) + "/ext/*.rb"].sort.each do |path|
|
67
71
|
filename = ::File.basename(path, '.rb')
|
68
72
|
class_name = filename.capitalize
|
69
|
-
extension = eval
|
73
|
+
extension = eval <<-EOS
|
74
|
+
module ::Monkey::Ext::#{class_name} # <- for MacRuby!?
|
75
|
+
module ClassMethods; end # <- for 1.9
|
76
|
+
self
|
77
|
+
end
|
78
|
+
EOS
|
70
79
|
extension.extend ExtDSL
|
71
|
-
extension.core_class Object.const_get(class_name)
|
80
|
+
extension.core_class ::Object.const_get(class_name)
|
72
81
|
require "monkey/ext/#{filename}"
|
73
82
|
end
|
74
83
|
|
data/lib/monkey/ext/module.rb
CHANGED
@@ -3,6 +3,26 @@ module Monkey
|
|
3
3
|
module Module
|
4
4
|
# Defined by backend.
|
5
5
|
expects :parent
|
6
|
+
|
7
|
+
def nested_method_missing(mod, name, *args, &block)
|
8
|
+
Monkey.invisible __FILE__ do
|
9
|
+
if respond_to? :parent and parent != self
|
10
|
+
parent.send(:nested_method_missing, mod, name, *args, &block)
|
11
|
+
else
|
12
|
+
mod.send(:method_missing_without_nesting, name, *args)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def method_missing(name, *args, &block)
|
18
|
+
if respond_to? :parent and parent.respond_to? :nested_method_missing
|
19
|
+
parent.nested_method_missing(self, name, *args, &block)
|
20
|
+
else
|
21
|
+
method_missing_without_nesting(name, *args, &block)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
6
25
|
end
|
7
26
|
end
|
8
|
-
end
|
27
|
+
end
|
28
|
+
|
data/lib/monkey/ext/object.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Monkey
|
2
2
|
module Ext
|
3
3
|
module Object
|
4
|
-
|
4
|
+
|
5
5
|
# Defined by backend.
|
6
|
-
expects :
|
7
|
-
|
6
|
+
expects :singleton_class, :tap
|
7
|
+
|
8
8
|
# Behaves like instance_eval or yield depending on whether a block takes an argument or not.
|
9
9
|
#
|
10
10
|
# class Foo
|
@@ -24,15 +24,27 @@ module Monkey
|
|
24
24
|
raise LocalJumpError, "no block given (yield)" unless block
|
25
25
|
block.arity > 0 ? yield(self) : instance_eval(&block)
|
26
26
|
end
|
27
|
-
|
28
|
-
def
|
29
|
-
|
27
|
+
|
28
|
+
def singleton_class_eval(&block)
|
29
|
+
singleton_class.class_eval(&block)
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def define_singleton_method(name, &block)
|
33
|
-
|
33
|
+
singleton_class_eval { define_method(name, &block) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def metaclass
|
37
|
+
warn "DEPRECATION WARNING: #metaclass will be removed, use #singleton_class (#{caller})"
|
38
|
+
singleton_class
|
39
|
+
end
|
40
|
+
|
41
|
+
def metaclass_eval(&block)
|
42
|
+
warn "DEPRECATION WARNING: #metaclass_eval will be removed, use #singleton_class_eval (#{caller})"
|
43
|
+
singleton_class_eval(&block)
|
34
44
|
end
|
35
|
-
|
45
|
+
|
46
|
+
alias_core_method :method_missing, :method_missing_without_nesting
|
47
|
+
|
36
48
|
end
|
37
49
|
end
|
38
50
|
end
|
data/lib/monkey/ext/pathname.rb
CHANGED
@@ -2,7 +2,7 @@ module Monkey
|
|
2
2
|
module Ext
|
3
3
|
module Pathname
|
4
4
|
##
|
5
|
-
# @
|
5
|
+
# @return [Pathname, NilClass] Path with correct casing.
|
6
6
|
def cased_path
|
7
7
|
return unless exist?
|
8
8
|
return Dir.chdir(self) { Pathname(Dir.pwd) } if ::File.directory? path
|
@@ -13,4 +13,20 @@ describe Monkey::Ext::Module do
|
|
13
13
|
ExtFoo.parent.should == Monkey::Ext
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
|
+
describe "nested_method_missing" do
|
18
|
+
|
19
|
+
before do
|
20
|
+
[:Foo, :Bar, :Blah].inject(Object) do |parent, name|
|
21
|
+
parent.send :remove_const, name if parent.const_defined? name
|
22
|
+
parent.const_set name, Module.new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should call nested_method_missing on parent" do
|
27
|
+
Foo.should_receive(:nested_method_missing).once.with(Foo::Bar, :foo)
|
28
|
+
Foo::Bar.foo
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -14,9 +14,9 @@ describe Monkey::Ext::Object do
|
|
14
14
|
42.tap { 23 }.should == 42
|
15
15
|
end
|
16
16
|
|
17
|
-
# expects :
|
18
|
-
it "imports
|
19
|
-
@obj.
|
17
|
+
# expects :singleton_class
|
18
|
+
it "imports singleton_class from backend" do
|
19
|
+
@obj.singleton_class.should == (class << @obj; self; end)
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require __FILE__.sub(%r{monkey/.*$}, "spec_helper")
|
2
|
+
|
3
|
+
describe Monkey::Ext do
|
4
|
+
describe Monkey::Ext::ExtDSL do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@core_class = Class.new
|
8
|
+
@extension = Module.new
|
9
|
+
@extension::ClassMethods = Module.new
|
10
|
+
@extension.extend Monkey::Ext::ExtDSL
|
11
|
+
@extension.core_class @core_class
|
12
|
+
end
|
13
|
+
|
14
|
+
it "extends the core class" do
|
15
|
+
@core_class.ancestors.should include(@extension)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "adds methods to the core class instances" do
|
19
|
+
instance = @core_class.new
|
20
|
+
@extension.class_eval do
|
21
|
+
def foo
|
22
|
+
42
|
23
|
+
end
|
24
|
+
end
|
25
|
+
instance.foo.should == 42
|
26
|
+
end
|
27
|
+
|
28
|
+
it "adds methods to the core class" do
|
29
|
+
@extension.class_methods do
|
30
|
+
def foo
|
31
|
+
42
|
32
|
+
end
|
33
|
+
end
|
34
|
+
@core_class.foo.should == 42
|
35
|
+
end
|
36
|
+
|
37
|
+
it "is able to rename core instance methods" do
|
38
|
+
instance = @core_class.new
|
39
|
+
@core_class.class_eval do
|
40
|
+
def foo
|
41
|
+
42
|
42
|
+
end
|
43
|
+
end
|
44
|
+
@extension.rename_core_method :foo, :bar
|
45
|
+
instance.should_not respond_to(:foo)
|
46
|
+
instance.bar.should == 42
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
data/spec/monkey_spec.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require __FILE__.sub(%r{monkey_spec\.rb$}, "spec_helper")
|
2
|
+
|
3
|
+
describe Monkey do
|
4
|
+
describe :invisible do
|
5
|
+
it "removes lines from a backtrace" do
|
6
|
+
Monkey.hide_invisibles! do
|
7
|
+
begin
|
8
|
+
Monkey.invisible(__FILE__) { raise }
|
9
|
+
rescue
|
10
|
+
$!.backtrace.each do |line|
|
11
|
+
line.should_not include(__FILE__)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
if BACKEND
|
19
|
+
describe "backend" do
|
20
|
+
it "uses backend #{ENV['BACKEND']}" do
|
21
|
+
Monkey.backend.should == Monkey::Backend.detect_backend(BACKEND)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,13 +7,20 @@ begin
|
|
7
7
|
rescue LoadError
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
case
|
13
|
-
when "autodetect"
|
14
|
-
|
10
|
+
BACKEND, BACKEND_SETUP = ENV['BACKEND'], ENV['BACKEND_SETUP']
|
11
|
+
if BACKEND and not BACKEND.empty?
|
12
|
+
case BACKEND_SETUP
|
13
|
+
when "autodetect"
|
14
|
+
require BACKEND
|
15
|
+
Monkey::Backend.setup
|
16
|
+
when "explicit"
|
17
|
+
Monkey.backend = BACKEND
|
15
18
|
else
|
16
19
|
puts "Please set BACKEND_SETUP."
|
17
20
|
exit 1
|
18
21
|
end
|
22
|
+
version = "version " << Monkey.backend.version << ", " if Monkey.backend.version?
|
23
|
+
puts "Using #{BACKEND} (#{version}#{BACKEND_SETUP} setup mode)"
|
19
24
|
end
|
25
|
+
|
26
|
+
Monkey.show_invisibles!
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monkey-lib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 4
|
8
|
+
- 0
|
9
|
+
version: 0.4.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Konstantin Haase
|
@@ -9,10 +14,21 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-04-13 00:00:00 +02:00
|
13
18
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: backports
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
16
32
|
description: Making ruby extension frameworks pluggable.
|
17
33
|
email: konstantin.mailinglists@googlemail.com
|
18
34
|
executables: []
|
@@ -26,8 +42,8 @@ extra_rdoc_files:
|
|
26
42
|
- lib/monkey/backend/active_support.rb
|
27
43
|
- lib/monkey/backend/backports.rb
|
28
44
|
- lib/monkey/backend/common/extract_options.rb
|
29
|
-
- lib/monkey/backend/common/metaclass.rb
|
30
45
|
- lib/monkey/backend/common/parent.rb
|
46
|
+
- lib/monkey/backend/common/singleton_class.rb
|
31
47
|
- lib/monkey/backend/common/tap.rb
|
32
48
|
- lib/monkey/backend/extlib.rb
|
33
49
|
- lib/monkey/backend/facets.rb
|
@@ -40,6 +56,7 @@ extra_rdoc_files:
|
|
40
56
|
- lib/monkey/ext/pathname.rb
|
41
57
|
- lib/monkey/ext/string.rb
|
42
58
|
- lib/monkey/ext.rb
|
59
|
+
- lib/monkey/hash_fix.rb
|
43
60
|
- lib/monkey/version.rb
|
44
61
|
- lib/monkey-lib.rb
|
45
62
|
- lib/monkey.rb
|
@@ -51,8 +68,8 @@ files:
|
|
51
68
|
- lib/monkey/backend/active_support.rb
|
52
69
|
- lib/monkey/backend/backports.rb
|
53
70
|
- lib/monkey/backend/common/extract_options.rb
|
54
|
-
- lib/monkey/backend/common/metaclass.rb
|
55
71
|
- lib/monkey/backend/common/parent.rb
|
72
|
+
- lib/monkey/backend/common/singleton_class.rb
|
56
73
|
- lib/monkey/backend/common/tap.rb
|
57
74
|
- lib/monkey/backend/extlib.rb
|
58
75
|
- lib/monkey/backend/facets.rb
|
@@ -65,16 +82,19 @@ files:
|
|
65
82
|
- lib/monkey/ext/pathname.rb
|
66
83
|
- lib/monkey/ext/string.rb
|
67
84
|
- lib/monkey/ext.rb
|
85
|
+
- lib/monkey/hash_fix.rb
|
68
86
|
- lib/monkey/version.rb
|
69
87
|
- lib/monkey-lib.rb
|
70
88
|
- lib/monkey.rb
|
89
|
+
- spec/monkey/backend_spec.rb
|
71
90
|
- spec/monkey/engine_spec.rb
|
72
91
|
- spec/monkey/ext/array_spec.rb
|
73
92
|
- spec/monkey/ext/module_spec.rb
|
74
93
|
- spec/monkey/ext/object_spec.rb
|
75
94
|
- spec/monkey/ext/pathname_spec.rb
|
76
95
|
- spec/monkey/ext/string_spec.rb
|
77
|
-
- spec/monkey/
|
96
|
+
- spec/monkey/ext_spec.rb
|
97
|
+
- spec/monkey_spec.rb
|
78
98
|
- spec/spec_helper.rb
|
79
99
|
has_rdoc: true
|
80
100
|
homepage: http://github.com/rkh/monkey-lib
|
@@ -89,18 +109,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
109
|
requirements:
|
90
110
|
- - ">="
|
91
111
|
- !ruby/object:Gem::Version
|
112
|
+
segments:
|
113
|
+
- 0
|
92
114
|
version: "0"
|
93
|
-
version:
|
94
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
116
|
requirements:
|
96
|
-
- - "
|
117
|
+
- - ">="
|
97
118
|
- !ruby/object:Gem::Version
|
98
|
-
|
99
|
-
|
119
|
+
segments:
|
120
|
+
- 0
|
121
|
+
version: "0"
|
100
122
|
requirements: []
|
101
123
|
|
102
124
|
rubyforge_project:
|
103
|
-
rubygems_version: 1.3.
|
125
|
+
rubygems_version: 1.3.6
|
104
126
|
signing_key:
|
105
127
|
specification_version: 3
|
106
128
|
summary: Making ruby extension frameworks pluggable.
|
data/spec/monkey/version_spec.rb
DELETED
File without changes
|