sugar-high 0.4.5.2 → 0.4.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/VERSION +1 -1
- data/lib/sugar-high/class_ext.rb +14 -7
- data/spec/sugar-high/class_ext_spec.rb +10 -1
- data/sugar-high.gemspec +1 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.6
|
data/lib/sugar-high/class_ext.rb
CHANGED
@@ -12,7 +12,14 @@ class Class
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
module ClassExt
|
15
|
+
module ClassExt
|
16
|
+
def get_module name
|
17
|
+
# Module.const_get(name)
|
18
|
+
name.to_s.constantize
|
19
|
+
rescue
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
|
16
23
|
def is_class?(clazz)
|
17
24
|
clazz.is_a?(Class) && (clazz.respond_to? :new)
|
18
25
|
end
|
@@ -22,20 +29,20 @@ module ClassExt
|
|
22
29
|
end
|
23
30
|
|
24
31
|
def class_exists?(name)
|
25
|
-
is_class?
|
26
|
-
rescue
|
32
|
+
is_class? get_module(name)
|
33
|
+
rescue
|
27
34
|
return false
|
28
35
|
end
|
29
36
|
|
30
37
|
def module_exists?(name)
|
31
|
-
is_module?
|
38
|
+
is_module? get_module(name)
|
32
39
|
rescue NameError
|
33
40
|
return false
|
34
41
|
end
|
35
42
|
|
36
43
|
def try_class name
|
37
44
|
return name if name.kind_of?(Class)
|
38
|
-
found =
|
45
|
+
found = get_module(name) if name.kind_of_label?
|
39
46
|
return found if found.is_a?(Class)
|
40
47
|
rescue
|
41
48
|
false
|
@@ -43,7 +50,7 @@ module ClassExt
|
|
43
50
|
|
44
51
|
def try_module name
|
45
52
|
return name if name.kind_of?(Module)
|
46
|
-
found =
|
53
|
+
found = get_module(name) if name.kind_of_label?
|
47
54
|
return found if found.is_a?(Module)
|
48
55
|
rescue
|
49
56
|
false
|
@@ -51,7 +58,7 @@ module ClassExt
|
|
51
58
|
|
52
59
|
def try_module_only name
|
53
60
|
return name if is_module?(name)
|
54
|
-
found =
|
61
|
+
found = get_module(name) if name.kind_of_label?
|
55
62
|
return found if is_module?(found)
|
56
63
|
rescue
|
57
64
|
false
|
@@ -9,8 +9,13 @@ class Hello
|
|
9
9
|
end
|
10
10
|
|
11
11
|
module GoodBye
|
12
|
+
module Alpha
|
13
|
+
module Beta
|
14
|
+
end
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
18
|
+
|
14
19
|
def trial
|
15
20
|
@trial ||= Trial.new
|
16
21
|
end
|
@@ -25,7 +30,11 @@ describe ClassExt do
|
|
25
30
|
|
26
31
|
it "should return module if found" do
|
27
32
|
trial.try_module('GoodBye').should be_a(Module)
|
28
|
-
trial.try_module(:GoodBye).should be_a(Module)
|
33
|
+
trial.try_module(:GoodBye).should be_a(Module)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return namespaced module if found" do
|
37
|
+
trial.try_module('GoodBye::Alpha::Beta').should be_a(Module)
|
29
38
|
end
|
30
39
|
|
31
40
|
it "should return false if only class of that name is found" do
|
data/sugar-high.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sugar-high
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-06-11 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &2153368820 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '2.5'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2153368820
|
25
25
|
description: More Ruby sugar - inspired by the 'zuker' project
|
26
26
|
email: kmandrup@gmail.com
|
27
27
|
executables: []
|