ruby-registry 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +2 -0
- data/lib/registry.rb +27 -0
- data/lib/registry/version.rb +3 -0
- data/registry.gemspec +24 -0
- data/spec/registry_spec.rb +53 -0
- data/spec/spec_helper.rb +3 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8a77b3e00480ab57af403b4440220fe7143e776c
|
4
|
+
data.tar.gz: ab947c96cc3bfa8a55a3a8f5e378366dad03283e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ba9a5f18030f07883572db33c48040daed422588f065922b1bb178ceb01c6a4253550352fab62f23987f893455f3c4264226532d48762ecca73d2b93f15399dc
|
7
|
+
data.tar.gz: c07cd6539458fb6faedcfd24490ed36c2c38aa03459cbce0bee767c6e082340c3c1c3d2061506a4b09a1eedc250cd6bc5142eb2257962ffa6ae6ad744e7d36d3
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ben Bergstein and Nick Chaffee
|
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,40 @@
|
|
1
|
+
# Registry
|
2
|
+
|
3
|
+
Register stuff to stuff with stuff and stuff.
|
4
|
+
|
5
|
+
For a use case, see [sharespost/authorize](https://github.com/sharespost/authorize).
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
Call `Registry` on your object:
|
10
|
+
|
11
|
+
```
|
12
|
+
class ClassWithRegistry
|
13
|
+
Registry(self)
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
Your class now has a registry:
|
18
|
+
|
19
|
+
```
|
20
|
+
ClassWithRegistry.registry
|
21
|
+
=> {}
|
22
|
+
```
|
23
|
+
|
24
|
+
Register something:
|
25
|
+
|
26
|
+
```
|
27
|
+
ClassWithRegistry.register(:some_key, 'value to register') { 'proc to register' }
|
28
|
+
ClassWithRegistry.registry[:some_key]
|
29
|
+
=> ["value to register", #<Proc:0x007fb3e42036f0@(irb):13>]
|
30
|
+
```
|
31
|
+
|
32
|
+
You can give any object a registry:
|
33
|
+
|
34
|
+
```
|
35
|
+
string_with_registry = 'a'
|
36
|
+
Registry(string_with_registry)
|
37
|
+
string_with_registry.register(:a, 'b')
|
38
|
+
string_with_registry[:a]
|
39
|
+
=> 'b'
|
40
|
+
```
|
data/Rakefile
ADDED
data/lib/registry.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "registry/version"
|
2
|
+
|
3
|
+
def Registry(klass)
|
4
|
+
klass.extend Registry::ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
class Registry < Hash
|
8
|
+
module ClassMethods
|
9
|
+
def register(*args, &block)
|
10
|
+
registry.register(*args, &block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def registry
|
14
|
+
@registry ||= Registry.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def reset!
|
18
|
+
@registry = Registry.new
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def register(key, *values, &block)
|
23
|
+
values << block if block_given?
|
24
|
+
values = values.first if values.count < 2
|
25
|
+
self[key] = values
|
26
|
+
end
|
27
|
+
end
|
data/registry.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'registry/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruby-registry"
|
8
|
+
spec.version = Registry::VERSION
|
9
|
+
spec.authors = ["Ben Bergstein and Nick Chaffee"]
|
10
|
+
spec.email = ["pair+ben+nick@npm.com"]
|
11
|
+
spec.summary = "A registry gem."
|
12
|
+
spec.description = "Register stuff to stuff with stuff and stuff."
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Registry do
|
4
|
+
describe '#register' do
|
5
|
+
subject { Registry.new }
|
6
|
+
|
7
|
+
let(:b) { ->{} }
|
8
|
+
|
9
|
+
before do
|
10
|
+
subject.register(:a)
|
11
|
+
subject.register(:b, 'a')
|
12
|
+
subject.register(:c, 'a', 'b')
|
13
|
+
subject.register(:d, 'a', &b)
|
14
|
+
end
|
15
|
+
|
16
|
+
specify { expect(subject[:a]).to eq nil }
|
17
|
+
specify { expect(subject[:b]).to eq 'a' }
|
18
|
+
specify { expect(subject[:c]).to eq [ 'a', 'b' ] }
|
19
|
+
specify { expect(subject[:d]).to eq [ 'a', b ] }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'kernel method' do
|
23
|
+
subject { Class.new{Registry(self)}}
|
24
|
+
let(:registry){{}}
|
25
|
+
let(:block){->{}}
|
26
|
+
|
27
|
+
describe '#register' do
|
28
|
+
before do
|
29
|
+
allow(registry).to receive(:register).and_return(nil)
|
30
|
+
subject.stub(registry: registry)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'delegates to .registry' do
|
34
|
+
subject.register('blah', &block)
|
35
|
+
expect(registry).to have_received(:register).with('blah', &block)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '.registry' do
|
40
|
+
specify do
|
41
|
+
expect(subject.registry).to be_a(Registry)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '.reset!' do
|
46
|
+
before{subject.register(:blah, 'blah')}
|
47
|
+
|
48
|
+
specify do
|
49
|
+
expect{subject.reset!}.to change{subject.registry[:blah]}.from('blah').to(nil)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-registry
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Bergstein and Nick Chaffee
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-02 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '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: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Register stuff to stuff with stuff and stuff.
|
56
|
+
email:
|
57
|
+
- pair+ben+nick@npm.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/registry.rb
|
68
|
+
- lib/registry/version.rb
|
69
|
+
- registry.gemspec
|
70
|
+
- spec/registry_spec.rb
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
homepage: ''
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.2.2
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: A registry gem.
|
96
|
+
test_files:
|
97
|
+
- spec/registry_spec.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
has_rdoc:
|