consty 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69c9618efaa0615ccac608d18398224c2901f617
4
- data.tar.gz: 3d3ed648418a8fc1ec54be1044c5db24557f7c88
3
+ metadata.gz: 926acc6ca18532a6b5f3ef26e0151d61174087a1
4
+ data.tar.gz: 02409837cc9e2104b199c20c9ed61ce5e1fe9728
5
5
  SHA512:
6
- metadata.gz: a1d773b2e82c6b3931219b99f0a0c641393e67847d001511be926d61e30b56b81957c905ffee458452cdc9110544c62682ab5b4c608dcd0fd3d39908a68993b5
7
- data.tar.gz: ecb95e4fc7980afe895423b4b67422fd8f7536a905e8eec336caadf88b5a1db63e62279d1a7430475aa20c65833fe077c3d3cebbf6c558af62f924615faa22e2
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
- - jruby
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
@@ -1,3 +1,3 @@
1
1
  class Consty
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
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::Baz::VAL
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.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: 2016-09-16 00:00:00.000000000 Z
11
+ date: 2017-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler