dm-core 1.1.0.rc2 → 1.1.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -8
- data/VERSION +1 -1
- data/dm-core.gemspec +24 -15
- data/lib/dm-core.rb +9 -48
- data/lib/dm-core/adapters.rb +1 -1
- data/lib/dm-core/adapters/abstract_adapter.rb +2 -1
- data/lib/dm-core/associations/many_to_many.rb +3 -3
- data/lib/dm-core/associations/many_to_one.rb +15 -4
- data/lib/dm-core/associations/one_to_many.rb +1 -1
- data/lib/dm-core/associations/relationship.rb +7 -6
- data/lib/dm-core/collection.rb +7 -2
- data/lib/dm-core/core_ext/pathname.rb +0 -14
- data/lib/dm-core/ext/array.rb +41 -0
- data/lib/dm-core/ext/blank.rb +24 -0
- data/lib/dm-core/ext/hash.rb +67 -0
- data/lib/dm-core/ext/module.rb +49 -0
- data/lib/dm-core/ext/object.rb +57 -0
- data/lib/dm-core/ext/singleton_class.rb +8 -0
- data/lib/dm-core/ext/string.rb +24 -0
- data/lib/dm-core/ext/try_dup.rb +12 -0
- data/lib/dm-core/model.rb +2 -1
- data/lib/dm-core/model/property.rb +3 -2
- data/lib/dm-core/property.rb +1 -1
- data/lib/dm-core/property/class.rb +1 -1
- data/lib/dm-core/property/date.rb +3 -3
- data/lib/dm-core/property/date_time.rb +3 -3
- data/lib/dm-core/property/time.rb +3 -3
- data/lib/dm-core/property/typecast/time.rb +2 -2
- data/lib/dm-core/property_set.rb +1 -1
- data/lib/dm-core/query.rb +9 -12
- data/lib/dm-core/resource.rb +2 -2
- data/lib/dm-core/spec/lib/counter_adapter.rb +1 -1
- data/lib/dm-core/spec/lib/spec_helper.rb +1 -1
- data/lib/dm-core/spec/shared/resource_spec.rb +2 -1
- data/lib/dm-core/support/equalizer.rb +1 -1
- data/lib/dm-core/support/hook.rb +0 -15
- data/lib/dm-core/support/inflections.rb +60 -0
- data/lib/dm-core/support/inflector.rb +3 -0
- data/lib/dm-core/support/inflector/inflections.rb +211 -0
- data/lib/dm-core/support/inflector/methods.rb +151 -0
- data/lib/dm-core/support/lazy_array.rb +4 -4
- data/lib/dm-core/support/mash.rb +176 -0
- data/lib/dm-core/support/subject.rb +1 -1
- data/lib/dm-core/version.rb +1 -1
- data/spec/public/model/relationship_spec.rb +2 -1
- data/spec/public/shared/collection_shared_spec.rb +5 -2
- data/spec/public/shared/finder_shared_spec.rb +10 -6
- data/spec/semipublic/adapters/in_memory_adapter_spec.rb +1 -1
- data/spec/semipublic/query_spec.rb +2 -2
- data/spec/semipublic/resource/state/immutable_spec.rb +2 -1
- data/spec/semipublic/resource/state_spec.rb +1 -3
- data/spec/semipublic/shared/resource_state_shared_spec.rb +2 -1
- data/spec/semipublic/shared/subject_shared_spec.rb +1 -1
- data/spec/support/core_ext/hash.rb +10 -0
- data/spec/support/core_ext/inheritable_attributes.rb +46 -0
- data/spec/unit/array_spec.rb +8 -20
- data/spec/unit/blank_spec.rb +62 -0
- data/spec/unit/data_mapper/ordered_set/hash_spec.rb +1 -1
- data/spec/unit/hash_spec.rb +8 -16
- data/spec/unit/lazy_array_spec.rb +3 -14
- data/spec/unit/mash_spec.rb +312 -0
- data/spec/unit/module_spec.rb +15 -15
- data/spec/unit/object_spec.rb +9 -9
- data/spec/unit/try_dup_spec.rb +8 -8
- metadata +32 -39
- data/lib/dm-core/core_ext/array.rb +0 -36
- data/lib/dm-core/core_ext/hash.rb +0 -30
- data/lib/dm-core/core_ext/module.rb +0 -46
- data/lib/dm-core/core_ext/object.rb +0 -31
- data/lib/dm-core/core_ext/string.rb +0 -22
- data/lib/dm-core/core_ext/try_dup.rb +0 -44
data/spec/unit/module_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'dm-core/
|
2
|
+
require 'dm-core/ext/module'
|
3
3
|
|
4
|
-
describe Module do
|
4
|
+
describe DataMapper::Ext::Module do
|
5
5
|
|
6
6
|
before :all do
|
7
7
|
Object.send(:remove_const, :Foo) if defined?(Foo)
|
@@ -26,46 +26,46 @@ describe Module do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should raise NameError for a missing constant" do
|
29
|
-
lambda {
|
30
|
-
lambda {
|
29
|
+
lambda { DataMapper::Ext::Module.find_const(Foo, 'Moo') }.should raise_error(NameError)
|
30
|
+
lambda { DataMapper::Ext::Module.find_const(Object, 'MissingConstant') }.should raise_error(NameError)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should be able to get a recursive constant" do
|
34
|
-
|
34
|
+
DataMapper::Ext::Module.find_const(Object, 'Foo::ModBar').should == Foo::ModBar
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should ignore get Constants from the Kernel namespace correctly" do
|
38
|
-
|
38
|
+
DataMapper::Ext::Module.find_const(Object, '::Foo::ModBar').should == ::Foo::ModBar
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should find relative constants" do
|
42
|
-
|
43
|
-
|
42
|
+
DataMapper::Ext::Module.find_const(Foo, 'ModBar').should == Foo::ModBar
|
43
|
+
DataMapper::Ext::Module.find_const(Foo, 'Baz').should == Baz
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should find sibling constants" do
|
47
|
-
|
47
|
+
DataMapper::Ext::Module.find_const(Foo::ModBar, "Zed").should == Foo::Zed
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should find nested constants on nested constants" do
|
51
|
-
|
51
|
+
DataMapper::Ext::Module.find_const(Foo::ModBar, 'Noo::Too').should == Foo::ModBar::Noo::Too
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should find constants outside of nested constants" do
|
55
|
-
Foo::ModBar::Noo::Too
|
55
|
+
DataMapper::Ext::Module.find_const(Foo::ModBar::Noo::Too, "Zed").should == Foo::Zed
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'should be able to find past the second nested level' do
|
59
|
-
Foo::ModBar::Noo
|
60
|
-
Foo::ModBar::Noo::Too
|
59
|
+
DataMapper::Ext::Module.find_const(Foo::ModBar::Noo, 'Too').should == Foo::ModBar::Noo::Too
|
60
|
+
DataMapper::Ext::Module.find_const(Foo::ModBar::Noo::Too, 'Boo').should == Foo::ModBar::Noo::Too::Boo
|
61
61
|
end
|
62
62
|
|
63
63
|
|
64
64
|
it "should be able to deal with constants being added and removed" do
|
65
|
-
|
65
|
+
DataMapper::Ext::Module.find_const(Object, 'Bar') # First we load Bar with find_const
|
66
66
|
Object.module_eval { remove_const('Bar') } # Now we delete it
|
67
67
|
module ::Bar; end; # Now we redefine it
|
68
|
-
|
68
|
+
DataMapper::Ext::Module.find_const(Object, 'Bar').should == Bar
|
69
69
|
end
|
70
70
|
|
71
71
|
end
|
data/spec/unit/object_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'dm-core/
|
2
|
+
require 'dm-core/ext/object'
|
3
3
|
|
4
|
-
describe Object do
|
4
|
+
describe DataMapper::Ext::Object do
|
5
5
|
before :all do
|
6
6
|
Object.send(:remove_const, :HactiveSupport) if defined?(HactiveSupport)
|
7
7
|
module ::HactiveSupport
|
@@ -19,19 +19,19 @@ describe Object do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
describe "
|
22
|
+
describe ".full_const_get" do
|
23
23
|
it 'returns constant by FQ name in receiver namespace' do
|
24
|
-
Object.full_const_get("Oi").should == Oi
|
25
|
-
Object.full_const_get("Foo::Bar").should == Foo::Bar
|
24
|
+
DataMapper::Ext::Object.full_const_get("Oi").should == Oi
|
25
|
+
DataMapper::Ext::Object.full_const_get("Foo::Bar").should == Foo::Bar
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
describe "
|
29
|
+
describe ".full_const_set" do
|
30
30
|
it 'sets constant value by FQ name in receiver namespace' do
|
31
|
-
Object.full_const_set("HactiveSupport::MCU", HactiveSupport::MemoizeConsideredUseless)
|
31
|
+
DataMapper::Ext::Object.full_const_set("HactiveSupport::MCU", HactiveSupport::MemoizeConsideredUseless)
|
32
32
|
|
33
|
-
Object.full_const_get("HactiveSupport::MCU").should == HactiveSupport::MemoizeConsideredUseless
|
34
|
-
|
33
|
+
DataMapper::Ext::Object.full_const_get("HactiveSupport::MCU").should == HactiveSupport::MemoizeConsideredUseless
|
34
|
+
DataMapper::Ext::Object.full_const_get(HactiveSupport, "MCU").should == HactiveSupport::MemoizeConsideredUseless
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
data/spec/unit/try_dup_spec.rb
CHANGED
@@ -1,46 +1,46 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'dm-core/
|
2
|
+
require 'dm-core/ext/try_dup'
|
3
3
|
|
4
4
|
describe "try_dup" do
|
5
5
|
it "returns a duplicate version on regular objects" do
|
6
6
|
obj = Object.new
|
7
|
-
oth =
|
7
|
+
oth = DataMapper::Ext.try_dup(obj)
|
8
8
|
obj.should_not === oth
|
9
9
|
end
|
10
10
|
|
11
11
|
it "returns self on Numerics" do
|
12
12
|
obj = 12
|
13
|
-
oth =
|
13
|
+
oth = DataMapper::Ext.try_dup(obj)
|
14
14
|
obj.should === oth
|
15
15
|
end
|
16
16
|
|
17
17
|
it "returns self on Symbols" do
|
18
18
|
obj = :test
|
19
|
-
oth =
|
19
|
+
oth = DataMapper::Ext.try_dup(obj)
|
20
20
|
obj.should === oth
|
21
21
|
end
|
22
22
|
|
23
23
|
it "returns self on true" do
|
24
24
|
obj = true
|
25
|
-
oth =
|
25
|
+
oth = DataMapper::Ext.try_dup(obj)
|
26
26
|
obj.should === oth
|
27
27
|
end
|
28
28
|
|
29
29
|
it "returns self on false" do
|
30
30
|
obj = false
|
31
|
-
oth =
|
31
|
+
oth = DataMapper::Ext.try_dup(obj)
|
32
32
|
obj.should === oth
|
33
33
|
end
|
34
34
|
|
35
35
|
it "returns self on nil" do
|
36
36
|
obj = nil
|
37
|
-
oth =
|
37
|
+
oth = DataMapper::Ext.try_dup(obj)
|
38
38
|
obj.should === oth
|
39
39
|
end
|
40
40
|
|
41
41
|
it "returns self on modules" do
|
42
42
|
obj = Module.new
|
43
|
-
oth =
|
43
|
+
oth = DataMapper::Ext.try_dup(obj)
|
44
44
|
obj.object_id.should == oth.object_id
|
45
45
|
end
|
46
46
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: dm-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: 6
|
5
|
-
version: 1.1.0.
|
5
|
+
version: 1.1.0.rc3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Dan Kubb
|
@@ -10,34 +10,12 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-10 00:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
17
|
-
name: activesupport
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
-
none: false
|
20
|
-
requirements:
|
21
|
-
- - ~>
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 3.0.4
|
24
|
-
type: :runtime
|
25
|
-
prerelease: false
|
26
|
-
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: i18n
|
29
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
-
none: false
|
31
|
-
requirements:
|
32
|
-
- - ~>
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: 0.5.0
|
35
|
-
type: :runtime
|
36
|
-
prerelease: false
|
37
|
-
version_requirements: *id002
|
38
16
|
- !ruby/object:Gem::Dependency
|
39
17
|
name: addressable
|
40
|
-
requirement: &
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
41
19
|
none: false
|
42
20
|
requirements:
|
43
21
|
- - ~>
|
@@ -45,10 +23,10 @@ dependencies:
|
|
45
23
|
version: 2.2.4
|
46
24
|
type: :runtime
|
47
25
|
prerelease: false
|
48
|
-
version_requirements: *
|
26
|
+
version_requirements: *id001
|
49
27
|
- !ruby/object:Gem::Dependency
|
50
28
|
name: jeweler
|
51
|
-
requirement: &
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
52
30
|
none: false
|
53
31
|
requirements:
|
54
32
|
- - ~>
|
@@ -56,10 +34,10 @@ dependencies:
|
|
56
34
|
version: 1.5.2
|
57
35
|
type: :development
|
58
36
|
prerelease: false
|
59
|
-
version_requirements: *
|
37
|
+
version_requirements: *id002
|
60
38
|
- !ruby/object:Gem::Dependency
|
61
39
|
name: rake
|
62
|
-
requirement: &
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
63
41
|
none: false
|
64
42
|
requirements:
|
65
43
|
- - ~>
|
@@ -67,10 +45,10 @@ dependencies:
|
|
67
45
|
version: 0.8.7
|
68
46
|
type: :development
|
69
47
|
prerelease: false
|
70
|
-
version_requirements: *
|
48
|
+
version_requirements: *id003
|
71
49
|
- !ruby/object:Gem::Dependency
|
72
50
|
name: rspec
|
73
|
-
requirement: &
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
74
52
|
none: false
|
75
53
|
requirements:
|
76
54
|
- - ~>
|
@@ -78,7 +56,7 @@ dependencies:
|
|
78
56
|
version: 1.3.1
|
79
57
|
type: :development
|
80
58
|
prerelease: false
|
81
|
-
version_requirements: *
|
59
|
+
version_requirements: *id004
|
82
60
|
description: Faster, Better, Simpler.
|
83
61
|
email: dan.kubb@gmail.com
|
84
62
|
executables: []
|
@@ -107,15 +85,17 @@ files:
|
|
107
85
|
- lib/dm-core/associations/one_to_one.rb
|
108
86
|
- lib/dm-core/associations/relationship.rb
|
109
87
|
- lib/dm-core/collection.rb
|
110
|
-
- lib/dm-core/core_ext/array.rb
|
111
|
-
- lib/dm-core/core_ext/hash.rb
|
112
88
|
- lib/dm-core/core_ext/kernel.rb
|
113
|
-
- lib/dm-core/core_ext/module.rb
|
114
|
-
- lib/dm-core/core_ext/object.rb
|
115
89
|
- lib/dm-core/core_ext/pathname.rb
|
116
|
-
- lib/dm-core/core_ext/string.rb
|
117
90
|
- lib/dm-core/core_ext/symbol.rb
|
118
|
-
- lib/dm-core/
|
91
|
+
- lib/dm-core/ext/array.rb
|
92
|
+
- lib/dm-core/ext/blank.rb
|
93
|
+
- lib/dm-core/ext/hash.rb
|
94
|
+
- lib/dm-core/ext/module.rb
|
95
|
+
- lib/dm-core/ext/object.rb
|
96
|
+
- lib/dm-core/ext/singleton_class.rb
|
97
|
+
- lib/dm-core/ext/string.rb
|
98
|
+
- lib/dm-core/ext/try_dup.rb
|
119
99
|
- lib/dm-core/identity_map.rb
|
120
100
|
- lib/dm-core/model.rb
|
121
101
|
- lib/dm-core/model/hook.rb
|
@@ -178,9 +158,14 @@ files:
|
|
178
158
|
- lib/dm-core/support/descendant_set.rb
|
179
159
|
- lib/dm-core/support/equalizer.rb
|
180
160
|
- lib/dm-core/support/hook.rb
|
161
|
+
- lib/dm-core/support/inflections.rb
|
162
|
+
- lib/dm-core/support/inflector.rb
|
163
|
+
- lib/dm-core/support/inflector/inflections.rb
|
164
|
+
- lib/dm-core/support/inflector/methods.rb
|
181
165
|
- lib/dm-core/support/lazy_array.rb
|
182
166
|
- lib/dm-core/support/local_object_space.rb
|
183
167
|
- lib/dm-core/support/logger.rb
|
168
|
+
- lib/dm-core/support/mash.rb
|
184
169
|
- lib/dm-core/support/naming_conventions.rb
|
185
170
|
- lib/dm-core/support/ordered_set.rb
|
186
171
|
- lib/dm-core/support/subject.rb
|
@@ -268,8 +253,11 @@ files:
|
|
268
253
|
- spec/semipublic/shared/subject_shared_spec.rb
|
269
254
|
- spec/spec.opts
|
270
255
|
- spec/spec_helper.rb
|
256
|
+
- spec/support/core_ext/hash.rb
|
257
|
+
- spec/support/core_ext/inheritable_attributes.rb
|
271
258
|
- spec/support/properties/huge_integer.rb
|
272
259
|
- spec/unit/array_spec.rb
|
260
|
+
- spec/unit/blank_spec.rb
|
273
261
|
- spec/unit/data_mapper/ordered_set/append_spec.rb
|
274
262
|
- spec/unit/data_mapper/ordered_set/clear_spec.rb
|
275
263
|
- spec/unit/data_mapper/ordered_set/delete_spec.rb
|
@@ -324,6 +312,7 @@ files:
|
|
324
312
|
- spec/unit/hash_spec.rb
|
325
313
|
- spec/unit/hook_spec.rb
|
326
314
|
- spec/unit/lazy_array_spec.rb
|
315
|
+
- spec/unit/mash_spec.rb
|
327
316
|
- spec/unit/module_spec.rb
|
328
317
|
- spec/unit/object_spec.rb
|
329
318
|
- spec/unit/try_dup_spec.rb
|
@@ -355,7 +344,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
355
344
|
requirements: []
|
356
345
|
|
357
346
|
rubyforge_project: datamapper
|
358
|
-
rubygems_version: 1.
|
347
|
+
rubygems_version: 1.6.2
|
359
348
|
signing_key:
|
360
349
|
specification_version: 3
|
361
350
|
summary: An Object/Relational Mapper for Ruby
|
@@ -438,8 +427,11 @@ test_files:
|
|
438
427
|
- spec/semipublic/shared/resource_state_shared_spec.rb
|
439
428
|
- spec/semipublic/shared/subject_shared_spec.rb
|
440
429
|
- spec/spec_helper.rb
|
430
|
+
- spec/support/core_ext/hash.rb
|
431
|
+
- spec/support/core_ext/inheritable_attributes.rb
|
441
432
|
- spec/support/properties/huge_integer.rb
|
442
433
|
- spec/unit/array_spec.rb
|
434
|
+
- spec/unit/blank_spec.rb
|
443
435
|
- spec/unit/data_mapper/ordered_set/append_spec.rb
|
444
436
|
- spec/unit/data_mapper/ordered_set/clear_spec.rb
|
445
437
|
- spec/unit/data_mapper/ordered_set/delete_spec.rb
|
@@ -494,6 +486,7 @@ test_files:
|
|
494
486
|
- spec/unit/hash_spec.rb
|
495
487
|
- spec/unit/hook_spec.rb
|
496
488
|
- spec/unit/lazy_array_spec.rb
|
489
|
+
- spec/unit/mash_spec.rb
|
497
490
|
- spec/unit/module_spec.rb
|
498
491
|
- spec/unit/object_spec.rb
|
499
492
|
- spec/unit/try_dup_spec.rb
|
@@ -1,36 +0,0 @@
|
|
1
|
-
class Array
|
2
|
-
|
3
|
-
##
|
4
|
-
# Transforms an Array of key/value pairs into a Hash
|
5
|
-
#
|
6
|
-
# This is a better idiom than using Hash[*array.flatten] in Ruby 1.8.6
|
7
|
-
# because it is not possible to limit the flattening to a single
|
8
|
-
# level.
|
9
|
-
#
|
10
|
-
# @return [Hash]
|
11
|
-
# A Hash where each entry in the Array is turned into a key/value
|
12
|
-
#
|
13
|
-
# @api public
|
14
|
-
def to_hash
|
15
|
-
h = {}
|
16
|
-
each { |k,v| h[k] = v }
|
17
|
-
h
|
18
|
-
end
|
19
|
-
|
20
|
-
##
|
21
|
-
# Transforms an Array of key/value pairs into a Mash
|
22
|
-
#
|
23
|
-
# This is a better idiom than using Mash[*array.flatten] in Ruby 1.8.6
|
24
|
-
# because it is not possible to limit the flattening to a single
|
25
|
-
# level.
|
26
|
-
#
|
27
|
-
# @return [Mash]
|
28
|
-
# A Hash where each entry in the Array is turned into a key/value
|
29
|
-
#
|
30
|
-
# @api public
|
31
|
-
def to_mash
|
32
|
-
m = Mash.new
|
33
|
-
each { |k,v| m[k] = v }
|
34
|
-
m
|
35
|
-
end
|
36
|
-
end # class Array
|
@@ -1,30 +0,0 @@
|
|
1
|
-
class Hash
|
2
|
-
|
3
|
-
##
|
4
|
-
# Create a hash with *only* key/value pairs in receiver and +allowed+
|
5
|
-
#
|
6
|
-
# { :one => 1, :two => 2, :three => 3 }.only(:one) #=> { :one => 1 }
|
7
|
-
#
|
8
|
-
# @param [Array[String, Symbol]] *allowed The hash keys to include.
|
9
|
-
#
|
10
|
-
# @return [Hash] A new hash with only the selected keys.
|
11
|
-
#
|
12
|
-
# @api public
|
13
|
-
def only(*allowed)
|
14
|
-
hash = {}
|
15
|
-
allowed.each {|k| hash[k] = self[k] if self.has_key?(k) }
|
16
|
-
hash
|
17
|
-
end
|
18
|
-
|
19
|
-
# Convert to Mash. This class has semantics of ActiveSupport's
|
20
|
-
# HashWithIndifferentAccess and we only have it so that people can write
|
21
|
-
# params[:key] instead of params['key'].
|
22
|
-
#
|
23
|
-
# @return [Mash] This hash as a Mash for string or symbol key access.
|
24
|
-
def to_mash
|
25
|
-
hash = Mash.new(self)
|
26
|
-
hash.default = default
|
27
|
-
hash
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'dm-core/core_ext/object'
|
2
|
-
|
3
|
-
class Module
|
4
|
-
|
5
|
-
def find_const(const_name)
|
6
|
-
if const_name[0..1] == '::'
|
7
|
-
Object.full_const_get(const_name[2..-1])
|
8
|
-
else
|
9
|
-
nested_const_lookup(const_name)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
# Doesn't do any caching since constants can change with remove_const
|
16
|
-
def nested_const_lookup(const_name)
|
17
|
-
unless equal?(Object)
|
18
|
-
constants = []
|
19
|
-
|
20
|
-
name.split('::').each do |part|
|
21
|
-
const = constants.last || Object
|
22
|
-
constants << const.const_get(part)
|
23
|
-
end
|
24
|
-
|
25
|
-
parts = const_name.split('::')
|
26
|
-
|
27
|
-
# from most to least specific constant, use each as a base and try
|
28
|
-
# to find a constant with the name const_name within them
|
29
|
-
constants.reverse_each do |const|
|
30
|
-
# return the nested constant if available
|
31
|
-
return const if parts.all? do |part|
|
32
|
-
const = if RUBY_VERSION >= '1.9.0'
|
33
|
-
const.const_defined?(part, false) ? const.const_get(part, false) : nil
|
34
|
-
else
|
35
|
-
const.const_defined?(part) ? const.const_get(part) : nil
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# no relative constant found, fallback to an absolute lookup and
|
42
|
-
# use const_missing if not found
|
43
|
-
Object.full_const_get(const_name)
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|