monkey-lib 0.3.6 → 0.4.0.a

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -5,6 +5,8 @@ fancy features).
5
5
  TODO: Describe what it actually does. Feel free to have a look at the specs/code, should
6
6
  be pretty easy to understand.
7
7
 
8
+ Version number will soon be synchronized with BigBand.
9
+
8
10
  == Backends
9
11
  Those libraries are supported as backends out of the box:
10
12
  * ActiveSupport (tested with 2.3.2 to 3.0.pre)
@@ -17,9 +19,9 @@ MonkeyLib has been tested and is known to work with the following Ruby implement
17
19
 
18
20
  * Ruby (MRI) 1.8.6, 1.8.7, 1.9.1, 1.9.2-preview1
19
21
  * Ruby Enterprise Edition 2009.10, 2010.01
20
- * Rubinius 1.0.0rc2
22
+ * Rubinius 1.0.0-rc2, 1.0.0-rc3
21
23
  * JRuby 1.3.1, 1.4.0
22
- * MagLev 22780 (Backports backend recommended, but all expectations pass on all backends)
24
+ * MagLev 22780, 2804, 2816 (Backports backend recommended, but all expectations pass on all backends)
23
25
  * IronRuby 0.9.3 (only Extlib and Backports)
24
26
 
25
27
  Currently it does *not* run on MacRuby, but I'm working on it.
@@ -1,11 +1,11 @@
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
+ expects_module "::ActiveSupport::CoreExtensions::String::Inflections" if ::ActiveSupport::VERSION::MAJOR < 3
5
5
  load_libs "core_ext/object" => [:metaclass, :misc], :core_ext => %w[array/extract_options string/inflections module/introspection]
6
- if ActiveSupport::VERSION::MAJOR < 3
7
- Array.send :include, ActiveSupport::CoreExtensions::Array::ExtractOptions
8
- Module.send :include, ActiveSupport::CoreExtensions::Module
6
+ if ::ActiveSupport::VERSION::MAJOR < 3
7
+ ::Array.send :include, ::ActiveSupport::CoreExtensions::Array::ExtractOptions
8
+ ::Module.send :include, ::ActiveSupport::CoreExtensions::Module
9
9
  end
10
10
  ::String.class_eval do
11
11
  alias to_const_string camelcase
@@ -11,7 +11,7 @@ module Monkey
11
11
  attr_accessor :backend_name, :backend_path
12
12
 
13
13
  def available?
14
- Object.const_defined? backend_name or $LOADED_FEATURES.any? { |l| l =~ /^#{backend_path}\// }
14
+ Object.const_defined? backend_name
15
15
  end
16
16
 
17
17
  def setup_complete
@@ -68,10 +68,10 @@ module Monkey
68
68
  end
69
69
 
70
70
  def self.setup!(backend)
71
+ @setup = true
71
72
  if backend
72
73
  @backend = detect_backend(backend)
73
74
  @backend.setup
74
- @setup = true
75
75
  @backend
76
76
  else
77
77
  available_backends.each do |backend|
@@ -109,4 +109,4 @@ module Monkey
109
109
  end
110
110
 
111
111
  end
112
- end
112
+ end
@@ -6,160 +6,177 @@ module Monkey
6
6
  # Defined by backend.
7
7
  expects :constantize, :to_const_string, :to_const_path, :underscore, :camelcase
8
8
 
9
- def atime
10
- Pathname(self).atime
11
- end
9
+ feature :version do
12
10
 
13
- def absolute_path?
14
- Pathname(self).absolute?
15
- end
11
+ def to_version
12
+ dup.to_version!
13
+ end
16
14
 
17
- def basename
18
- Pathname(self).basename.to_s
19
- end
15
+ def to_version!
16
+ extend Monkey::Version
17
+ self
18
+ end
20
19
 
21
- def blockdev?
22
- Pathname(self).blockdev?
23
20
  end
24
21
 
25
- def chardev?
26
- Pathname(self).chardev?
27
- end
22
+ feature :pathname do
28
23
 
29
- def cleanpath
30
- Pathname(self).cleanpath.to_s
31
- end
24
+ def atime
25
+ Pathname(self).atime
26
+ end
32
27
 
33
- def ctime
34
- Pathname(self).ctime
35
- end
28
+ def absolute_path?
29
+ Pathname(self).absolute?
30
+ end
36
31
 
37
- def directory_children
38
- Pathname(self).children
39
- end
32
+ def basename
33
+ Pathname(self).basename.to_s
34
+ end
40
35
 
41
- def directory?
42
- Pathname(self).directory?
43
- end
36
+ def blockdev?
37
+ Pathname(self).blockdev?
38
+ end
44
39
 
45
- def dirname
46
- Pathname(self).dirname.to_s
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
40
+ def chardev?
41
+ Pathname(self).chardev?
42
+ end
56
43
 
57
- def expand_path
58
- Pathname(self).expand_path.to_s
59
- end
44
+ def cleanpath
45
+ Pathname(self).cleanpath.to_s
46
+ end
60
47
 
61
- def extname
62
- Pathname(self).extname.to_s
63
- end
48
+ def ctime
49
+ Pathname(self).ctime
50
+ end
64
51
 
65
- def file?
66
- Pathname(self).file?
67
- end
52
+ def directory_children
53
+ Pathname(self).children
54
+ end
68
55
 
69
- def file_exist?
70
- Pathname(self).exist?
71
- end
56
+ def directory?
57
+ Pathname(self).directory?
58
+ end
72
59
 
73
- alias file_exists? file_exist?
60
+ def dirname
61
+ Pathname(self).dirname.to_s
62
+ end
74
63
 
75
- def file_grpowned?
76
- Pathname(self).grpowned?
77
- end
64
+ def cased_path
65
+ Pathname(self).cased_path.to_s
66
+ end
78
67
 
79
- def file_owned?
80
- Pathname(self).owned?
81
- end
68
+ def chdir(&block)
69
+ Pathname(self).chdir(&block)
70
+ end
82
71
 
83
- def file_size?
84
- Pathname(self).size?
85
- end
72
+ def expand_path
73
+ Pathname(self).expand_path.to_s
74
+ end
86
75
 
87
- def file_sticky?
88
- Pathname(self).sticky?
89
- end
76
+ def extname
77
+ Pathname(self).extname.to_s
78
+ end
90
79
 
91
- def file_executable?
92
- Pathname(self).executable?
93
- end
80
+ def file?
81
+ Pathname(self).file?
82
+ end
94
83
 
95
- def file_executable_real?
96
- Pathname(self).executable_real?
97
- end
84
+ def file_exist?
85
+ Pathname(self).exist?
86
+ end
98
87
 
99
- def file_join(other)
100
- Pathname(self).join(other.to_s).to_s
101
- end
88
+ alias file_exists? file_exist?
102
89
 
103
- alias / file_join
104
-
105
- def file_open(mode = 'r', &block)
106
- Pathname(self).open(mode = 'r', &block)
107
- end
90
+ def file_grpowned?
91
+ Pathname(self).grpowned?
92
+ end
108
93
 
109
- def file_readable?
110
- Pathname(self).readable?
111
- end
94
+ def file_owned?
95
+ Pathname(self).owned?
96
+ end
112
97
 
113
- def file_readable_real?
114
- Pathname(self).readable_real?
115
- end
98
+ def file_size?
99
+ Pathname(self).size?
100
+ end
116
101
 
117
- def file_relative?
118
- Pathname(self).relative?
119
- end
102
+ def file_sticky?
103
+ Pathname(self).sticky?
104
+ end
120
105
 
121
- def file_writable?
122
- Pathname(self).writable?
123
- end
106
+ def file_executable?
107
+ Pathname(self).executable?
108
+ end
124
109
 
125
- def file_writable_real?
126
- Pathname(self).writable_real?
127
- end
110
+ def file_executable_real?
111
+ Pathname(self).executable_real?
112
+ end
128
113
 
129
- def file_zero?
130
- Pathname(self).zero?
131
- end
114
+ def file_join(other)
115
+ Pathname(self).join(other.to_s).to_s
116
+ end
132
117
 
133
- def ftype
134
- Pathname(self).ftype.to_s
135
- end
118
+ alias / file_join
136
119
 
137
- def mountpoint?
138
- Pathname(self).mountpoint?
139
- end
120
+ def file_open(mode = 'r', &block)
121
+ Pathname(self).open(mode = 'r', &block)
122
+ end
140
123
 
141
- def mtime
142
- Pathname(self).mtime
143
- end
124
+ def file_readable?
125
+ Pathname(self).readable?
126
+ end
144
127
 
145
- def pipe?
146
- Pathname(self).pipe?
147
- end
128
+ def file_readable_real?
129
+ Pathname(self).readable_real?
130
+ end
148
131
 
149
- def realpath
150
- Pathname(self).realpath.to_s
151
- end
132
+ def file_relative?
133
+ Pathname(self).relative?
134
+ end
152
135
 
153
- def root?
154
- Pathname(self).root?
155
- end
136
+ def file_writable?
137
+ Pathname(self).writable?
138
+ end
156
139
 
157
- def socket?
158
- Pathname(self).socket?
159
- end
140
+ def file_writable_real?
141
+ Pathname(self).writable_real?
142
+ end
143
+
144
+ def file_zero?
145
+ Pathname(self).zero?
146
+ end
147
+
148
+ def ftype
149
+ Pathname(self).ftype.to_s
150
+ end
151
+
152
+ def mountpoint?
153
+ Pathname(self).mountpoint?
154
+ end
155
+
156
+ def mtime
157
+ Pathname(self).mtime
158
+ end
159
+
160
+ def pipe?
161
+ Pathname(self).pipe?
162
+ end
163
+
164
+ def realpath
165
+ Pathname(self).realpath.to_s
166
+ end
167
+
168
+ def root?
169
+ Pathname(self).root?
170
+ end
171
+
172
+ def socket?
173
+ Pathname(self).socket?
174
+ end
175
+
176
+ def symlink?
177
+ Pathname(self).symlink?
178
+ end
160
179
 
161
- def symlink?
162
- Pathname(self).symlink?
163
180
  end
164
181
 
165
182
  end
data/lib/monkey/ext.rb CHANGED
@@ -20,6 +20,36 @@ module Monkey
20
20
  end
21
21
  return @core_class
22
22
  end
23
+
24
+ def rename_core_method(old_name, new_name)
25
+ new_name = new_name % old_name if new_name.is_a? String
26
+ core_class.class_eval do
27
+ alias_method new_name, old_name
28
+ undef_method old_name
29
+ end
30
+ end
31
+
32
+ def wrap_core_methods(list = {})
33
+ list.each do |old_name, new_name|
34
+ rename_core_method old_name, new_name
35
+ define_method(old_name) { |*args| send(new_name, old_name, *args) }
36
+ end
37
+ end
38
+
39
+ def feature(name, mode = :instance, &block)
40
+ case mode
41
+ when :instance then block.call
42
+ when :class then class_methods(&block)
43
+ when :shared
44
+ feature(name, :instance, &block)
45
+ feature(name, :class, &block)
46
+ else raise ArgumentError, "unkown mode #{mode.inspect}"
47
+ end
48
+ end
49
+
50
+ def class_methods(&block)
51
+ raise NotImplementedError
52
+ end
23
53
 
24
54
  def expects(*list)
25
55
  list.each do |name|
@@ -0,0 +1,35 @@
1
+ module Monkey
2
+ module Version
3
+ def self.new(value = "")
4
+ super.to_version!
5
+ end
6
+
7
+ def to_version
8
+ self.dup
9
+ end
10
+
11
+ def to_version!
12
+ self
13
+ end
14
+
15
+ def major; fields[0]; end
16
+ def minor; fields[1]; end
17
+ def tiny; fields[2]; end
18
+
19
+ def <=>(other)
20
+ return super unless other.respond_to? :to_version
21
+ mine, others = fields.dup, other.to_version.fields
22
+ loop do
23
+ a, b = mine.unshift, others.unshift
24
+ return 0 if a.nil? and b.nil?
25
+ return 1 if b.nil? or (a.is_a? Integer and b.is_a? String)
26
+ return -1 if a.nil? or (b.is_a? Integer and a.is_a? String)
27
+ return comp unless (comp = (a <=> b)) == 0
28
+ end
29
+ end
30
+
31
+ def fields
32
+ split(".").map { |f| f =~ /^\d+$/ ? f.to_i : f }
33
+ end
34
+ end
35
+ end
@@ -8,8 +8,9 @@ describe Monkey::Ext::Module do
8
8
  Monkey::Ext.parent.should == Monkey
9
9
  Monkey.parent.should == Object
10
10
  Object.parent.should == Object
11
- Foo = Monkey::Ext::Module
12
- Foo.parent.should == Monkey::Ext
11
+ Object.send :remove_const, :ExtFoo if Object.const_defined? :ExtFoo
12
+ ExtFoo = Monkey::Ext::Module
13
+ ExtFoo.parent.should == Monkey::Ext
13
14
  end
14
15
  end
15
16
  end
@@ -38,9 +38,6 @@ describe Monkey::Ext::String do
38
38
 
39
39
  before do
40
40
  @strings = ["/usr/bin/ruby", ".", "..", ENV["HOME"]]
41
- @methods = Pathname.instance_methods(false).reject do |m|
42
- String.methods.include? m or m.to_s == "to_path"
43
- end
44
41
  end
45
42
 
46
43
  it "imports Pathname's cleanpath to String" do
File without changes
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.6
4
+ version: 0.4.0.a
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-02-05 00:00:00 +01:00
12
+ date: 2010-02-15 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -40,6 +40,7 @@ extra_rdoc_files:
40
40
  - lib/monkey/ext/pathname.rb
41
41
  - lib/monkey/ext/string.rb
42
42
  - lib/monkey/ext.rb
43
+ - lib/monkey/version.rb
43
44
  - lib/monkey-lib.rb
44
45
  - lib/monkey.rb
45
46
  files:
@@ -64,6 +65,7 @@ files:
64
65
  - lib/monkey/ext/pathname.rb
65
66
  - lib/monkey/ext/string.rb
66
67
  - lib/monkey/ext.rb
68
+ - lib/monkey/version.rb
67
69
  - lib/monkey-lib.rb
68
70
  - lib/monkey.rb
69
71
  - spec/monkey/engine_spec.rb
@@ -72,6 +74,7 @@ files:
72
74
  - spec/monkey/ext/object_spec.rb
73
75
  - spec/monkey/ext/pathname_spec.rb
74
76
  - spec/monkey/ext/string_spec.rb
77
+ - spec/monkey/version_spec.rb
75
78
  - spec/spec_helper.rb
76
79
  has_rdoc: true
77
80
  homepage: http://github.com/rkh/monkey-lib
@@ -90,9 +93,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
93
  version:
91
94
  required_rubygems_version: !ruby/object:Gem::Requirement
92
95
  requirements:
93
- - - ">="
96
+ - - ">"
94
97
  - !ruby/object:Gem::Version
95
- version: "0"
98
+ version: 1.3.1
96
99
  version:
97
100
  requirements: []
98
101