require-here 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - jruby-18mode # JRuby in 1.8 mode
7
+ - jruby-19mode # JRuby in 1.9 mode
8
+ - rbx-18mode
9
+ - rbx-19mode
10
+ script: ruby -rubygems -w spec/require_here_spec.rb
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ require-here (0.0.0)
5
+ minitest (~> 2.11)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ minitest (2.12.1)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ minitest (~> 2.11)
17
+ require-here!
@@ -0,0 +1,43 @@
1
+ # require-here
2
+
3
+ Require constants into current namespace
4
+
5
+ [![Build Status](https://secure.travis-ci.org/hannestyden/require-here.png)](http://travis-ci.org/hannestyden/require-here)
6
+
7
+ # Example
8
+
9
+ ```ruby
10
+ # lib_a.rb
11
+
12
+ module GenericModuleName
13
+ def self.method
14
+ :lib_a
15
+ end
16
+ end
17
+
18
+ # lib_b.rb
19
+
20
+ module GenericModuleName
21
+ def self.method
22
+ :lib_b
23
+ end
24
+ end
25
+
26
+ # app.rb
27
+
28
+ module Application
29
+ module CertainAspect
30
+ require_here 'lib_a.rb'
31
+ end
32
+
33
+ module AnotherCertainAspect
34
+ require_here 'lib_b.rb'
35
+ end
36
+ end
37
+
38
+ # The modules are not included, nor reopened, into the global namespace.
39
+ Application::CertainAspect::GenericModuleName.method # => :lib_a
40
+ Application::AnotherCertainAspect::GenericModuleName.method # => :lib_b
41
+
42
+ GenericModuleName rescue $! # => #<NameError: uninitialized constant Object::GenericModuleName>
43
+ ```
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,31 @@
1
+ require 'require_here/version'
2
+
3
+ module RequireHere
4
+ LOOKUP = {}
5
+
6
+ def require_here(file_path)
7
+ # Existing constants before require.
8
+ existing = Object.constants
9
+
10
+ require(file_path)
11
+
12
+ # Introduced by require.
13
+ introduced = Object.constants - existing
14
+
15
+ # Move each introduced constant into the current namespace.
16
+ introduced.each_with_index do |c, i|
17
+ # Keep a reference to the constant.
18
+ LOOKUP[i] = Object.const_get(c)
19
+ # Remove the constant from the root.
20
+ Object.send(:remove_const, c)
21
+ # Place it in the current namespace.
22
+ module_eval %Q(#{c} = ::RequireHere::LOOKUP[#{i}])
23
+ end
24
+
25
+ LOOKUP.clear
26
+ end
27
+ end
28
+
29
+ class Module
30
+ include RequireHere
31
+ end
@@ -0,0 +1,9 @@
1
+ module RequireHere
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ PATCH = 0
6
+
7
+ SEMANTIC = [ MAJOR, MINOR, PATCH ].join('.')
8
+ end
9
+ end
@@ -0,0 +1,44 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'require_here/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'require-here'
7
+ s.version = RequireHere::Version::SEMANTIC
8
+ s.authors = [ 'Hannes Tydén' ]
9
+ s.email = [ 'hannes@soundcloud.com' ]
10
+ s.homepage = 'http://github.com/hannestyden/require-here'
11
+ s.summary = 'Require constants into current namespace.'
12
+
13
+ s.description = <<-DESCRIPTION
14
+ Keep your namespaces clean.
15
+ DESCRIPTION
16
+
17
+ # Required for validation.
18
+ s.rubyforge_project = 'require-here'
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+
23
+ s.executables = `git ls-files -- bin/*`.
24
+ split("\n").map { |f| File.basename(f) }
25
+
26
+ s.require_paths = [ 'lib' ]
27
+
28
+ dependencies =
29
+ [
30
+ [ 'minitest', '~> 2.11' ],
31
+ ]
32
+
33
+ developement_dependencies = []
34
+
35
+ runtime_dependencies = []
36
+
37
+ (dependencies + developement_dependencies).each do |dependency|
38
+ s.add_development_dependency *dependency
39
+ end
40
+
41
+ (dependencies + runtime_dependencies).each do |dependency|
42
+ s.add_runtime_dependency *dependency
43
+ end
44
+ end
@@ -0,0 +1,38 @@
1
+ # Ensure gem is used over 1.9.x built in.
2
+ gem 'minitest' if RUBY_VERSION =~ /1.9.\d/
3
+
4
+ require 'minitest/spec'
5
+ require 'minitest/autorun'
6
+
7
+ $:.push File.expand_path('../../lib', __FILE__)
8
+ require 'require_here'
9
+
10
+ module RequireHere
11
+ module Version
12
+ describe 'semantic' do
13
+ it 'should be of version 0.0.0' do
14
+ SEMANTIC.must_equal '0.0.0'
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ describe 'require_here' do
21
+ it 'should require the constants into the current namespace' do
22
+ module M
23
+ require_here './spec/support/lib_a'
24
+ end
25
+
26
+ defined?(M::A).must_equal 'constant'
27
+ end
28
+
29
+ it 'should not require the constants into the global namespace' do
30
+ module M
31
+ require_here './spec/support/lib_a'
32
+ end
33
+
34
+ lambda do
35
+ A
36
+ end.must_raise NameError
37
+ end
38
+ end
@@ -0,0 +1,2 @@
1
+ module A
2
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: require-here
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Hannes Tydén
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.11'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.11'
30
+ - !ruby/object:Gem::Dependency
31
+ name: minitest
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.11'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.11'
46
+ description: ! ' Keep your namespaces clean.
47
+
48
+ '
49
+ email:
50
+ - hannes@soundcloud.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - .travis.yml
57
+ - Gemfile
58
+ - Gemfile.lock
59
+ - README.md
60
+ - Rakefile
61
+ - lib/require_here.rb
62
+ - lib/require_here/version.rb
63
+ - require-here.gemspec
64
+ - spec/require_here_spec.rb
65
+ - spec/support/lib_a.rb
66
+ homepage: http://github.com/hannestyden/require-here
67
+ licenses: []
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project: require-here
86
+ rubygems_version: 1.8.21
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Require constants into current namespace.
90
+ test_files:
91
+ - spec/require_here_spec.rb
92
+ - spec/support/lib_a.rb