consty 1.0.0 → 1.0.1
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.
- checksums.yaml +4 -4
- data/.travis.yml +13 -1
- data/lib/consty/version.rb +1 -1
- data/lib/consty.rb +8 -1
- data/spec/consty_spec.rb +29 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 926acc6ca18532a6b5f3ef26e0151d61174087a1
|
4
|
+
data.tar.gz: 02409837cc9e2104b199c20c9ed61ce5e1fe9728
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 217ee655ebf09c96b40ab060e4b4b0adde8383a8264289759903a28f220def9ef3b37233a296c0628c630641791820f983cdeeb46cb7e40dd6fa772b9bcd0641
|
7
|
+
data.tar.gz: 7ce26f3464a3389650bba4c6dcb0cfd37239631cc8809179bef9ebd2400c07eea6c080664a651495a7798ebfff0a0e8207a5b4aab11bb5b0c4359b2a9ff825db
|
data/.travis.yml
CHANGED
@@ -1,10 +1,22 @@
|
|
1
1
|
language: ruby
|
2
|
+
|
2
3
|
rvm:
|
3
4
|
- 1.9.3
|
4
5
|
- 2.0
|
5
6
|
- 2.1
|
6
7
|
- 2.2
|
7
8
|
- 2.3.0
|
8
|
-
-
|
9
|
+
- 2.4.0
|
10
|
+
- jruby-1.7.25
|
11
|
+
- jruby-9.1.7.0
|
12
|
+
- ruby-head
|
13
|
+
- jruby-head
|
14
|
+
|
15
|
+
matrix:
|
16
|
+
fast_finish: true
|
17
|
+
allow_failures:
|
18
|
+
- rvm: ruby-head
|
19
|
+
- rvm: jruby-head
|
20
|
+
|
9
21
|
before_install:
|
10
22
|
- gem install bundler
|
data/lib/consty/version.rb
CHANGED
data/lib/consty.rb
CHANGED
@@ -26,8 +26,15 @@ class Consty
|
|
26
26
|
namespace = Object
|
27
27
|
name_sections = name_sections[1..-1]
|
28
28
|
end
|
29
|
+
|
30
|
+
name_sections.inject(namespace) do |namespace, section|
|
31
|
+
if namespace.constants.include?(section.to_sym)
|
32
|
+
namespace.const_get section
|
33
|
+
else
|
34
|
+
namespace.const_missing section
|
35
|
+
end
|
36
|
+
end
|
29
37
|
|
30
|
-
name_sections.inject(namespace) { |c,n| c.const_get n }
|
31
38
|
end
|
32
39
|
|
33
40
|
end
|
data/spec/consty_spec.rb
CHANGED
@@ -8,6 +8,9 @@ module Foo
|
|
8
8
|
class Bar
|
9
9
|
VAL = 3
|
10
10
|
|
11
|
+
class Qux
|
12
|
+
end
|
13
|
+
|
11
14
|
def self.const_missing(name)
|
12
15
|
name.to_s == 'Const' ? Baz : super
|
13
16
|
end
|
@@ -29,6 +32,7 @@ describe Consty do
|
|
29
32
|
Consty.get('Foo').must_equal Foo
|
30
33
|
Consty.get('Foo::VAL').must_equal Foo::VAL
|
31
34
|
Consty.get('Foo::Bar').must_equal Foo::Bar
|
35
|
+
Consty.get('Foo::Baz').must_equal Foo::Baz
|
32
36
|
Consty.get('Foo::Bar::VAL').must_equal Foo::Bar::VAL
|
33
37
|
end
|
34
38
|
|
@@ -37,6 +41,7 @@ describe Consty do
|
|
37
41
|
Consty.get('Foo'.to_sym).must_equal Foo
|
38
42
|
Consty.get('Foo::VAL'.to_sym).must_equal Foo::VAL
|
39
43
|
Consty.get('Foo::Bar'.to_sym).must_equal Foo::Bar
|
44
|
+
Consty.get('Foo::Baz'.to_sym).must_equal Foo::Baz
|
40
45
|
Consty.get('Foo::Bar::VAL'.to_sym).must_equal Foo::Bar::VAL
|
41
46
|
end
|
42
47
|
|
@@ -46,20 +51,13 @@ describe Consty do
|
|
46
51
|
Consty.get('::Foo::Bar::VAL').must_equal Foo::Bar::VAL
|
47
52
|
end
|
48
53
|
|
49
|
-
it 'NameError for undefined constant' do
|
50
|
-
proc { Consty.get '' }.must_raise NameError
|
51
|
-
proc { Consty.get 'UndefinedConstant' }.must_raise NameError
|
52
|
-
end
|
53
|
-
|
54
54
|
it 'Search in ancestors' do
|
55
|
-
Consty.get('Foo::Baz::VAL').must_equal Foo::
|
55
|
+
Consty.get('Foo::Baz::VAL').must_equal Foo::Bar::VAL
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'Searches in const_missing (autoload support)' do
|
59
59
|
Consty.get('Foo::Autoloaded::Const').must_equal Foo::Baz
|
60
60
|
Consty.get('Foo::Bar::Const').must_equal Foo::Baz
|
61
|
-
proc { Consty.get 'Foo::UndefinedConstant' }.must_raise NameError
|
62
|
-
proc { Consty.get 'Foo::Bar::UndefinedConstant' }.must_raise NameError
|
63
61
|
end
|
64
62
|
|
65
63
|
end
|
@@ -70,8 +68,11 @@ describe Consty do
|
|
70
68
|
Consty.get('VAL', Foo).must_equal Foo::VAL
|
71
69
|
Consty.get('Bar', Foo).must_equal Foo::Bar
|
72
70
|
Consty.get('Bar::VAL', Foo).must_equal Foo::Bar::VAL
|
71
|
+
Consty.get('Baz::VAL', Foo).must_equal Foo::Bar::VAL
|
73
72
|
Consty.get('VAL', Foo::Bar).must_equal Foo::Bar::VAL
|
74
73
|
Consty.get('Bar', Foo::Baz).must_equal Foo::Bar
|
74
|
+
Consty.get('VAL', Foo::Bar::Qux).must_equal Foo::Bar::VAL
|
75
|
+
Consty.get('VAL', Foo::Baz::Qux).must_equal Foo::Bar::VAL
|
75
76
|
end
|
76
77
|
|
77
78
|
it 'Explicit :: prefix (::SomeClass)' do
|
@@ -81,4 +82,24 @@ describe Consty do
|
|
81
82
|
|
82
83
|
end
|
83
84
|
|
85
|
+
describe 'NameError' do
|
86
|
+
|
87
|
+
it 'Undefined constant' do
|
88
|
+
proc { Consty.get '' }.must_raise NameError
|
89
|
+
proc { Consty.get 'UndefinedConstant' }.must_raise NameError
|
90
|
+
proc { Consty.get 'Foo::UndefinedConstant' }.must_raise NameError
|
91
|
+
proc { Consty.get 'Foo::Bar::UndefinedConstant' }.must_raise NameError
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'Ignore top level defined constant' do
|
95
|
+
proc { Consty.get('Foo::Bar::Qux::VAL') }.must_raise NameError
|
96
|
+
proc { Consty.get('Foo::Baz::Qux::VAL') }.must_raise NameError
|
97
|
+
proc { Consty.get('Bar::Qux::VAL', Foo) }.must_raise NameError
|
98
|
+
proc { Consty.get('Baz::Qux::VAL', Foo) }.must_raise NameError
|
99
|
+
proc { Consty.get('Qux::VAL', Foo::Bar) }.must_raise NameError
|
100
|
+
proc { Consty.get('Qux::VAL', Foo::Baz) }.must_raise NameError
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
84
105
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|