require-extra 0.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.
- data/lib/is_required.rb +23 -0
 - data/lib/on_require.rb +42 -0
 - metadata +65 -0
 
    
        data/lib/is_required.rb
    ADDED
    
    | 
         @@ -0,0 +1,23 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #--
         
     | 
| 
      
 2 
     | 
    
         
            +
            #           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
         
     | 
| 
      
 3 
     | 
    
         
            +
            #                   Version 2, December 2004
         
     | 
| 
      
 4 
     | 
    
         
            +
            #
         
     | 
| 
      
 5 
     | 
    
         
            +
            #  Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
         
     | 
| 
      
 6 
     | 
    
         
            +
            #
         
     | 
| 
      
 7 
     | 
    
         
            +
            #           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
         
     | 
| 
      
 8 
     | 
    
         
            +
            #  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
         
     | 
| 
      
 9 
     | 
    
         
            +
            #
         
     | 
| 
      
 10 
     | 
    
         
            +
            #  0. You just DO WHAT THE FUCK YOU WANT TO.
         
     | 
| 
      
 11 
     | 
    
         
            +
            #++
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            module Kernel
         
     | 
| 
      
 14 
     | 
    
         
            +
              def required? (name, from=$")
         
     | 
| 
      
 15 
     | 
    
         
            +
                regexp = /(\A|\/)#{Regexp.escape(name)}(\.([sS][oO]|[rR][bB]))?$/
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                from.any? {|file|
         
     | 
| 
      
 18 
     | 
    
         
            +
                  file =~ regexp
         
     | 
| 
      
 19 
     | 
    
         
            +
                }
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              alias is_required? required?
         
     | 
| 
      
 23 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/on_require.rb
    ADDED
    
    | 
         @@ -0,0 +1,42 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #--
         
     | 
| 
      
 2 
     | 
    
         
            +
            #           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
         
     | 
| 
      
 3 
     | 
    
         
            +
            #                   Version 2, December 2004
         
     | 
| 
      
 4 
     | 
    
         
            +
            #
         
     | 
| 
      
 5 
     | 
    
         
            +
            #  Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
         
     | 
| 
      
 6 
     | 
    
         
            +
            #
         
     | 
| 
      
 7 
     | 
    
         
            +
            #           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
         
     | 
| 
      
 8 
     | 
    
         
            +
            #  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
         
     | 
| 
      
 9 
     | 
    
         
            +
            #
         
     | 
| 
      
 10 
     | 
    
         
            +
            #  0. You just DO WHAT THE FUCK YOU WANT TO.
         
     | 
| 
      
 11 
     | 
    
         
            +
            #++
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            require 'is_required'
         
     | 
| 
      
 14 
     | 
    
         
            +
            require 'refining'
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            module Kernel
         
     | 
| 
      
 17 
     | 
    
         
            +
              RequireWatch = Hash.new {|hash, key|
         
     | 
| 
      
 18 
     | 
    
         
            +
                hash[key] = []
         
     | 
| 
      
 19 
     | 
    
         
            +
              }
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              def on_require (name, &block)
         
     | 
| 
      
 22 
     | 
    
         
            +
                if required?(name)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  block.call(name)
         
     | 
| 
      
 24 
     | 
    
         
            +
                else
         
     | 
| 
      
 25 
     | 
    
         
            +
                  RequireWatch[name] << block
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
              refine_method :require do |old, path|
         
     | 
| 
      
 30 
     | 
    
         
            +
                old.call(path).tap {
         
     | 
| 
      
 31 
     | 
    
         
            +
                  RequireWatch.any? {|name, blocks|
         
     | 
| 
      
 32 
     | 
    
         
            +
                    if required?(name, [path])
         
     | 
| 
      
 33 
     | 
    
         
            +
                      blocks.each {|block|
         
     | 
| 
      
 34 
     | 
    
         
            +
                        block.call(name)
         
     | 
| 
      
 35 
     | 
    
         
            +
                      }
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                      RequireWatch.delete(name)
         
     | 
| 
      
 38 
     | 
    
         
            +
                    end
         
     | 
| 
      
 39 
     | 
    
         
            +
                  }
         
     | 
| 
      
 40 
     | 
    
         
            +
                }
         
     | 
| 
      
 41 
     | 
    
         
            +
              end
         
     | 
| 
      
 42 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,65 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification 
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: require-extra
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version 
         
     | 
| 
      
 4 
     | 
    
         
            +
              prerelease: 
         
     | 
| 
      
 5 
     | 
    
         
            +
              version: 0.0.1
         
     | 
| 
      
 6 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 7 
     | 
    
         
            +
            authors: 
         
     | 
| 
      
 8 
     | 
    
         
            +
            - meh.
         
     | 
| 
      
 9 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 10 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 11 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            date: 2011-08-31 00:00:00 Z
         
     | 
| 
      
 14 
     | 
    
         
            +
            dependencies: 
         
     | 
| 
      
 15 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 16 
     | 
    
         
            +
              name: refining
         
     | 
| 
      
 17 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 18 
     | 
    
         
            +
              requirement: &id001 !ruby/object:Gem::Requirement 
         
     | 
| 
      
 19 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 20 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 21 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 22 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 23 
     | 
    
         
            +
                    version: "0"
         
     | 
| 
      
 24 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 25 
     | 
    
         
            +
              version_requirements: *id001
         
     | 
| 
      
 26 
     | 
    
         
            +
            description: 
         
     | 
| 
      
 27 
     | 
    
         
            +
            email: meh@paranoici.org
         
     | 
| 
      
 28 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            files: 
         
     | 
| 
      
 35 
     | 
    
         
            +
            - lib/is_required.rb
         
     | 
| 
      
 36 
     | 
    
         
            +
            - lib/on_require.rb
         
     | 
| 
      
 37 
     | 
    
         
            +
            homepage: http://github.com/meh/ruby-required
         
     | 
| 
      
 38 
     | 
    
         
            +
            licenses: []
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 41 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
            require_paths: 
         
     | 
| 
      
 44 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 45 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 46 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 47 
     | 
    
         
            +
              requirements: 
         
     | 
| 
      
 48 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 49 
     | 
    
         
            +
                - !ruby/object:Gem::Version 
         
     | 
| 
      
 50 
     | 
    
         
            +
                  version: "0"
         
     | 
| 
      
 51 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 52 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 53 
     | 
    
         
            +
              requirements: 
         
     | 
| 
      
 54 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 55 
     | 
    
         
            +
                - !ruby/object:Gem::Version 
         
     | 
| 
      
 56 
     | 
    
         
            +
                  version: "0"
         
     | 
| 
      
 57 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 60 
     | 
    
         
            +
            rubygems_version: 1.8.5
         
     | 
| 
      
 61 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 62 
     | 
    
         
            +
            specification_version: 3
         
     | 
| 
      
 63 
     | 
    
         
            +
            summary: "Some extra methods having to do with #require"
         
     | 
| 
      
 64 
     | 
    
         
            +
            test_files: []
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     |