extlib 0.9.14 → 0.9.15
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of extlib might be problematic. Click here for more details.
- data/.gitignore +13 -0
- data/Rakefile +2 -3
- data/VERSION +1 -1
- data/extlib.gemspec +11 -12
- data/lib/extlib.rb +2 -1
- data/lib/extlib/array.rb +2 -0
- data/lib/extlib/class.rb +2 -0
- data/lib/extlib/datetime.rb +1 -1
- data/lib/extlib/hash.rb +8 -0
- data/lib/extlib/hook.rb +11 -2
- data/lib/extlib/inflection.rb +2 -0
- data/lib/extlib/lazy_array.rb +2 -0
- data/lib/extlib/local_object_space.rb +12 -0
- data/lib/extlib/mash.rb +2 -0
- data/lib/extlib/module.rb +4 -0
- data/lib/extlib/object.rb +9 -6
- data/lib/extlib/time.rb +2 -1
- data/lib/extlib/try_dup.rb +44 -0
- data/spec/array_spec.rb +2 -1
- data/spec/blank_spec.rb +2 -1
- data/spec/byte_array_spec.rb +2 -1
- data/spec/class_spec.rb +2 -1
- data/spec/datetime_spec.rb +2 -2
- data/spec/hash_spec.rb +2 -3
- data/spec/hook_spec.rb +2 -1
- data/spec/inflection/plural_spec.rb +2 -1
- data/spec/inflection/singular_spec.rb +2 -1
- data/spec/inflection_extras_spec.rb +2 -1
- data/spec/lazy_array_spec.rb +5 -1
- data/spec/lazy_module_spec.rb +1 -1
- data/spec/mash_spec.rb +2 -1
- data/spec/module_spec.rb +4 -3
- data/spec/object_space_spec.rb +2 -1
- data/spec/object_spec.rb +4 -4
- data/spec/pooling_spec.rb +2 -2
- data/spec/simple_set_spec.rb +2 -1
- data/spec/spec_helper.rb +1 -4
- data/spec/string_spec.rb +2 -1
- data/spec/struct_spec.rb +2 -1
- data/spec/symbol_spec.rb +2 -1
- data/spec/time_spec.rb +3 -1
- data/spec/try_call_spec.rb +2 -1
- data/spec/try_dup_spec.rb +3 -2
- data/spec/virtual_file_spec.rb +2 -1
- metadata +29 -24
data/.gitignore
CHANGED
@@ -13,10 +13,23 @@ tmtags
|
|
13
13
|
## VIM
|
14
14
|
*.swp
|
15
15
|
|
16
|
+
## Rubinius
|
17
|
+
*.rbc
|
18
|
+
|
16
19
|
## PROJECT::GENERAL
|
20
|
+
*.gem
|
17
21
|
coverage
|
18
22
|
rdoc
|
19
23
|
pkg
|
20
24
|
tmp
|
25
|
+
doc
|
26
|
+
log
|
27
|
+
.yardoc
|
28
|
+
measurements
|
29
|
+
|
30
|
+
## BUNDLER
|
31
|
+
.bundle
|
32
|
+
Gemfile.local
|
33
|
+
Gemfile.lock
|
21
34
|
|
22
35
|
## PROJECT::SPECIFIC
|
data/Rakefile
CHANGED
@@ -15,9 +15,8 @@ begin
|
|
15
15
|
|
16
16
|
gem.rubyforge_project = 'extlib'
|
17
17
|
|
18
|
-
gem.add_development_dependency 'json_pure', '~> 1.
|
19
|
-
gem.add_development_dependency 'rspec', '~> 1.
|
20
|
-
gem.add_development_dependency 'yard', '~> 0.4.0'
|
18
|
+
gem.add_development_dependency 'json_pure', '~> 1.4'
|
19
|
+
gem.add_development_dependency 'rspec', '~> 1.3'
|
21
20
|
end
|
22
21
|
|
23
22
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.15
|
data/extlib.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{extlib}
|
8
|
-
s.version = "0.9.
|
8
|
+
s.version = "0.9.15"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dan Kubb"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-05-18}
|
13
13
|
s.description = %q{Support library for DataMapper and Merb}
|
14
14
|
s.email = %q{dan.kubb@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -39,6 +39,7 @@ Gem::Specification.new do |s|
|
|
39
39
|
"lib/extlib/inflection.rb",
|
40
40
|
"lib/extlib/lazy_array.rb",
|
41
41
|
"lib/extlib/lazy_module.rb",
|
42
|
+
"lib/extlib/local_object_space.rb",
|
42
43
|
"lib/extlib/logger.rb",
|
43
44
|
"lib/extlib/mash.rb",
|
44
45
|
"lib/extlib/module.rb",
|
@@ -54,6 +55,7 @@ Gem::Specification.new do |s|
|
|
54
55
|
"lib/extlib/struct.rb",
|
55
56
|
"lib/extlib/symbol.rb",
|
56
57
|
"lib/extlib/time.rb",
|
58
|
+
"lib/extlib/try_dup.rb",
|
57
59
|
"lib/extlib/virtual_file.rb",
|
58
60
|
"spec/array_spec.rb",
|
59
61
|
"spec/blank_spec.rb",
|
@@ -93,7 +95,7 @@ Gem::Specification.new do |s|
|
|
93
95
|
s.rdoc_options = ["--charset=UTF-8"]
|
94
96
|
s.require_paths = ["lib"]
|
95
97
|
s.rubyforge_project = %q{extlib}
|
96
|
-
s.rubygems_version = %q{1.3.
|
98
|
+
s.rubygems_version = %q{1.3.6}
|
97
99
|
s.summary = %q{Support library for DataMapper and Merb}
|
98
100
|
s.test_files = [
|
99
101
|
"spec/array_spec.rb",
|
@@ -129,18 +131,15 @@ Gem::Specification.new do |s|
|
|
129
131
|
s.specification_version = 3
|
130
132
|
|
131
133
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
132
|
-
s.add_development_dependency(%q<json_pure>, ["~> 1.
|
133
|
-
s.add_development_dependency(%q<rspec>, ["~> 1.
|
134
|
-
s.add_development_dependency(%q<yard>, ["~> 0.4.0"])
|
134
|
+
s.add_development_dependency(%q<json_pure>, ["~> 1.4"])
|
135
|
+
s.add_development_dependency(%q<rspec>, ["~> 1.3"])
|
135
136
|
else
|
136
|
-
s.add_dependency(%q<json_pure>, ["~> 1.
|
137
|
-
s.add_dependency(%q<rspec>, ["~> 1.
|
138
|
-
s.add_dependency(%q<yard>, ["~> 0.4.0"])
|
137
|
+
s.add_dependency(%q<json_pure>, ["~> 1.4"])
|
138
|
+
s.add_dependency(%q<rspec>, ["~> 1.3"])
|
139
139
|
end
|
140
140
|
else
|
141
|
-
s.add_dependency(%q<json_pure>, ["~> 1.
|
142
|
-
s.add_dependency(%q<rspec>, ["~> 1.
|
143
|
-
s.add_dependency(%q<yard>, ["~> 0.4.0"])
|
141
|
+
s.add_dependency(%q<json_pure>, ["~> 1.4"])
|
142
|
+
s.add_dependency(%q<rspec>, ["~> 1.3"])
|
144
143
|
end
|
145
144
|
end
|
146
145
|
|
data/lib/extlib.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
|
3
|
-
# for Pathname /
|
4
3
|
require 'extlib/pathname'
|
5
4
|
require 'extlib/class.rb'
|
6
5
|
require 'extlib/object'
|
7
6
|
require 'extlib/object_space'
|
7
|
+
require 'extlib/local_object_space'
|
8
8
|
require 'extlib/array'
|
9
9
|
require 'extlib/string'
|
10
10
|
require 'extlib/symbol'
|
@@ -27,6 +27,7 @@ require 'extlib/blank'
|
|
27
27
|
require 'extlib/simple_set'
|
28
28
|
require 'extlib/struct'
|
29
29
|
require 'extlib/symbol'
|
30
|
+
require 'extlib/try_dup'
|
30
31
|
|
31
32
|
Extlib.autoload('Hook', 'extlib/hook')
|
32
33
|
Extlib.autoload('Pooling', 'extlib/pooling')
|
data/lib/extlib/array.rb
CHANGED
data/lib/extlib/class.rb
CHANGED
data/lib/extlib/datetime.rb
CHANGED
data/lib/extlib/hash.rb
CHANGED
data/lib/extlib/hook.rb
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
require 'extlib/assertions'
|
2
|
+
require 'extlib/class'
|
3
|
+
require 'extlib/object'
|
4
|
+
require 'extlib/local_object_space'
|
5
|
+
|
1
6
|
module Extlib
|
2
7
|
#
|
3
8
|
# TODO: Write more documentation!
|
@@ -30,16 +35,19 @@ module Extlib
|
|
30
35
|
class << self
|
31
36
|
def method_added(name)
|
32
37
|
process_method_added(name, :instance)
|
38
|
+
super
|
33
39
|
end
|
34
40
|
|
35
41
|
def singleton_method_added(name)
|
36
42
|
process_method_added(name, :class)
|
43
|
+
super
|
37
44
|
end
|
38
45
|
end
|
39
46
|
end
|
40
47
|
end
|
41
48
|
|
42
49
|
module ClassMethods
|
50
|
+
extend Extlib::LocalObjectSpace
|
43
51
|
include Extlib::Assertions
|
44
52
|
# Inject code that executes before the target class method.
|
45
53
|
#
|
@@ -260,14 +268,15 @@ module Extlib
|
|
260
268
|
# Returns ruby code that will invoke the hook. It checks the arity of the hook method
|
261
269
|
# and passes arguments accordingly.
|
262
270
|
def inline_call(method_info, scope)
|
271
|
+
Extlib::Hook::ClassMethods.hook_scopes << method_info[:from]
|
263
272
|
name = method_info[:name]
|
264
273
|
|
265
274
|
if scope == :instance
|
266
275
|
args = method_defined?(name) && instance_method(name).arity != 0 ? '*args' : ''
|
267
|
-
%(#{name}(#{args}) if self.class <=
|
276
|
+
%(#{name}(#{args}) if self.class <= Extlib::Hook::ClassMethods.object_by_id(#{method_info[:from].object_id}))
|
268
277
|
else
|
269
278
|
args = respond_to?(name) && method(name).arity != 0 ? '*args' : ''
|
270
|
-
%(#{name}(#{args}) if self <=
|
279
|
+
%(#{name}(#{args}) if self <= Extlib::Hook::ClassMethods.object_by_id(#{method_info[:from].object_id}))
|
271
280
|
end
|
272
281
|
end
|
273
282
|
|
data/lib/extlib/inflection.rb
CHANGED
data/lib/extlib/lazy_array.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
module Extlib
|
2
|
+
module LocalObjectSpace
|
3
|
+
def self.extended(klass)
|
4
|
+
(class << klass; self; end).send :attr_accessor, :hook_scopes
|
5
|
+
klass.hook_scopes = []
|
6
|
+
end
|
7
|
+
|
8
|
+
def object_by_id(object_id)
|
9
|
+
self.hook_scopes.detect {|object| object.object_id == object_id}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/extlib/mash.rb
CHANGED
data/lib/extlib/module.rb
CHANGED
data/lib/extlib/object.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'extlib/blank'
|
3
|
+
|
1
4
|
class Object
|
2
5
|
# Extracts the singleton class, so that metaprogramming can be done on it.
|
3
6
|
#
|
@@ -92,14 +95,14 @@ class Object
|
|
92
95
|
# @param name<String> The name of the full module name to make
|
93
96
|
#
|
94
97
|
# @return [nil]
|
95
|
-
def make_module(
|
96
|
-
mod = str.split("::")
|
98
|
+
def make_module(string)
|
97
99
|
current_module = self
|
98
|
-
|
99
|
-
|
100
|
-
current_module.
|
100
|
+
string.split('::').each do |part|
|
101
|
+
current_module = if current_module.const_defined?(part)
|
102
|
+
current_module.const_get(part)
|
103
|
+
else
|
104
|
+
current_module.const_set(part, Module.new)
|
101
105
|
end
|
102
|
-
current_module = current_module.const_get(x)
|
103
106
|
end
|
104
107
|
current_module
|
105
108
|
end
|
data/lib/extlib/time.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
class Object
|
2
|
+
# Override this in a child if it cannot be dup'ed
|
3
|
+
#
|
4
|
+
# @return [Object]
|
5
|
+
def try_dup
|
6
|
+
self.dup
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class TrueClass
|
11
|
+
def try_dup
|
12
|
+
self
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class FalseClass
|
17
|
+
def try_dup
|
18
|
+
self
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Module
|
23
|
+
def try_dup
|
24
|
+
self
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class NilClass
|
29
|
+
def try_dup
|
30
|
+
self
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Numeric
|
35
|
+
def try_dup
|
36
|
+
self
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Symbol
|
41
|
+
def try_dup
|
42
|
+
self
|
43
|
+
end
|
44
|
+
end
|
data/spec/array_spec.rb
CHANGED
data/spec/blank_spec.rb
CHANGED
data/spec/byte_array_spec.rb
CHANGED
data/spec/class_spec.rb
CHANGED
data/spec/datetime_spec.rb
CHANGED
data/spec/hash_spec.rb
CHANGED
data/spec/hook_spec.rb
CHANGED
data/spec/lazy_array_spec.rb
CHANGED
data/spec/lazy_module_spec.rb
CHANGED
data/spec/mash_spec.rb
CHANGED
data/spec/module_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'extlib/module'
|
2
3
|
|
3
4
|
describe Module do
|
4
5
|
|
@@ -17,7 +18,7 @@ describe Module do
|
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
|
-
class ::
|
21
|
+
class ::Bas
|
21
22
|
end
|
22
23
|
|
23
24
|
class ::Bar
|
@@ -39,7 +40,7 @@ describe Module do
|
|
39
40
|
|
40
41
|
it "should find relative constants" do
|
41
42
|
Foo.find_const('ModBar').should == Foo::ModBar
|
42
|
-
Foo.find_const('
|
43
|
+
Foo.find_const('Bas').should == Bas
|
43
44
|
end
|
44
45
|
|
45
46
|
it "should find sibling constants" do
|
data/spec/object_space_spec.rb
CHANGED
data/spec/object_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'extlib/object'
|
3
3
|
|
4
4
|
module HactiveSupport
|
5
5
|
class MemoizeConsideredUseless
|
@@ -27,8 +27,8 @@ describe Object do
|
|
27
27
|
|
28
28
|
describe "#full_const_get" do
|
29
29
|
it 'returns constant by FQ name in receiver namespace' do
|
30
|
-
Object.full_const_get("
|
31
|
-
Object.full_const_get("
|
30
|
+
Object.full_const_get("Oi").should == Oi
|
31
|
+
Object.full_const_get("Foo::Bar").should == Foo::Bar
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
data/spec/pooling_spec.rb
CHANGED
data/spec/simple_set_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -3,8 +3,5 @@ require "rubygems"
|
|
3
3
|
require "spec"
|
4
4
|
require "yaml"
|
5
5
|
|
6
|
-
|
7
|
-
lib_path = File.expand_path("#{dir}/../lib")
|
6
|
+
lib_path = File.expand_path('../lib', __FILE__)
|
8
7
|
$LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
|
9
|
-
|
10
|
-
require 'extlib'
|
data/spec/string_spec.rb
CHANGED
data/spec/struct_spec.rb
CHANGED
data/spec/symbol_spec.rb
CHANGED
data/spec/time_spec.rb
CHANGED
data/spec/try_call_spec.rb
CHANGED
data/spec/try_dup_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'extlib/try_dup'
|
2
3
|
|
3
4
|
describe "try_dup" do
|
4
5
|
it "returns a duplicate version on regular objects" do
|
@@ -38,7 +39,7 @@ describe "try_dup" do
|
|
38
39
|
end
|
39
40
|
|
40
41
|
it "returns self on modules" do
|
41
|
-
obj =
|
42
|
+
obj = Module.new
|
42
43
|
oth = obj.try_dup
|
43
44
|
obj.object_id.should == oth.object_id
|
44
45
|
end
|
data/spec/virtual_file_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: extlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 9
|
8
|
+
- 15
|
9
|
+
version: 0.9.15
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Dan Kubb
|
@@ -9,39 +14,35 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-05-18 00:00:00 -07:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: json_pure
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ~>
|
22
26
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 4
|
30
|
+
version: "1.4"
|
31
|
+
type: :development
|
32
|
+
version_requirements: *id001
|
25
33
|
- !ruby/object:Gem::Dependency
|
26
34
|
name: rspec
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
37
|
requirements:
|
31
38
|
- - ~>
|
32
39
|
- !ruby/object:Gem::Version
|
33
|
-
|
34
|
-
|
35
|
-
-
|
36
|
-
|
40
|
+
segments:
|
41
|
+
- 1
|
42
|
+
- 3
|
43
|
+
version: "1.3"
|
37
44
|
type: :development
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
41
|
-
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: 0.4.0
|
44
|
-
version:
|
45
|
+
version_requirements: *id002
|
45
46
|
description: Support library for DataMapper and Merb
|
46
47
|
email: dan.kubb@gmail.com
|
47
48
|
executables: []
|
@@ -74,6 +75,7 @@ files:
|
|
74
75
|
- lib/extlib/inflection.rb
|
75
76
|
- lib/extlib/lazy_array.rb
|
76
77
|
- lib/extlib/lazy_module.rb
|
78
|
+
- lib/extlib/local_object_space.rb
|
77
79
|
- lib/extlib/logger.rb
|
78
80
|
- lib/extlib/mash.rb
|
79
81
|
- lib/extlib/module.rb
|
@@ -89,6 +91,7 @@ files:
|
|
89
91
|
- lib/extlib/struct.rb
|
90
92
|
- lib/extlib/symbol.rb
|
91
93
|
- lib/extlib/time.rb
|
94
|
+
- lib/extlib/try_dup.rb
|
92
95
|
- lib/extlib/virtual_file.rb
|
93
96
|
- spec/array_spec.rb
|
94
97
|
- spec/blank_spec.rb
|
@@ -136,18 +139,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
139
|
requirements:
|
137
140
|
- - ">="
|
138
141
|
- !ruby/object:Gem::Version
|
142
|
+
segments:
|
143
|
+
- 0
|
139
144
|
version: "0"
|
140
|
-
version:
|
141
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
146
|
requirements:
|
143
147
|
- - ">="
|
144
148
|
- !ruby/object:Gem::Version
|
149
|
+
segments:
|
150
|
+
- 0
|
145
151
|
version: "0"
|
146
|
-
version:
|
147
152
|
requirements: []
|
148
153
|
|
149
154
|
rubyforge_project: extlib
|
150
|
-
rubygems_version: 1.3.
|
155
|
+
rubygems_version: 1.3.6
|
151
156
|
signing_key:
|
152
157
|
specification_version: 3
|
153
158
|
summary: Support library for DataMapper and Merb
|