const_lookup 0.3.0 → 0.4.0
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/README.md +17 -0
 - data/lib/const_lookup/core_ext.rb +13 -0
 - data/lib/const_lookup/version.rb +1 -1
 - data/spec/const_lookup/core_ext_spec.rb +21 -0
 - data/spec/readme_spec.rb +21 -0
 - metadata +4 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 3eecd6ef6683b4b6cb3aaa860153047ba969b853
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 87609285e5549e1e375a8f958118037cdae90a6a
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 55f4cc3995ca5af7e0b31c3d5df4124ab0b13f877111b5ea3ca6bcde58c099df17241d5c8369ad4ecd5ac4db9dd43500891aaf53a99230a20c72db4cca914b82
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 787cac62e65e37edf237f3fbaf408a9f3e103ab1f0af3f5aba6e69d7da779c8ae57d5af576dcbc829c1a57319b5ce783e60f2d491147bfd19fa188413612234b
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,6 +1,8 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # ConstLookup
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            [](http://travis-ci.org/amarshall/const_lookup)
         
     | 
| 
      
 4 
     | 
    
         
            +
            [](https://codeclimate.com/github/amarshall/const_lookup)
         
     | 
| 
      
 5 
     | 
    
         
            +
            [](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.
         
     | 
    
        data/lib/const_lookup/version.rb
    CHANGED
    
    
| 
         @@ -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. 
     | 
| 
      
 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: 
         
     |