const_lookup 0.3.0 → 0.4.0

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: 1458ea9888b8c803ec0caa1f836100e7804b5b3c
4
- data.tar.gz: 7ed3c09d749f078e480289026678abb74e684038
3
+ metadata.gz: 3eecd6ef6683b4b6cb3aaa860153047ba969b853
4
+ data.tar.gz: 87609285e5549e1e375a8f958118037cdae90a6a
5
5
  SHA512:
6
- metadata.gz: 668cb854b6887322fc9da2175f428451b4dcdb42e20b13013a813bd57bba237531e1057c41dc24c33db5f540b1eb468d3f5be097ece4d781d4c8b663b585a010
7
- data.tar.gz: eacb2acf1eaf9c967cfca7c02f3e0d7da7615fe4802f324349e5bf5a85c3f755dede4d0cde85b4b5a0718d702dcdeaeef03e0d753a8e0571ff58860f62178887
6
+ metadata.gz: 55f4cc3995ca5af7e0b31c3d5df4124ab0b13f877111b5ea3ca6bcde58c099df17241d5c8369ad4ecd5ac4db9dd43500891aaf53a99230a20c72db4cca914b82
7
+ data.tar.gz: 787cac62e65e37edf237f3fbaf408a9f3e103ab1f0af3f5aba6e69d7da779c8ae57d5af576dcbc829c1a57319b5ce783e60f2d491147bfd19fa188413612234b
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # ConstLookup
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/amarshall/const_lookup.png?branch=master)](http://travis-ci.org/amarshall/const_lookup)
4
+ [![Code Climate rating](https://codeclimate.com/github/amarshall/const_lookup.png)](https://codeclimate.com/github/amarshall/const_lookup)
5
+ [![Gem Version](https://badge.fury.io/rb/const_lookup.png)](https://badge.fury.io/rb/const_lookup)
4
6
 
5
7
  Makes resolving a constant in a given namespace easy.
6
8
 
@@ -25,6 +27,21 @@ ConstLookup.lookup('D', A::C) #=> D
25
27
  ConstLookup.lookup('E', A::C) #=> #<NameError: Failed to find `E' in A::C>
26
28
  ```
27
29
 
30
+ Or, if you like monkey-patching Ruby core:
31
+
32
+ ```
33
+ module A
34
+ module B; end
35
+ module C; end
36
+ end
37
+ module D; end
38
+
39
+ require 'const_lookup/core_ext'
40
+
41
+ A::C.const_lookup('B') #=> A::B
42
+ A::C.const_lookup('D') #=> D
43
+ ```
44
+
28
45
  ## Contributing
29
46
 
30
47
  Contributions are welcome. Please be sure that your pull requests are atomic so they can be considered and accepted separately.
@@ -0,0 +1,13 @@
1
+ require 'const_lookup'
2
+
3
+ class ConstLookup
4
+ module CoreExt
5
+ def const_lookup name
6
+ ConstLookup.lookup name, self
7
+ end
8
+ end
9
+ end
10
+
11
+ class Module
12
+ include ConstLookup::CoreExt
13
+ end
@@ -1,3 +1,3 @@
1
1
  class ConstLookup
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -0,0 +1,21 @@
1
+ require 'const_lookup/core_ext'
2
+
3
+ describe "core extensions" do
4
+ describe Module do
5
+ describe ".const_lookup" do
6
+ it "calls ConstLookup.lookup with the receiving Module" do
7
+ tofind = double
8
+ mod = Module.new
9
+ expect(ConstLookup).to receive(:lookup).with(tofind, mod)
10
+ mod.const_lookup tofind
11
+ end
12
+
13
+ it "calls ConstLookup.lookup with the receiving Class" do
14
+ tofind = double
15
+ klass = Class.new
16
+ expect(ConstLookup).to receive(:lookup).with(tofind, klass)
17
+ klass.const_lookup tofind
18
+ end
19
+ end
20
+ end
21
+ end
data/spec/readme_spec.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'const_lookup'
2
+ require 'const_lookup/core_ext'
2
3
 
3
4
  describe "README examples" do
4
5
  describe "example 1" do
@@ -22,4 +23,24 @@ describe "README examples" do
22
23
  expect{ConstLookup.lookup('E', A::C)}.to raise_error NameError, %q(Failed to find `E' in A::C)
23
24
  end
24
25
  end
26
+
27
+ describe "example 2" do
28
+ before do
29
+ module A
30
+ module B; end
31
+ module C; end
32
+ end
33
+ module D; end
34
+ end
35
+
36
+ after do
37
+ Object.send :remove_const, :A
38
+ Object.send :remove_const, :D
39
+ end
40
+
41
+ it "works" do
42
+ expect(A::C.const_lookup('B')).to eq A::B
43
+ expect(A::C.const_lookup('D')).to eq D
44
+ end
45
+ end
25
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: const_lookup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Marshall
@@ -67,7 +67,9 @@ files:
67
67
  - Rakefile
68
68
  - const_lookup.gemspec
69
69
  - lib/const_lookup.rb
70
+ - lib/const_lookup/core_ext.rb
70
71
  - lib/const_lookup/version.rb
72
+ - spec/const_lookup/core_ext_spec.rb
71
73
  - spec/const_lookup_spec.rb
72
74
  - spec/readme_spec.rb
73
75
  homepage: http://johnandrewmarshall.com/projects/const_lookup
@@ -95,6 +97,7 @@ signing_key:
95
97
  specification_version: 4
96
98
  summary: Makes resolving a constant in a given namespace easy.
97
99
  test_files:
100
+ - spec/const_lookup/core_ext_spec.rb
98
101
  - spec/const_lookup_spec.rb
99
102
  - spec/readme_spec.rb
100
103
  has_rdoc: