register 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.travis.yml ADDED
@@ -0,0 +1,23 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.4.1
6
+ - 2.3.4
7
+ - 2.2.7
8
+ before_install: gem install bundler -v 1.15.4
9
+ notifications:
10
+ email:
11
+ recipients:
12
+ - kigster@gmail.com
13
+ on_success: change
14
+ on_failure: always
15
+ slack:
16
+ rooms:
17
+ secure: GcACCHmcmo99lYE5dgt2TmY4YIPMWr75q0Bkm4Lddegq/1eMXgcZDz00j8iHWtnveyJSjEUpZFQ9uyx+P7dvxT7D5gl43arKZEylS4vMRg9QRgZu7/ROrXbJtrUyKulFRUTdFrmOiK9nDKpAzlvLvMKC4kaQnn88Xtu9pYMU8y4n5fCtl29gZM9ZjVbrBBvV/SumnTDLla2oQ7oFgUZdZhQZ1qsevYknxNq4eIcvPDjbon+bovfsIISEVRSNo2C3yjO+mqWKed3jfuCA4taAZ8/aVVFEKURMH10HFms1CiC3lE/gF4YfBXsqKpjnB+bKjBcWox2FQrp96FulMEIfkKQrnuncO96o7MGHX9oNqKSMoycf3+SZFwNa+5Mfq7SBepbHYCoU7/ow31UTyStrc5idG19XzYgI85yjQHdzQN299Xf0O8cGf9q9qAu7rS7JlM3ekR+3rZYO+OxNYTF8rcW1fYIj6GKcbsV8BvuhAVQRFOsk/ibcIb2N7rGVd/ZbU4HAk3RE1ywt+XowinpIHktu2PQUPDNpgRQwM6xqZHO/7s9r7oW0ULmZCMLZ9CMKNjKzrQ9wfh90+v+FiEiUKsaVj4cCwF3PvhVYvxU2AKbCeHtSEb7K6to86+DYNoIKnGH1ryKoyCtyOTZpNMLGFt34Msv7WfEylhG+DpVMvkM=
18
+ addons:
19
+ code_climate:
20
+ repo_token:
21
+ secure: B1l5OpGEPsAzThXW1UnojquRMH/oIO1QPd/sgB0y0ymwU6l6wAWPiN5/JwGNJPSl2h/EwrK2aTroP7fUsn7J5UcGh8yaerMwNKbUXo5/VNVfMz0ZVzNwaWPjMdDtuSolhabwPMPP1afdm2YT+IZwrid8zRjSB8/OsSPr0LCrciftVDiaN3XMfXMIheEOUokkH/X+m+PxZlYbL1v36D+CyhhulItnlEbhavK4fzN8bpkno2uK/IvLmheUeXCGvHdxhHE04mXYoEZGP87PCbV5vJ9hiFMXx9TiN2F51Z0Qr0F07MQY/l/svwpWUsnGRL3xaM58a/JxDG7Z/Qipt+4UId67xXSMmibHzW2kcJo71odS8rXUkwuxHuYFbHBQvBstjimc4YFfrth8YnVUnFIv/a3y8bE3+ESt++LRj2MlK6trisxOrCwJtDNJq5fJw6evdGOogTQ186oaBR8/6pPbmOrZHKc0aCrguWvVc3NHwD9oZNoPqKZ5vU/5RysDfx9dljfTR1BoMxjs0UN+nlMryFXRTyNgkk0YsLD3VrxjLNl6ykcO7nYgxiyuWOiXxTzGai5NU4ihbSFqpFeQ973iEnAGlnX2Uz32rX/ZPwJeqpVRZZkmZyUZo4cFjYa/yKwCTIgx3m2zAfV6VqwEs6USSq1OhEEKVgFw+rfo8Bw2cyw=
22
+ after_success:
23
+ - bundle exec codeclimate-test-reporter
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |_repo_name| 'https://github.com/kigster/register-rb' }
4
+
5
+ # Specify your gem's dependencies in register.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Konstantin Gredeskoul
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,99 @@
1
+ [![Build Status](https://travis-ci.org/kigster/register.svg?branch=master)](https://travis-ci.org/kigster/register)
2
+ [![Code Climate](https://codeclimate.com/github/kigster/register/badges/gpa.svg)](https://codeclimate.com/github/kigster/register)
3
+ [![Test Coverage](https://codeclimate.com/github/kigster/register/badges/coverage.svg)](https://codeclimate.com/github/kigster/register/coverage)
4
+ [![Issue Count](https://codeclimate.com/github/kigster/register/badges/issue_count.svg)](https://codeclimate.com/github/kigster/register)
5
+
6
+
7
+ # *Register* — A Module Method Factory Pattern
8
+
9
+ **Register** is a tiny library that can be included in a module that is to become a Façade to several application globals via auto-generated module-level methods.
10
+
11
+ A good example is a register of several connections to either *Redis* or *MemCached*, for example you might have a short-term memcached connection with a short default expiration TTL, and a longer-living one that requires sweeping to clean. You could use `Register` to wrap access to these singletons in `MyModule.cache_type` accessors.
12
+
13
+ ## Usage
14
+
15
+ ### Creating a Register
16
+
17
+ To create a register module, just include `Register` in any ruby module:
18
+
19
+ ```ruby
20
+ require 'register'
21
+
22
+ module Cache
23
+ include Register
24
+ end
25
+ ```
26
+
27
+ ### Storing Items in the Register
28
+
29
+ To add items to the register, call the `<<` method, passing an array of identifiers, followed by the actual item to store. In other words, the last items of the argument array is the actual item stored against each of the identifiers passed before it.
30
+
31
+ ```ruby
32
+
33
+ # Our "item" will be a simple cache store with a name:
34
+ CacheStore = Struct.new(:name)
35
+
36
+ # Register items associated with any one of the identifiers
37
+ Cache.register :planetary, :cosmic, CacheStore.new(:saturn)
38
+
39
+ # You can use << syntax which is an alias to #register, but
40
+ # then use << to append the actual item
41
+ Cache.<< %i[primary main rails deploy] << CacheStore.new(:primary)
42
+
43
+ Cache.<< %i[durable secondary] << CacheStore.new(:secondary)
44
+ ```
45
+
46
+ ### Looking up (Fetching) Items from the Register
47
+
48
+ There are two ways to fetch the previously-stored item:
49
+
50
+ 1. Using the `#for(:name)` method
51
+ 2. Using the auto-generated module-level accessor
52
+
53
+ In the first example, we would call `Cache.for(:planetary)` to fetch the cache store, while in the second case we would call `Cache.planetary` method, which provides additional guarantees: if the method is not there, something is definitely wrong.
54
+
55
+ ```ruby
56
+ Cache.planetary.name should eq(:saturn)
57
+ Cache.primary === Cache.main === Cache.rails === Cache.deploy
58
+ Cache.durable.name = 'DURABLE'
59
+ Cache.secondary.name # => 'DURABLE'
60
+ ```
61
+
62
+ Here is a more complete RSPec example:
63
+
64
+ ```ruby
65
+ require 'rspec'
66
+ require 'rspec/its'
67
+ RSpec.describe Cache do
68
+ subject(:cache) { Cache }
69
+ its(:planetary) { should eq CachStore.new(:saturn) }
70
+ its(:deploy) { should eq CachStore.new(:primary) }
71
+ its(:durable) { should eq CachStore.new(:secondary) }
72
+ it 'should also respond to #for' do
73
+ expect(cache.for(:secondary)).to eq(CacheStore(:secondary))
74
+ end
75
+ end
76
+ ```
77
+
78
+ ## Installation
79
+
80
+ gem install register
81
+
82
+ ## Note on Patches and Pull Requests
83
+
84
+ * Fork the project.
85
+ * Make your feature addition or bug fix.
86
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
87
+ * Commit, do not mess with rakefile, version, or history. If you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull.
88
+ * Send a pull request. Bonus points for topic branches.
89
+
90
+ ## Copyright
91
+
92
+ Copyright &copy; 2017 Konstantin Gredeskoul. See LICENSE for details.
93
+
94
+ ## Contributors
95
+
96
+ * [Konstantin Gredeskoul](https://github.com/kigster)
97
+
98
+
99
+
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'yard'
4
+
5
+ def shell(*args)
6
+ puts "running: #{args.join(' ')}"
7
+ system(args.join(' '))
8
+ end
9
+
10
+ task :permissions do
11
+ shell('rm -rf pkg/')
12
+ shell('chmod -v o+r,g+r * */* */*/* */*/*/* */*/*/*/* */*/*/*/*/*')
13
+ shell('chmod -v o+x,g+x exe/* bin/*')
14
+ shell("find . -type d -exec chmod o+x,g+x {} \\;")
15
+ end
16
+
17
+ task :build => :permissions
18
+
19
+ YARD::Rake::YardocTask.new(:doc) do |t|
20
+ t.files = %w(lib/**/*.rb exe/*.rb - README.md LICENSE)
21
+ t.options.unshift('--title','Register - An easy way to create Mudule-level accessors to global resources')
22
+ t.after = ->() { exec('open doc/index.html') }
23
+ end
24
+
25
+ RSpec::Core::RakeTask.new(:spec)
26
+
27
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "register"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/register.rb ADDED
@@ -0,0 +1,76 @@
1
+ require 'register/version'
2
+ require 'colored2'
3
+ module Register
4
+ class RegisterError < StandardError; end
5
+ class AlreadyRegisteredError < RegisterError; end
6
+ class NoSuchIdentifierError < RegisterError; end
7
+ class ReservedIdentifierError < RegisterError; end
8
+
9
+ module DummyModule
10
+ end
11
+
12
+ RESERVED = (DummyModule.methods << %i[for register << add_method]).flatten!.freeze
13
+
14
+ def self.included(klass)
15
+ klass.instance_eval do
16
+ @store = Hash.new
17
+ @mutex = Mutex.new
18
+ class << self
19
+ attr_accessor :store, :mutex
20
+ def <<(*names, &block)
21
+ names.flatten!
22
+ item = block ? yield(self) : names.pop
23
+ validate_existing_keys!(names)
24
+ validate_reserved_keys!(names)
25
+ names.each do |n|
26
+ store[n] = item
27
+ add_method(n)
28
+ end
29
+ end
30
+
31
+ alias register <<
32
+
33
+ def for(id)
34
+ unless store.key?(id)
35
+ raise NoSuchIdentifierError,
36
+ "No identifier #{id} found in the registry"
37
+ end
38
+ store[id]
39
+ end
40
+
41
+ private
42
+
43
+ def add_method(id)
44
+ return unless id.is_a?(Symbol)
45
+ @mutex.synchronize do
46
+ unless self.respond_to?(id)
47
+ line_no = __LINE__
48
+ method_defs = %Q!
49
+ def self.#{id}
50
+ store[:#{id}]
51
+ end\n!
52
+ module_eval method_defs, __FILE__, line_no
53
+ end
54
+ end
55
+ end
56
+
57
+ def validate_reserved_keys!(names)
58
+ reserved = names.select { |n| RESERVED.include?(n) }
59
+ unless reserved.empty?
60
+ raise ReservedIdentifierError, "The following keys are reserved and can not be used: #{reserved}"
61
+ end
62
+ end
63
+
64
+ def validate_existing_keys!(names)
65
+ already = names.select { |n| store.key?(n) }
66
+ unless already.empty?
67
+ raise AlreadyRegisteredError, "The following keys are already in the registry: #{already}"
68
+ end
69
+ end
70
+
71
+
72
+ end
73
+ end
74
+ end
75
+ end
76
+
@@ -0,0 +1,3 @@
1
+ module Register
2
+ VERSION = '0.5.3'.freeze
3
+ end
data/register.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'register/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'register'
8
+ spec.version = Register::VERSION
9
+ spec.authors = ['Konstantin Gredeskoul']
10
+ spec.email = ['kigster@gmail.com']
11
+
12
+ spec.summary = %q{This is a simple module-level registry for application globals. Use it to wrap global connection pools, memcached connections, redis, even database connections, and register them within a top-level namespace module of your application. For example, instead of doing Rails.cache you could be doing MyApp.rails_cache or MyApp.redis_cache, etc.}
13
+ spec.description = %q{This is a simple module-level registry for application globals. Use it to wrap global connection pools, memcached connections, redis, even database connections, and register them within a top-level namespace module of your application. For example, instead of doing Rails.cache you could be doing MyApp.rails_cache or MyApp.redis_cache, etc.}
14
+ spec.homepage = 'https://github.com/kigster/register'
15
+ spec.license = 'MIT'
16
+ spec.files = `git ls-files`.split($\).reject{ |f| f.match(%r{^(doc|spec|coverage|pkg)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'simplecov'
22
+ spec.add_development_dependency 'codeclimate-test-reporter'
23
+ spec.add_development_dependency 'colored2'
24
+ spec.add_development_dependency 'yard'
25
+ spec.add_development_dependency 'awesome_print'
26
+ spec.add_development_dependency 'bundler', '~> 1.15'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
+ spec.add_development_dependency 'rspec-its'
30
+ end
metadata ADDED
@@ -0,0 +1,192 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: register
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.3
5
+ platform: ruby
6
+ authors:
7
+ - Konstantin Gredeskoul
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: simplecov
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: codeclimate-test-reporter
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: colored2
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
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: awesome_print
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.15'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.15'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec-its
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: This is a simple module-level registry for application globals. Use it
140
+ to wrap global connection pools, memcached connections, redis, even database connections,
141
+ and register them within a top-level namespace module of your application. For example,
142
+ instead of doing Rails.cache you could be doing MyApp.rails_cache or MyApp.redis_cache,
143
+ etc.
144
+ email:
145
+ - kigster@gmail.com
146
+ executables: []
147
+ extensions: []
148
+ extra_rdoc_files: []
149
+ files:
150
+ - ".codeclimate.yml"
151
+ - ".gitignore"
152
+ - ".rspec"
153
+ - ".rubocop.yml"
154
+ - ".travis.yml"
155
+ - Gemfile
156
+ - LICENSE.txt
157
+ - README.md
158
+ - Rakefile
159
+ - bin/console
160
+ - bin/setup
161
+ - lib/register.rb
162
+ - lib/register/version.rb
163
+ - register.gemspec
164
+ homepage: https://github.com/kigster/register
165
+ licenses:
166
+ - MIT
167
+ metadata: {}
168
+ post_install_message:
169
+ rdoc_options: []
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ requirements: []
183
+ rubyforge_project:
184
+ rubygems_version: 2.6.11
185
+ signing_key:
186
+ specification_version: 4
187
+ summary: This is a simple module-level registry for application globals. Use it to
188
+ wrap global connection pools, memcached connections, redis, even database connections,
189
+ and register them within a top-level namespace module of your application. For example,
190
+ instead of doing Rails.cache you could be doing MyApp.rails_cache or MyApp.redis_cache,
191
+ etc.
192
+ test_files: []