require_callbacks 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/require_callbacks.rb +15 -17
- data/lib/require_callbacks/version.rb +1 -1
- data/require_callbacks.gemspec +1 -0
- data/spec/callbacks_spec.rb +59 -0
- data/spec/spec_helper.rb +2 -0
- metadata +22 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcbc6813e451b2df6f157c5ead86f08a3ca4112f
|
4
|
+
data.tar.gz: 1d437b44724e7838900c85a6082972ab674b3d68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e3a0c0a823325a79ed7129e5c08b01e8fbd97f84f025ca184d760957d71d46555999ccb3dd2a8e3d1324cb40d6f5c35cd67d41c9ed27e23df553b9fb61ade21
|
7
|
+
data.tar.gz: a2a41e8522e97317a6d239c7af84e37b322d3b3be046d5973fb63a1de132326f3f459e710d1baaa91b9314c20b7f8f2d656ae042d8db9fde148c546df5a17479
|
data/lib/require_callbacks.rb
CHANGED
@@ -1,25 +1,23 @@
|
|
1
1
|
require 'require_callbacks/version'
|
2
2
|
|
3
3
|
module RequireCallbacks
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
4
|
+
def after_require(name, &block)
|
5
|
+
@after_require ||= {}
|
6
|
+
@after_require[name] ||= []
|
7
|
+
@after_require[name] << block
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
def before_require(name, &block)
|
11
|
+
@before_require ||= {}
|
12
|
+
@before_require[name] ||= []
|
13
|
+
@before_require[name] << block
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
16
|
+
def require(*args)
|
17
|
+
@after_require ||= {}
|
18
|
+
@before_require ||= {}
|
19
|
+
(@before_require[args.first] || []).each(&:call)
|
20
|
+
super && !!(@after_require[args.first] || []).each(&:call)
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
data/require_callbacks.gemspec
CHANGED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
describe RequireCallbacks do
|
5
|
+
let(:file_name) { ('a'..'z').to_a.sample(8).join }
|
6
|
+
|
7
|
+
around(:each) do |example|
|
8
|
+
File.open("spec/#{file_name}.rb", 'w') do |f|
|
9
|
+
f.write("class #{file_name.upcase}; end")
|
10
|
+
end
|
11
|
+
example.run
|
12
|
+
File.delete("spec/#{file_name}.rb")
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'has a version number' do
|
16
|
+
expect(RequireCallbacks::VERSION).not_to be nil
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#require' do
|
20
|
+
subject { require(file_name) }
|
21
|
+
|
22
|
+
it { is_expected.to be(true) }
|
23
|
+
|
24
|
+
context 'on second try' do
|
25
|
+
before { require(file_name) }
|
26
|
+
it { is_expected.to be(false) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#after_require' do
|
31
|
+
before do
|
32
|
+
@count = 0
|
33
|
+
after_require(file_name) { @count += 1 }
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should run callback' do
|
37
|
+
expect(@count).to eq(0)
|
38
|
+
require(file_name)
|
39
|
+
expect(@count).to eq(1)
|
40
|
+
require(file_name)
|
41
|
+
expect(@count).to eq(1)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#before_require' do
|
46
|
+
before do
|
47
|
+
@count = 0
|
48
|
+
before_require(file_name) { @count += 1 }
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should run callback' do
|
52
|
+
expect(@count).to eq(0)
|
53
|
+
require(file_name)
|
54
|
+
expect(@count).to eq(1)
|
55
|
+
require(file_name)
|
56
|
+
expect(@count).to eq(2)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: require_callbacks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- smudge
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.3.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.3.0
|
41
55
|
description: This gem gives you convenient hooks around calls to `load`, `require`,
|
42
56
|
and `require_relative`, which can be used to define configuration or setup code
|
43
57
|
that will eventually be run when the library is actually loaded. This helps prevent
|
@@ -56,6 +70,8 @@ files:
|
|
56
70
|
- lib/require_callbacks.rb
|
57
71
|
- lib/require_callbacks/version.rb
|
58
72
|
- require_callbacks.gemspec
|
73
|
+
- spec/callbacks_spec.rb
|
74
|
+
- spec/spec_helper.rb
|
59
75
|
homepage: ''
|
60
76
|
licenses:
|
61
77
|
- MIT
|
@@ -76,10 +92,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
92
|
version: '0'
|
77
93
|
requirements: []
|
78
94
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.4.5.1
|
80
96
|
signing_key:
|
81
97
|
specification_version: 4
|
82
98
|
summary: Convenient hooks to help prevent loading unnecessary gems and configuration
|
83
99
|
code.
|
84
|
-
test_files:
|
85
|
-
|
100
|
+
test_files:
|
101
|
+
- spec/callbacks_spec.rb
|
102
|
+
- spec/spec_helper.rb
|