require_callbacks 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b5c48fd53e8868361a56e4b4c9404ac335281856
4
+ data.tar.gz: 403899eae9b6559612eb67693a07be97f554a20b
5
+ SHA512:
6
+ metadata.gz: c92ed68e70cb66dcaf8eb75c9ee9c775e2293497f6d723bc40fa25ebff1e82cff631c6e70ec2888600e36b7107827b998d29fc01ed9e399bacb29b8eb4736897
7
+ data.tar.gz: ea7f92dfb528e801a145c9c25b3c2fd22ae5148c0b780d7959315f83acb664ba9796bb3b590bdb197d2c4ff5ccd4d6ba8c561c91f465f6849b5172385d6dd9c5
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in require_callbacks.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Nathan Griffith
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # require_callbacks
2
+
3
+ This gem gives you convenient hooks around calls to `load`, `require`, and `require_relative`,
4
+ which can be used to define configuration or setup code that will eventually be run when the
5
+ library is actually loaded. This helps prevent loading unnecessary gems and configuration code in
6
+ contexts where they are not needed.
7
+
8
+ ## Basic Example
9
+
10
+ If you are using bundler, you may be loading gems automatically. To prevent this behavior,
11
+ add `require: false` in your `Gemfile` like so:
12
+
13
+ ```ruby
14
+ gem 'inky', '~> 1.6.0', require: false
15
+
16
+ # Alternatively, you can replace `Bundler.require` with `Bundler.setup`
17
+ ```
18
+
19
+ Then, in your application's initialization code (or wherever most of your configuration code goes),
20
+ define the block that must be run after the gem is loaded:
21
+
22
+ ```ruby
23
+ after_require('inky') do
24
+ Inky.authorize!(ENV['MY_INKY_KEY']) }
25
+ end
26
+ ```
27
+
28
+ Lastly, wherever you ultimately need to use the gem, make sure to `require` it at the top of the
29
+ file:
30
+
31
+ ```ruby
32
+ require 'inky'
33
+ ```
34
+
35
+ And that's it! As long as `after_require` gets called before `require`, you're good to go.
36
+
37
+ ## Installation
38
+
39
+ Add this line to your application's Gemfile:
40
+
41
+ ```ruby
42
+ gem 'require_callbacks', require: false
43
+ ```
44
+
45
+ And this line before you define your callbacks:
46
+ ```ruby
47
+ require 'require_callbacks'
48
+
49
+ # Or, alternatively, don't include the "require: false" for this gem in your Gemfile ;-)
50
+ ```
51
+
52
+ Lastly, don't forget to execute:
53
+
54
+ $ bundle
55
+
56
+ ## Callbacks
57
+
58
+ `require_callbacks` adds the following methods, which are wrapped around `load`, `require`, and
59
+ `require_relative` (respectively). Note that the `after_require` callbacks will only be run the
60
+ *first* time (when `require` returns true), while `after_load` and all `before_` callbacks will
61
+ be run *every* time.
62
+
63
+ ```ruby
64
+ after_load('myfile.rb') do
65
+ # always run
66
+ end
67
+ after_require('mygem') do
68
+ # run once
69
+ end
70
+ after_require_relative('./myfile') do
71
+ # run once
72
+ end
73
+
74
+ before_load('myfile.rb') do
75
+ # always run
76
+ end
77
+ before_require('mygem') do
78
+ # always run
79
+ end
80
+ before_require_relative('./myfile') do
81
+ # always run
82
+ end
83
+ ```
84
+
85
+ ## Warnings
86
+
87
+ This gem messes with standard `Kernal` methods, so use at your own risk! There may be compatibility
88
+ issues with anything else that modifies `load`, `require`, and `require_relative`.
89
+
90
+ ## Contributing
91
+
92
+ 1. Fork it ( https://github.com/smudge/require_callbacks/fork )
93
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
94
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
95
+ 4. Push to the branch (`git push origin my-new-feature`)
96
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,3 @@
1
+ module RequireCallbacks
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,29 @@
1
+ require 'require_callbacks/version'
2
+
3
+ module RequireCallbacks
4
+ %w(load require require_relative).each do |m|
5
+ define_method("after_#{m}") do |name, &block|
6
+ @after_load ||= {}
7
+ @after_load[name] ||= []
8
+ @after_load[name] << block
9
+ end
10
+
11
+ define_method("before_#{m}") do |name, &block|
12
+ @before_load ||= {}
13
+ @before_load[name] ||= []
14
+ @before_load[name] << block
15
+ end
16
+
17
+ define_method(m) do |*args|
18
+ @after_load ||= {}
19
+ @before_load ||= {}
20
+ (@before_load[args.first] || []).each(&:call)
21
+ super(*args) && !!(@after_load[args.first] || []).each(&:call)
22
+ end
23
+ end
24
+ end
25
+
26
+ Object.send :prepend, RequireCallbacks
27
+ class << Object
28
+ prepend RequireCallbacks
29
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'require_callbacks/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'require_callbacks'
8
+ spec.version = RequireCallbacks::VERSION
9
+ spec.authors = ['smudge']
10
+ spec.email = ['nathan@ngriffith.com']
11
+ spec.summary = <<-END.gsub("\n", ' ').gsub!(/[[:space:]]+/, ' ').strip
12
+ Convenient hooks to help prevent loading unnecessary gems and
13
+ configuration code.
14
+ END
15
+ spec.description = <<-END.gsub("\n", ' ').gsub!(/[[:space:]]+/, ' ').strip
16
+ This gem gives you convenient hooks around calls to `load`, `require`, and
17
+ `require_relative`, which can be used to define configuration or setup code
18
+ that will eventually be run when the library is actually loaded. This helps
19
+ prevent loading unnecessary gems and configuration code in contexts where
20
+ they are not needed.
21
+ END
22
+ spec.homepage = ''
23
+ spec.license = 'MIT'
24
+
25
+ spec.files = `git ls-files -z`.split("\x0")
26
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
27
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.7'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: require_callbacks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - smudge
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: This gem gives you convenient hooks around calls to `load`, `require`,
42
+ and `require_relative`, which can be used to define configuration or setup code
43
+ that will eventually be run when the library is actually loaded. This helps prevent
44
+ loading unnecessary gems and configuration code in contexts where they are not needed.
45
+ email:
46
+ - nathan@ngriffith.com
47
+ executables: []
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - ".gitignore"
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - lib/require_callbacks.rb
57
+ - lib/require_callbacks/version.rb
58
+ - require_callbacks.gemspec
59
+ homepage: ''
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Convenient hooks to help prevent loading unnecessary gems and configuration
83
+ code.
84
+ test_files: []
85
+ has_rdoc: