currentable 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/lib/currentable/auto_cleaner.rb +15 -0
- data/lib/currentable/cleaner.rb +14 -0
- data/lib/currentable/instance.rb +27 -0
- data/lib/currentable/railtie.rb +9 -0
- data/lib/currentable/registry.rb +24 -0
- data/lib/currentable/version.rb +3 -0
- data/lib/currentable.rb +11 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 507a8189752407fb3beb69d7ea63a6c39815c6aa
|
4
|
+
data.tar.gz: d9d9f05faacbe82b0da483f6f2cc3ca8606e90b2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5a11ad3bb18de07c1eefb55ce28bea8073a95abd232acc5e7f976435114ce72b8890f34bb30285c223faf93205346d5ec77401658aa1e4691f90eee9bad0984c
|
7
|
+
data.tar.gz: e827013b5bd1feddbf949f92ed5c0f75c8e194cdc8539c0534c8ae7bc39001d59b7d7a7d9685b50eb80fd1ff2c9d85c83e1b907008f7cccb5fcac19eb6730040
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Currentable
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/currentable`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'currentable'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install currentable
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/currentable.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Currentable
|
2
|
+
class Cleaner
|
3
|
+
class << self
|
4
|
+
def clean_all
|
5
|
+
Currentable::Registry.currents.each do |klass|
|
6
|
+
if defined? ::Rails
|
7
|
+
Rails.logger.debug "Cleaning current for #{klass}"
|
8
|
+
end
|
9
|
+
klass.current = nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'registry'
|
2
|
+
|
3
|
+
module Currentable
|
4
|
+
module Instance
|
5
|
+
def self.included(klass)
|
6
|
+
super
|
7
|
+
|
8
|
+
klass.extend(ClassMethods)
|
9
|
+
|
10
|
+
Currentable::Registry.register_current(klass)
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def current=(current)
|
15
|
+
Thread.current[current_identifier] = current
|
16
|
+
end
|
17
|
+
|
18
|
+
def current
|
19
|
+
Thread.current[current_identifier]
|
20
|
+
end
|
21
|
+
|
22
|
+
def current_identifier
|
23
|
+
"current.#{name}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Currentable
|
2
|
+
class Registry
|
3
|
+
MUTEX = Mutex.new
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def register_current(klass)
|
7
|
+
MUTEX.synchronize do
|
8
|
+
_currents.add(klass)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def currents
|
13
|
+
MUTEX.synchronize { _currents }
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def _currents
|
19
|
+
@currents ||= Set.new
|
20
|
+
@currents
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/currentable.rb
ADDED
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: currentable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maddie Schipper
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-07 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Track Current Objects
|
70
|
+
email:
|
71
|
+
- me@maddiesch.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- README.md
|
77
|
+
- Rakefile
|
78
|
+
- lib/currentable.rb
|
79
|
+
- lib/currentable/auto_cleaner.rb
|
80
|
+
- lib/currentable/cleaner.rb
|
81
|
+
- lib/currentable/instance.rb
|
82
|
+
- lib/currentable/railtie.rb
|
83
|
+
- lib/currentable/registry.rb
|
84
|
+
- lib/currentable/version.rb
|
85
|
+
homepage: https://github.com/maddiesch/currentable
|
86
|
+
licenses: []
|
87
|
+
metadata:
|
88
|
+
homepage_uri: https://github.com/maddiesch/currentable
|
89
|
+
source_code_uri: https://github.com/maddiesch/currentable
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.5.2.3
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Track Current Objects
|
110
|
+
test_files: []
|