sugar-high 0.4.5.2 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.5.2
1
+ 0.4.6
@@ -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? Module.const_get(name)
26
- rescue NameError
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? Module.const_get(name)
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 = Module.const_get(name) if name.kind_of_label?
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 = Module.const_get(name) if name.kind_of_label?
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 = Module.const_get(name) if name.kind_of_label?
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sugar-high}
8
- s.version = "0.4.5.2"
8
+ s.version = "0.4.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Kristian Mandrup}]
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.5.2
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: &2151903500 !ruby/object:Gem::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: *2151903500
24
+ version_requirements: *2153368820
25
25
  description: More Ruby sugar - inspired by the 'zuker' project
26
26
  email: kmandrup@gmail.com
27
27
  executables: []