monkey-lib 0.3.5.4 → 0.3.6
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/README.rdoc +34 -1
- data/lib/monkey/autoloader.rb +2 -2
- data/lib/monkey/backend.rb +6 -4
- data/lib/monkey/backend/active_support.rb +7 -4
- data/lib/monkey/ext.rb +6 -3
- data/lib/monkey/ext/file.rb +12 -0
- data/lib/monkey/ext/pathname.rb +23 -0
- data/lib/monkey/ext/string.rb +12 -0
- data/spec/monkey/ext/pathname_spec.rb +0 -0
- data/spec/monkey/ext/string_spec.rb +4 -1
- data/spec/spec_helper.rb +6 -0
- metadata +7 -2
data/README.rdoc
CHANGED
@@ -1,4 +1,28 @@
|
|
1
|
-
|
1
|
+
Makes ruby extension libraries pluggable (thus not forcing such a library
|
2
|
+
on the users of your library - like BigBand - but still giving you some
|
3
|
+
fancy features).
|
4
|
+
|
5
|
+
TODO: Describe what it actually does. Feel free to have a look at the specs/code, should
|
6
|
+
be pretty easy to understand.
|
7
|
+
|
8
|
+
== Backends
|
9
|
+
Those libraries are supported as backends out of the box:
|
10
|
+
* ActiveSupport (tested with 2.3.2 to 3.0.pre)
|
11
|
+
* Backports (tested with 1.11.1 to 1.13.2, >= 1.13.1 required for Rubinius)
|
12
|
+
* Extlib (tested with 0.9.13 and 0.9.14)
|
13
|
+
* Facets (tested with 2.8.0 and 2.8.1)
|
14
|
+
|
15
|
+
== Ruby versions
|
16
|
+
MonkeyLib has been tested and is known to work with the following Ruby implementations:
|
17
|
+
|
18
|
+
* Ruby (MRI) 1.8.6, 1.8.7, 1.9.1, 1.9.2-preview1
|
19
|
+
* Ruby Enterprise Edition 2009.10, 2010.01
|
20
|
+
* Rubinius 1.0.0rc2
|
21
|
+
* JRuby 1.3.1, 1.4.0
|
22
|
+
* MagLev 22780 (Backports backend recommended, but all expectations pass on all backends)
|
23
|
+
* IronRuby 0.9.3 (only Extlib and Backports)
|
24
|
+
|
25
|
+
Currently it does *not* run on MacRuby, but I'm working on it.
|
2
26
|
|
3
27
|
== Running the specs
|
4
28
|
|
@@ -10,3 +34,12 @@ Run specs with active_support:
|
|
10
34
|
|
11
35
|
Run specs with backports and using mspec instead of rspec (so it might work on incomplete ruby implementations):
|
12
36
|
SPEC_RUNNER=mspec rake spec:backports
|
37
|
+
|
38
|
+
Sometimes there are issues with running rake from the ruby implementation (maybe rake is not fully supported, or the backend detection messes
|
39
|
+
with your ruby). You can use one ruby implementation to run the specs on another one. Fo instance, I use rvm to manage my rubies:
|
40
|
+
|
41
|
+
rvm install macruby-0.5
|
42
|
+
rvm use macruby-0.5
|
43
|
+
gem install mspec backports
|
44
|
+
rvm use default
|
45
|
+
RUBY=$rvm_path/rubies/macruby-0.5/bin/ruby SPEC_RUNNER=mspec rake spec:backports
|
data/lib/monkey/autoloader.rb
CHANGED
@@ -28,17 +28,17 @@ module Monkey
|
|
28
28
|
if const_defined? const_name
|
29
29
|
const = const_get const_name
|
30
30
|
const.extend Monkey::Autoloader
|
31
|
-
constants.each { |c| c.extend Monkey::Autoloader if c.is_a? Module and not c.is_a? Monkey::Autoloader }
|
32
31
|
const
|
33
32
|
else
|
34
33
|
warn "expected #{file} to define #{name}::#{const_name}"
|
35
34
|
raise LoadError
|
36
35
|
end
|
37
|
-
rescue LoadError
|
36
|
+
rescue LoadError => error
|
38
37
|
begin
|
39
38
|
return parent.const_get(const_name) if parent != self
|
40
39
|
rescue NameError
|
41
40
|
end
|
41
|
+
warn "tried to load #{file}: #{error.message}"
|
42
42
|
super
|
43
43
|
end
|
44
44
|
end
|
data/lib/monkey/backend.rb
CHANGED
@@ -23,6 +23,8 @@ module Monkey
|
|
23
23
|
load_with_prefix backend_path, data
|
24
24
|
end
|
25
25
|
|
26
|
+
alias load_lib load_libs
|
27
|
+
|
26
28
|
def load_with_prefix(prefix, libs = nil)
|
27
29
|
case libs
|
28
30
|
when String, Symbol then require File.join(prefix.to_s, libs.to_s)
|
@@ -31,11 +33,11 @@ module Monkey
|
|
31
33
|
else raise ArgumentError, "cannot handle #{libs.inspect}"
|
32
34
|
end
|
33
35
|
end
|
34
|
-
|
36
|
+
|
35
37
|
def missing(*libs)
|
36
38
|
load_with_prefix "monkey/backend/common", libs
|
37
39
|
end
|
38
|
-
|
40
|
+
|
39
41
|
def expects_module(name)
|
40
42
|
name.split("::").inject(Object) do |parent, name|
|
41
43
|
if name.empty?
|
@@ -47,7 +49,7 @@ module Monkey
|
|
47
49
|
end
|
48
50
|
|
49
51
|
end
|
50
|
-
|
52
|
+
|
51
53
|
def self.new(backend_name, backend_path = nil, &block)
|
52
54
|
mod = eval "module #{backend_name}; self; end"
|
53
55
|
mod.extend AbstractBackend
|
@@ -91,7 +93,7 @@ module Monkey
|
|
91
93
|
def self.setup
|
92
94
|
setup! preferred_backend unless setup?
|
93
95
|
end
|
94
|
-
|
96
|
+
|
95
97
|
def self.detect_backend(backend_or_name)
|
96
98
|
return backend_or_name if backend_or_name.respond_to? :setup
|
97
99
|
detected = available_backends.detect do |backend|
|
@@ -1,12 +1,15 @@
|
|
1
1
|
Monkey::Backend.new :ActiveSupport, :active_support do
|
2
2
|
def self.setup
|
3
|
-
|
3
|
+
load_lib :version
|
4
|
+
expects_module "::ActiveSupport::CoreExtensions::String::Inflections" if ActiveSupport::VERSION::MAJOR < 3
|
4
5
|
load_libs "core_ext/object" => [:metaclass, :misc], :core_ext => %w[array/extract_options string/inflections module/introspection]
|
5
|
-
|
6
|
-
|
6
|
+
if ActiveSupport::VERSION::MAJOR < 3
|
7
|
+
Array.send :include, ActiveSupport::CoreExtensions::Array::ExtractOptions
|
8
|
+
Module.send :include, ActiveSupport::CoreExtensions::Module
|
9
|
+
end
|
7
10
|
::String.class_eval do
|
8
11
|
alias to_const_string camelcase
|
9
12
|
alias to_const_path underscore
|
10
13
|
end
|
11
|
-
end
|
14
|
+
end
|
12
15
|
end
|
data/lib/monkey/ext.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
1
3
|
module Monkey
|
2
4
|
module Ext
|
3
5
|
|
@@ -7,6 +9,7 @@ module Monkey
|
|
7
9
|
if klass
|
8
10
|
@core_class = klass
|
9
11
|
klass.send :include, self
|
12
|
+
klass.extend self::ClassMethods if defined? self::ClassMethods
|
10
13
|
@core_class.class_eval <<-EOS
|
11
14
|
def method_missing(meth, *args, &blk)
|
12
15
|
return super if Monkey::Backend.setup?
|
@@ -30,10 +33,10 @@ module Monkey
|
|
30
33
|
@expectations ||= Hash.new { |h,k| h[k] = [] }
|
31
34
|
end
|
32
35
|
|
33
|
-
Dir[File.dirname(__FILE__) + "/ext/*.rb"].sort.each do |path|
|
34
|
-
filename = File.basename(path, '.rb')
|
36
|
+
Dir[::File.dirname(__FILE__) + "/ext/*.rb"].sort.each do |path|
|
37
|
+
filename = ::File.basename(path, '.rb')
|
35
38
|
class_name = filename.capitalize
|
36
|
-
extension =
|
39
|
+
extension = eval "module ::Monkey::Ext::#{class_name}; self; end" # <- for MacRuby!?
|
37
40
|
extension.extend ExtDSL
|
38
41
|
extension.core_class Object.const_get(class_name)
|
39
42
|
require "monkey/ext/#{filename}"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Monkey
|
2
|
+
module Ext
|
3
|
+
module Pathname
|
4
|
+
##
|
5
|
+
# @returns [Pathname, NilClass] Path with correct casing.
|
6
|
+
def cased_path
|
7
|
+
return unless exist?
|
8
|
+
return Dir.chdir(self) { Pathname(Dir.pwd) } if ::File.directory? path
|
9
|
+
files = Dir.chdir(dirname) { Dir.entries('.').select { |f| f.downcase == basename.to_s.downcase } }
|
10
|
+
dirname.cased_path.join(files.size == 1 ? files.first : basename)
|
11
|
+
end
|
12
|
+
|
13
|
+
def chdir(&block)
|
14
|
+
Dir.chdir(self.to_s, &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def open(mode = "r", &block)
|
18
|
+
File.open(self, mode, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/monkey/ext/string.rb
CHANGED
@@ -45,6 +45,14 @@ module Monkey
|
|
45
45
|
def dirname
|
46
46
|
Pathname(self).dirname.to_s
|
47
47
|
end
|
48
|
+
|
49
|
+
def cased_path
|
50
|
+
Pathname(self).cased_path.to_s
|
51
|
+
end
|
52
|
+
|
53
|
+
def chdir(&block)
|
54
|
+
Pathname(self).chdir(&block)
|
55
|
+
end
|
48
56
|
|
49
57
|
def expand_path
|
50
58
|
Pathname(self).expand_path.to_s
|
@@ -93,6 +101,10 @@ module Monkey
|
|
93
101
|
end
|
94
102
|
|
95
103
|
alias / file_join
|
104
|
+
|
105
|
+
def file_open(mode = 'r', &block)
|
106
|
+
Pathname(self).open(mode = 'r', &block)
|
107
|
+
end
|
96
108
|
|
97
109
|
def file_readable?
|
98
110
|
Pathname(self).readable?
|
File without changes
|
@@ -51,7 +51,10 @@ describe Monkey::Ext::String do
|
|
51
51
|
|
52
52
|
it "imports Pathname's realpath to String" do
|
53
53
|
@strings.each do |s|
|
54
|
-
|
54
|
+
begin
|
55
|
+
s.realpath.should == Pathname(s).realpath.to_s
|
56
|
+
rescue Errno::ENOENT
|
57
|
+
end
|
55
58
|
end
|
56
59
|
end
|
57
60
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
$LOAD_PATH.unshift File.expand_path(__FILE__.sub("spec/spec_helper.rb", "lib"))
|
2
2
|
require "monkey"
|
3
3
|
|
4
|
+
# I hate that code, but rbx for some reason ignores RUBYOPT.
|
5
|
+
begin
|
6
|
+
require "rubygems"
|
7
|
+
rescue LoadError
|
8
|
+
end
|
9
|
+
|
4
10
|
if ENV['BACKEND'] and not ENV['BACKEND'].empty?
|
5
11
|
puts "Using #{ENV['BACKEND']} (#{ENV['BACKEND_SETUP']} setup mode)"
|
6
12
|
case ENV['BACKEND_SETUP']
|
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.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Haase
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-02-05 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -34,8 +34,10 @@ extra_rdoc_files:
|
|
34
34
|
- lib/monkey/backend.rb
|
35
35
|
- lib/monkey/engine.rb
|
36
36
|
- lib/monkey/ext/array.rb
|
37
|
+
- lib/monkey/ext/file.rb
|
37
38
|
- lib/monkey/ext/module.rb
|
38
39
|
- lib/monkey/ext/object.rb
|
40
|
+
- lib/monkey/ext/pathname.rb
|
39
41
|
- lib/monkey/ext/string.rb
|
40
42
|
- lib/monkey/ext.rb
|
41
43
|
- lib/monkey-lib.rb
|
@@ -56,8 +58,10 @@ files:
|
|
56
58
|
- lib/monkey/backend.rb
|
57
59
|
- lib/monkey/engine.rb
|
58
60
|
- lib/monkey/ext/array.rb
|
61
|
+
- lib/monkey/ext/file.rb
|
59
62
|
- lib/monkey/ext/module.rb
|
60
63
|
- lib/monkey/ext/object.rb
|
64
|
+
- lib/monkey/ext/pathname.rb
|
61
65
|
- lib/monkey/ext/string.rb
|
62
66
|
- lib/monkey/ext.rb
|
63
67
|
- lib/monkey-lib.rb
|
@@ -66,6 +70,7 @@ files:
|
|
66
70
|
- spec/monkey/ext/array_spec.rb
|
67
71
|
- spec/monkey/ext/module_spec.rb
|
68
72
|
- spec/monkey/ext/object_spec.rb
|
73
|
+
- spec/monkey/ext/pathname_spec.rb
|
69
74
|
- spec/monkey/ext/string_spec.rb
|
70
75
|
- spec/spec_helper.rb
|
71
76
|
has_rdoc: true
|