backload 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.index ADDED
@@ -0,0 +1,53 @@
1
+ ---
2
+ type: ruby
3
+ revision: 2013
4
+ sources:
5
+ - var
6
+ authors:
7
+ - name: Thomas Sawyer
8
+ email: transfire@gmail.com
9
+ organizations: []
10
+ requirements:
11
+ - groups:
12
+ - test
13
+ development: true
14
+ name: microtest
15
+ - groups:
16
+ - build
17
+ development: true
18
+ name: detroit
19
+ - groups:
20
+ - build
21
+ development: true
22
+ name: rake
23
+ conflicts: []
24
+ alternatives: []
25
+ resources:
26
+ - type: home
27
+ uri: http://rubyworks.github.com/backload
28
+ label: Homepage
29
+ - type: code
30
+ uri: http://github.com/rubyworks/backload
31
+ label: Source Code
32
+ - type: bugs
33
+ uri: http://github.com/rubyworks/backload/issues
34
+ label: Issue Tracker
35
+ repositories:
36
+ - name: upstream
37
+ scm: git
38
+ uri: git://github.com/rubyworks/backload.git
39
+ categories: []
40
+ paths:
41
+ load:
42
+ - lib
43
+ copyrights:
44
+ - holder: Rubyworks
45
+ year: '2012'
46
+ license: BSD-2-Clause
47
+ created: '2012-04-29'
48
+ summary: ! 'Callbacks for #require and #load.'
49
+ title: Backload
50
+ version: 0.2.0
51
+ name: backload
52
+ description: ! 'Backload provides callbacks for Ruby''s #require and #load methods.'
53
+ date: '2012-12-23'
@@ -0,0 +1,47 @@
1
+ # RELEASE HISTORY
2
+
3
+ ## 0.2.0 / 2012-12-22
4
+
5
+ Change the name of the project from Loaded to Backload, and
6
+ changed the main callback method from `#loaded` to `#backloaded`.
7
+ Then re-added `#loaded`, `#required` and `#required_relative` as
8
+ straight callbacks for their corresponding present-tense methods.
9
+ This makes the library backward compatible with v0.1.0.
10
+
11
+ Changes:
12
+
13
+ * Rename project to "backload".
14
+ * Add basic callbacks for load, require and require_relative.
15
+ * Master callback is renamed to `#backloaded`.
16
+
17
+
18
+ ## 0.1.1 / 2012-12-19
19
+
20
+ Just a tweak to require_relative support, so that the `:relative`
21
+ option provides the relative path, not just `true` or `false`.
22
+
23
+ Changes:
24
+
25
+ * The :relative option provides the relative path.
26
+
27
+
28
+ ## 0.1.0 / 2012-12-18
29
+
30
+ This release uses a single callback method `#loaded` instead
31
+ of the previous two (`#loaded` and `#required`). It also adds
32
+ optional support for `#require_relative`.
33
+
34
+ Changes:
35
+
36
+ * Use single callback method.
37
+ * Add support for #require_relative.
38
+
39
+
40
+ ## 0.0.1 / 2012-04-29
41
+
42
+ Initial release of Loaded.
43
+
44
+ Changes:
45
+
46
+ * Created and implemented.
47
+
@@ -0,0 +1,26 @@
1
+ Required - Shouldn't require have a callback?
2
+ (http://rubyworks.github.com/required)
3
+
4
+ Copyright (c) 2012 Rubyworks. All rights reserved
5
+
6
+ Redistribution and use in source and binary forms, with or without modification, are
7
+ permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this list of
10
+ conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list
13
+ of conditions and the following disclaimer in the documentation and/or other materials
14
+ provided with the distribution.
15
+
16
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17
+ BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
19
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
22
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+
26
+ SPDX License: BSD-2-Clause
@@ -0,0 +1,74 @@
1
+ [Homepage](http://rubygems.org/gems/backload) |
2
+ [Report Issue](http://github.com/rubyworks/backload/issues) |
3
+ [Source Code](http://github.com/rubyworks/backload)
4
+ ( [![Build Status](https://secure.travis-ci.org/rubyworks/backload.png)](http://travis-ci.org/rubyworks/backload) )
5
+
6
+
7
+ # Backload
8
+
9
+ Shouldn't loading have a callback?
10
+
11
+
12
+ ## Installation
13
+
14
+ Using RubyGems type on a command line:
15
+
16
+ $ gem install backload
17
+
18
+
19
+ ## Instruction
20
+
21
+ To use Backload simply override the `Kernel.backloaded` method.
22
+
23
+ ```ruby
24
+ require 'backload'
25
+ require 'backload/require_relative'
26
+
27
+ def Kernel.backloaded(feature, options={})
28
+ if options[:require]
29
+ if rel = options[:relative]
30
+ puts "#{feature} has been required relative to #{rel}!"
31
+ else
32
+ puts "#{feature} has been required!"
33
+ end
34
+ else
35
+ if wrap = options[:wrap]
36
+ puts "#{feature} has been loaded with wrap, it's #{wrap}!"
37
+ else
38
+ puts "#{feature} has been loaded!"
39
+ end
40
+ end
41
+ end
42
+ ```
43
+
44
+ Becuase of implementation details, `#require_relative` has to be reimplemented completely
45
+ to make the callback work. To be on the safe side, at least for now, it therefore has to
46
+ be required separately, as the example above demonstrates.
47
+
48
+ Backload also provides callbacks for each type of loading. Just use the past tense
49
+ of the term for any of `#load`, `#require` and `#require_relative`. For example, to
50
+ see all features as they have been required.
51
+
52
+ ```ruby
53
+ def Kernel.required(feature)
54
+ puts "#{feature} required!"
55
+ end
56
+ ```
57
+
58
+ ## Feedback
59
+
60
+ Please report issues or suggestions to
61
+ [GitHub Issues](http://github.com/rubyworks/backload/issues).
62
+ Or if you wish to discuss in real-time try [IRC #rubyworks](irc://chat.us.freenet.org/rubyworks) on freenode.net.
63
+
64
+
65
+ ## Copying
66
+
67
+ Backload is copyrighted open source software.
68
+
69
+ Copyright 2012 Rubyworks.
70
+
71
+ it is modifiable and redistributable in accordance with the
72
+ **BSD-2-Clause** license.
73
+
74
+ See LICENSE.txt for details.
@@ -0,0 +1,29 @@
1
+ require 'backload/load'
2
+ require 'backload/require'
3
+ #require 'backload/require_relative'
4
+
5
+ module Kernel
6
+
7
+ # Common callback for all loading methods: #load, #require
8
+ # and #require_relative.
9
+ #
10
+ # @param [Hash] options
11
+ # The load callback options.
12
+ #
13
+ # @option options [Boolean] :load
14
+ # True if #load was used.
15
+ #
16
+ # @option options [Boolean] :require
17
+ # True is #require or #require_relative was used.
18
+ #
19
+ # @option options [Boolean] :relative
20
+ # True is #require_relative was used.
21
+ #
22
+ # @option options [Boolean] :wrap
23
+ # The wrap argument passed to #load.
24
+ #
25
+ def self.backloaded(path, options={})
26
+ end
27
+
28
+ end
29
+
@@ -0,0 +1,12 @@
1
+ # This does not look doable in pure Ruby.
2
+
3
+ #module Kernel
4
+ #
5
+ # #
6
+ # # We create a noop method b/c it simplifes implementation.
7
+ # # Just override this method to use.
8
+ # #
9
+ # def self.autoloaded(path, options={})
10
+ # end
11
+ #
12
+ #end
@@ -0,0 +1,52 @@
1
+ module Kernel
2
+
3
+ #
4
+ # We create a noop method b/c it simplifes implementation.
5
+ # Just override this method to use.
6
+ #
7
+ def self.loaded(path, wrap=nil)
8
+ end
9
+
10
+ private
11
+
12
+ #
13
+ # Alias original Kernel#load method.
14
+ #
15
+ alias_method :load_without_callback, :load
16
+
17
+ #
18
+ # Redefine Kernel#load with callback.
19
+ #
20
+ def load(path, wrap=nil)
21
+ result = load_without_callback(path, wrap)
22
+
23
+ if result
24
+ Kernel.loaded(path, wrap)
25
+ Kernel.backloaded(path, :load=>true, :require=>false, :wrap=>wrap)
26
+ end
27
+
28
+ result
29
+ end
30
+
31
+ class << self
32
+ #
33
+ # Alias original Kernel.load method.
34
+ #
35
+ alias_method :load_without_callback, :load
36
+
37
+ #
38
+ # Redefine Kernel.load with callback.
39
+ #
40
+ def load(path, wrap=nil)
41
+ result = load_without_callback(path, wrap)
42
+
43
+ if result
44
+ Kernel.loaded(path, wrap)
45
+ Kernel.backloaded(path, :load=>true, :require=>false, :wrap=>wrap)
46
+ end
47
+
48
+ result
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,52 @@
1
+ module Kernel
2
+
3
+ #
4
+ # We create a noop method b/c it simplifes implementation.
5
+ # Just override this method to use.
6
+ #
7
+ def self.required(path)
8
+ end
9
+
10
+ private
11
+
12
+ #
13
+ # Alias original Kernel#require method.
14
+ #
15
+ alias_method :require_without_callback, :require
16
+
17
+ #
18
+ # Redefine Kernel#require with callback.
19
+ #
20
+ def require(feature, options=nil)
21
+ result = require_without_callback(feature)
22
+
23
+ if result
24
+ Kernel.required(feature)
25
+ Kernel.backloaded(feature, :require=>true, :load=>false)
26
+ end
27
+
28
+ result
29
+ end
30
+
31
+ class << self
32
+ #
33
+ # Alias original Kernel.require method.
34
+ #
35
+ alias_method :require_without_callback, :require
36
+
37
+ #
38
+ # Redefine Kernel.require with callback.
39
+ #
40
+ def require(feature)
41
+ result = require_without_callback(feature)
42
+
43
+ if result
44
+ Kernel.required(feature)
45
+ Kernel.backloaded(feature, :require=>true, :load=>false)
46
+ end
47
+
48
+ result
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,89 @@
1
+ module Kernel
2
+
3
+ #
4
+ # We create a noop method b/c it simplifes implementation.
5
+ # Just override this method to use.
6
+ #
7
+ # Presently this is an optional feature and must be required
8
+ # separately via `backload/require_relative`.
9
+ #
10
+ def self.required_relative(path)
11
+ end
12
+
13
+ private
14
+
15
+ #
16
+ # Alias original Kernel#require_relative method.
17
+ #
18
+ alias_method :require_relative_without_callback, :require_relative
19
+
20
+ #
21
+ # Redefine Kernel#require_relative with callback.
22
+ #
23
+ # @todo It would nice if the `:relative` option were set to the
24
+ # realtive path, but that would require `Binding.of_caller`.
25
+ #
26
+ def require_relative(feature)
27
+ #result = require_relative_without_callback(feature)
28
+
29
+ ## We have to reimplement #require_relative instead of calling
30
+ ## the alias to ensure the proper path is used. (*sad*)
31
+ result = (
32
+ c = caller.first
33
+ fail "Can't parse #{c}" unless c.rindex(/:\d+(:in `.*')?$/)
34
+ file = $` # File.dirname(c)
35
+ if /\A\((.*)\)/ =~ file # eval, etc.
36
+ raise LoadError, "require_relative is called in #{$1}"
37
+ end
38
+ #options[:relative] = File.dirname(file)
39
+ absolute = File.expand_path(feature, File.dirname(file))
40
+ require_without_callback(absolute)
41
+ )
42
+
43
+ if result
44
+ Kernel.required_relative(feature)
45
+ Kernel.backloaded(feature, :require=>true, :load=>false, :relative=>File.dirname(file))
46
+ end
47
+
48
+ result
49
+ end
50
+
51
+ class << self
52
+ #
53
+ # Alias original Kernel.require_relative method.
54
+ #
55
+ alias_method :require_relative_without_callback, :require_relative
56
+
57
+ #
58
+ # Redefine Kernel.require_relative with callback.
59
+ #
60
+ # @todo It would nice if the `:relative` option were set to the
61
+ # realtive path, but that would require `Binding.of_caller`.
62
+ #
63
+ def require_relative(feature)
64
+ #result = require_relative_without_callback(feature)
65
+
66
+ ## We have to reimplement #require_relative instead of calling
67
+ ## the alias to ensure the proper path is used. (*sad*)
68
+ result = (
69
+ c = caller.first
70
+ fail "Can't parse #{c}" unless c.rindex(/:\d+(:in `.*')?$/)
71
+ file = $` # File.dirname(c)
72
+ if /\A\((.*)\)/ =~ file # eval, etc.
73
+ raise LoadError, "require_relative is called in #{$1}"
74
+ end
75
+ #options[:relative] = File.dirname(file)
76
+ absolute = File.expand_path(feature, File.dirname(file))
77
+ require_without_callback absolute
78
+ )
79
+
80
+ if result
81
+ Kernel.required_relative(feature)
82
+ Kernel.backloaded(feature, :require=>true, :load=>false, :relative=>File.dirname(file))
83
+ end
84
+
85
+ result
86
+ end
87
+ end
88
+
89
+ end
@@ -0,0 +1,2 @@
1
+ # example ruby file
2
+ 1 + 1
@@ -0,0 +1,2 @@
1
+ # example ruby file
2
+ 1 + 1
@@ -0,0 +1,2 @@
1
+ # example ruby file
2
+ 1 + 1
@@ -0,0 +1,25 @@
1
+ # Load our test framework.
2
+ require 'microtest'
3
+ require 'microtest/assertions'
4
+
5
+ # Load the library to be tested.
6
+ require 'backload'
7
+
8
+ # Put our load fixtures on the load path.
9
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/fixtures')
10
+
11
+ # We use this setup to test each possible load configuration.
12
+ def Kernel.backloaded(name, opts)
13
+ $load_name = name
14
+ $load_opts = opts
15
+ end
16
+
17
+ # Old version of Microtest lacks #refute.
18
+ module MicroTest::Assertions
19
+ unless method_defined?(:refute)
20
+ def refute(fact, msg=nil)
21
+ __assert__(!fact, msg)
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,17 @@
1
+ require File.expand_path('helper', File.dirname(__FILE__))
2
+
3
+ class RequiredTestCase < MicroTest::TestCase
4
+
5
+ def test_load
6
+ load 'example_load.rb'
7
+
8
+ assert_equal 'example_load.rb', $load_name
9
+
10
+ refute $load_opts[:require]
11
+ refute $load_opts[:relative]
12
+ assert $load_opts[:load]
13
+ refute $load_opts[:wrap]
14
+ end
15
+
16
+ end
17
+
@@ -0,0 +1,17 @@
1
+ require File.expand_path('helper', File.dirname(__FILE__))
2
+
3
+ class RequiredTestCase < MicroTest::TestCase
4
+
5
+ def test_require
6
+ require 'example_require'
7
+
8
+ assert_equal 'example_require', $load_name
9
+
10
+ assert $load_opts[:require]
11
+ refute $load_opts[:relative]
12
+ refute $load_opts[:load]
13
+ refute $load_opts[:wrap]
14
+ end
15
+
16
+ end
17
+
@@ -0,0 +1,21 @@
1
+ require File.expand_path('helper', File.dirname(__FILE__))
2
+
3
+ require 'backload/require_relative' # optional feature
4
+
5
+ class RequiredTestCase < MicroTest::TestCase
6
+
7
+ def test_require_relative
8
+ require_relative 'fixtures/example_relative'
9
+
10
+ assert_equal 'fixtures/example_relative', $load_name
11
+
12
+ assert $load_opts[:require]
13
+ assert $load_opts[:relative]
14
+ refute $load_opts[:load]
15
+ refute $load_opts[:wrap]
16
+
17
+ assert_equal File.dirname(__FILE__), $load_opts[:relative]
18
+ end
19
+
20
+ end
21
+
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: backload
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thomas Sawyer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: microtest
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
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: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: detroit
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: ! 'Backload provides callbacks for Ruby''s #require and #load methods.'
63
+ email:
64
+ - transfire@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files:
68
+ - LICENSE.txt
69
+ - HISTORY.md
70
+ - README.md
71
+ files:
72
+ - .index
73
+ - lib/backload/autoload.rb
74
+ - lib/backload/load.rb
75
+ - lib/backload/require.rb
76
+ - lib/backload/require_relative.rb
77
+ - lib/backload.rb
78
+ - test/fixtures/example_load.rb
79
+ - test/fixtures/example_relative.rb
80
+ - test/fixtures/example_require.rb
81
+ - test/helper.rb
82
+ - test/test_load.rb
83
+ - test/test_require.rb
84
+ - test/test_require_relative.rb
85
+ - LICENSE.txt
86
+ - HISTORY.md
87
+ - README.md
88
+ homepage: http://rubyworks.github.com/backload
89
+ licenses:
90
+ - BSD-2-Clause
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 1.8.23
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: ! 'Callbacks for #require and #load.'
113
+ test_files:
114
+ - test/test_require.rb
115
+ - test/helper.rb
116
+ - test/test_require_relative.rb
117
+ - test/test_load.rb
118
+ - test/fixtures/example_require.rb
119
+ - test/fixtures/example_load.rb
120
+ - test/fixtures/example_relative.rb