dry-core 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.inch.yml +4 -0
- data/.rspec +3 -0
- data/.rubocop.yml +31 -0
- data/.travis.yml +31 -0
- data/CHANGELOG.md +153 -0
- data/CONTRIBUTING.md +29 -0
- data/Gemfile +22 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +6 -0
- data/dry-core.gemspec +34 -0
- data/lib/dry-core.rb +1 -0
- data/lib/dry/core.rb +8 -0
- data/lib/dry/core/cache.rb +66 -0
- data/lib/dry/core/class_attributes.rb +83 -0
- data/lib/dry/core/class_builder.rb +105 -0
- data/lib/dry/core/constants.rb +77 -0
- data/lib/dry/core/deprecations.rb +224 -0
- data/lib/dry/core/descendants_tracker.rb +76 -0
- data/lib/dry/core/errors.rb +11 -0
- data/lib/dry/core/extensions.rb +61 -0
- data/lib/dry/core/inflector.rb +138 -0
- data/lib/dry/core/memoizable.rb +68 -0
- data/lib/dry/core/version.rb +5 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 74e2816087ba373bcfd55f8e216ef6708e1e70b0930020d71518385190460537
|
4
|
+
data.tar.gz: 19eb04ff0972c2b928e455ff7345c93caed587af56ea8089a5433eb471a624b3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c1949faf46146ee0bb734aec09350b864ba414105ad7ceef4dad476b3667f4d14c0474c84da28fdf293e651da9a7a26119501548d6512eeed42e5e1296270d12
|
7
|
+
data.tar.gz: ffa845da4bf5da3f5b370f6093721d4c7689bde90da3b4a58f17954807fc9fe0f7065997b7bebee46e6eed2525bd181c042fe550ffa1b4557fa9cf95ee6eae47
|
data/.gitignore
ADDED
data/.inch.yml
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.1
|
3
|
+
Exclude:
|
4
|
+
- 'dry-core.gemspec'
|
5
|
+
- 'spec/spec_helper.rb'
|
6
|
+
|
7
|
+
Style/SignalException:
|
8
|
+
Exclude:
|
9
|
+
- 'spec/**/*'
|
10
|
+
|
11
|
+
Style/RedundantSelf:
|
12
|
+
Exclude:
|
13
|
+
- 'lib/dry/core/deprecations.rb'
|
14
|
+
|
15
|
+
Metrics/LineLength:
|
16
|
+
Max: 110
|
17
|
+
|
18
|
+
Metrics/MethodLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Style/FileName:
|
22
|
+
Exclude:
|
23
|
+
- 'lib/dry-core.rb'
|
24
|
+
|
25
|
+
Lint/AmbiguousRegexpLiteral:
|
26
|
+
Exclude:
|
27
|
+
- 'spec/**/*'
|
28
|
+
|
29
|
+
Style/BlockDelimiters:
|
30
|
+
Exclude:
|
31
|
+
- 'spec/**/*'
|
data/.travis.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
language: ruby
|
2
|
+
dist: trusty
|
3
|
+
sudo: required
|
4
|
+
cache: bundler
|
5
|
+
bundler_args: --without benchmarks tools
|
6
|
+
after_success:
|
7
|
+
- '[ -d coverage ] && bundle exec codeclimate-test-reporter'
|
8
|
+
script:
|
9
|
+
- bundle exec rake
|
10
|
+
before_install:
|
11
|
+
- gem update --system
|
12
|
+
after_success:
|
13
|
+
- '[ -d coverage ] && bundle exec codeclimate-test-reporter'
|
14
|
+
rvm:
|
15
|
+
- 2.2.9
|
16
|
+
- 2.3.6
|
17
|
+
- 2.4.3
|
18
|
+
- 2.5.0
|
19
|
+
- jruby-9.1.15.0
|
20
|
+
env:
|
21
|
+
global:
|
22
|
+
- COVERAGE=true
|
23
|
+
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
24
|
+
notifications:
|
25
|
+
email: false
|
26
|
+
webhooks:
|
27
|
+
urls:
|
28
|
+
- https://webhooks.gitter.im/e/19098b4253a72c9796db
|
29
|
+
on_success: change # options: [always|never|change] default: always
|
30
|
+
on_failure: always # options: [always|never|change] default: always
|
31
|
+
on_start: false # default: false
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
# v0.4.7 2018-06-25
|
2
|
+
|
3
|
+
### Fixed
|
4
|
+
|
5
|
+
* Fix default logger for deprecations, it now uses `$stderr` by default, as it should (flash-gordon)
|
6
|
+
|
7
|
+
[Compare v0.4.6...v0.4.7](https://github.com/dry-rb/dry-core/compare/v0.4.6...v0.4.7)
|
8
|
+
|
9
|
+
# v0.4.6 2018-05-15
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
* Trigger constant autoloading in the class builder (radar)
|
14
|
+
|
15
|
+
[Compare v0.4.5...v0.4.6](https://github.com/dry-rb/dry-core/compare/v0.4.5...v0.4.6)
|
16
|
+
|
17
|
+
# v0.4.5 2018-03-14
|
18
|
+
|
19
|
+
### Added
|
20
|
+
|
21
|
+
* `Dry::Core::Memoizable`, which provides a `memoize` macro for memoizing results of instance methods (timriley)
|
22
|
+
|
23
|
+
[Compare v0.4.4...v0.4.5](https://github.com/dry-rb/dry-core/compare/v0.4.4...v0.4.5)
|
24
|
+
|
25
|
+
# v0.4.4 2018-02-10
|
26
|
+
|
27
|
+
### Added
|
28
|
+
|
29
|
+
* `deprecate_constant` overrides `Module#deprecate_constant` and issues a labeled message on accessing a deprecated constant (flash-gordon)
|
30
|
+
* `Undefined.default` which accepts two arguments and returns the first if it's not `Undefined`; otherwise, returns the second one or yields a block (flash-gordon)
|
31
|
+
|
32
|
+
[Compare v0.4.3...v0.4.4](https://github.com/dry-rb/dry-core/compare/v0.4.3...v0.4.4)
|
33
|
+
|
34
|
+
# v0.4.3 2018-02-03
|
35
|
+
|
36
|
+
### Added
|
37
|
+
|
38
|
+
* `Dry::Core::DescendantsTracker` which is a maintained version of the [`descendants_tracker`](https://github.com/dkubb/descendants_tracker) gem (flash-gordon)
|
39
|
+
|
40
|
+
[Compare v0.4.2...v0.4.3](https://github.com/dry-rb/dry-core/compare/v0.4.2...0.4.3)
|
41
|
+
|
42
|
+
# v0.4.2 2017-12-16
|
43
|
+
|
44
|
+
### Fixed
|
45
|
+
|
46
|
+
* Class attributes now support private setters/getters (flash-gordon)
|
47
|
+
|
48
|
+
[Compare v0.4.1...v0.4.2](https://github.com/dry-rb/dry-core/compare/v0.4.1...v0.4.2)
|
49
|
+
|
50
|
+
# v0.4.1 2017-11-04
|
51
|
+
|
52
|
+
### Changed
|
53
|
+
|
54
|
+
* Improved error message on invalid attribute value (GustavoCaso)
|
55
|
+
|
56
|
+
[Compare v0.4.0...v0.4.1](https://github.com/dry-rb/dry-core/compare/v0.4.0...v0.4.1)
|
57
|
+
|
58
|
+
# v0.4.0 2017-11-02
|
59
|
+
|
60
|
+
### Added
|
61
|
+
|
62
|
+
* Added the `:type` option to class attributes, you can now restrict attribute values with a type. You can either use plain ruby types (`Integer`, `String`, etc) or `dry-types` (GustavoCaso)
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
class Foo
|
66
|
+
extend Dry::Core::ClassAttributes
|
67
|
+
|
68
|
+
defines :ruby_attr, type: Integer
|
69
|
+
defines :dry_attr, type: Dry::Types['strict.int']
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
[Compare v0.3.4...v0.4.0](https://github.com/dry-rb/dry-core/compare/v0.3.4...v0.4.0)
|
74
|
+
|
75
|
+
# v0.3.4 2017-09-29
|
76
|
+
|
77
|
+
### Fixed
|
78
|
+
|
79
|
+
* `Deprecations` output is set to `$stderr` by default now (solnic)
|
80
|
+
|
81
|
+
[Compare v0.3.3...v0.3.4](https://github.com/dry-rb/dry-core/compare/v0.3.3...v0.3.4)
|
82
|
+
|
83
|
+
# v0.3.3 2017-08-31
|
84
|
+
|
85
|
+
### Fixed
|
86
|
+
|
87
|
+
* The Deprecations module now shows the right caller line (flash-gordon)
|
88
|
+
|
89
|
+
[Compare v0.3.2...v0.3.3](https://github.com/dry-rb/dry-core/compare/v0.3.2...v0.3.3)
|
90
|
+
|
91
|
+
# v0.3.2 2017-08-31
|
92
|
+
|
93
|
+
### Added
|
94
|
+
|
95
|
+
* Accept an existing logger object in `Dry::Core::Deprecations.set_logger!` (flash-gordon)
|
96
|
+
|
97
|
+
[Compare v0.3.1...v0.3.2](https://github.com/dry-rb/dry-core/compare/v0.3.1...v0.3.2)
|
98
|
+
|
99
|
+
# v0.3.1 2017-05-27
|
100
|
+
|
101
|
+
### Added
|
102
|
+
|
103
|
+
* Support for building classes within an existing namespace (flash-gordon)
|
104
|
+
|
105
|
+
[Compare v0.3.0...v0.3.1](https://github.com/dry-rb/dry-core/compare/v0.3.0...v0.3.1)
|
106
|
+
|
107
|
+
# v0.3.0 2017-05-05
|
108
|
+
|
109
|
+
### Changed
|
110
|
+
|
111
|
+
* Class attributes are initialized _before_ running the `inherited` hook. It's slightly more convenient behavior and it's very unlikely anyone will be affected by this, but technically this is a breaking change (flash-gordon)
|
112
|
+
|
113
|
+
[Compare v0.2.4...v0.3.0](https://github.com/dry-rb/dry-core/compare/v0.2.4...v0.3.0)
|
114
|
+
|
115
|
+
# v0.2.4 2017-01-26
|
116
|
+
|
117
|
+
### Fixed
|
118
|
+
|
119
|
+
* Do not require deprecated method to be defined (flash-gordon)
|
120
|
+
|
121
|
+
[Compare v0.2.3...v0.2.4](https://github.com/dry-rb/dry-core/compare/v0.2.3...v0.2.4)
|
122
|
+
|
123
|
+
# v0.2.3 2016-12-30
|
124
|
+
|
125
|
+
### Fixed
|
126
|
+
|
127
|
+
* Fix warnings on using uninitialized class attributes (flash-gordon)
|
128
|
+
|
129
|
+
[Compare v0.2.2...v0.2.3](https://github.com/dry-rb/dry-core/compare/v0.2.2...v0.2.3)
|
130
|
+
|
131
|
+
# v0.2.2 2016-12-30
|
132
|
+
|
133
|
+
### Added
|
134
|
+
|
135
|
+
* `ClassAttributes` which provides `defines` method for defining get-or-set methods (flash-gordon)
|
136
|
+
|
137
|
+
[Compare v0.2.1...v0.2.2](https://github.com/dry-rb/dry-core/compare/v0.2.1...v0.2.2)
|
138
|
+
|
139
|
+
# v0.2.1 2016-11-18
|
140
|
+
|
141
|
+
### Added
|
142
|
+
|
143
|
+
* `Constants` are now available in nested scopes (flash-gordon)
|
144
|
+
|
145
|
+
[Compare v0.2.0...v0.2.1](https://github.com/dry-rb/dry-core/compare/v0.2.0...v0.2.1)
|
146
|
+
|
147
|
+
# v0.2.0 2016-11-01
|
148
|
+
|
149
|
+
[Compare v0.1.0...v0.2.0](https://github.com/dry-rb/dry-core/compare/v0.1.0...v0.2.0)
|
150
|
+
|
151
|
+
# v0.1.0 2016-09-17
|
152
|
+
|
153
|
+
Initial release
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Issue Guidelines
|
2
|
+
|
3
|
+
## Reporting bugs
|
4
|
+
|
5
|
+
If you found a bug, report an issue and describe what's the expected behavior versus what actually happens. If the bug causes a crash, attach a full backtrace. If possible, a reproduction script showing the problem is highly appreciated.
|
6
|
+
|
7
|
+
## Reporting feature requests
|
8
|
+
|
9
|
+
Report a feature request **only after discourseing it first on [discourse.dry-rb.org](https://discourse.dry-rb.org)** where it was accepted. Please provide a concise description of the feature, don't link to a discourseion thread, and instead summarize what was discourseed.
|
10
|
+
|
11
|
+
## Reporting questions, support requests, ideas, concerns etc.
|
12
|
+
|
13
|
+
**PLEASE DON'T** - use [discourse.dry-rb.org](https://discourse.dry-rb.org) instead.
|
14
|
+
|
15
|
+
# Pull Request Guidelines
|
16
|
+
|
17
|
+
A Pull Request will only be accepted if it addresses a specific issue that was reported previously, or fixes typos, mistakes in documentation etc.
|
18
|
+
|
19
|
+
Other requirements:
|
20
|
+
|
21
|
+
1) Do not open a pull request if you can't provide tests along with it. If you have problems writing tests, ask for help in the related issue.
|
22
|
+
2) Follow the style conventions of the surrounding code. In most cases, this is standard ruby style.
|
23
|
+
3) Add API documentation if it's a new feature
|
24
|
+
4) Update API documentation if it changes an existing feature
|
25
|
+
5) Bonus points for sending a PR to [github.com/dry-rb/dry-rb.org](github.com/dry-rb/dry-rb.org) which updates user documentation and guides
|
26
|
+
|
27
|
+
# Asking for help
|
28
|
+
|
29
|
+
If these guidelines aren't helpful, and you're stuck, please post a message on [discourse.dry-rb.org](https://discourse.dry-rb.org).
|
data/Gemfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
group :test do
|
6
|
+
if RUBY_VERSION >= '2.4'
|
7
|
+
gem 'activesupport'
|
8
|
+
else
|
9
|
+
gem 'activesupport', '~> 4.2'
|
10
|
+
end
|
11
|
+
gem 'inflecto', '~> 0.0', '>= 0.0.2'
|
12
|
+
gem 'codeclimate-test-reporter', require: false
|
13
|
+
gem 'simplecov', require: false
|
14
|
+
gem 'dry-types'
|
15
|
+
gem 'dry-inflector', git: 'https://github.com/dry-rb/dry-inflector', branch: 'master'
|
16
|
+
end
|
17
|
+
|
18
|
+
group :tools do
|
19
|
+
gem 'pry-byebug', platform: :mri
|
20
|
+
gem 'pry', platform: :jruby
|
21
|
+
gem 'rubocop'
|
22
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Nikita Shilnikov
|
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,47 @@
|
|
1
|
+
[gitter]: https://gitter.im/dry-rb/chat
|
2
|
+
[gem]: https://rubygems.org/gems/dry-core
|
3
|
+
[travis]: https://travis-ci.org/dry-rb/dry-core
|
4
|
+
[code_climate]: https://codeclimate.com/github/dry-rb/dry-core
|
5
|
+
[inch]: http://inch-ci.org/github/dry-rb/dry-core
|
6
|
+
|
7
|
+
# dry-core
|
8
|
+
|
9
|
+
[![Gem Version](https://img.shields.io/gem/v/dry-core.svg)][gem]
|
10
|
+
[![Build Status](https://img.shields.io/travis/dry-rb/dry-core.svg)][travis]
|
11
|
+
[![Code Climate](https://api.codeclimate.com/v1/badges/eebb0e969814744231e4/maintainability)][code_climate]
|
12
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/eebb0e969814744231e4/test_coverage)][code_climate]
|
13
|
+
[![API Documentation Coverage](http://inch-ci.org/github/dry-rb/dry-core.svg)][inch]
|
14
|
+
![No monkey-patches](https://img.shields.io/badge/monkey--patches-0-brightgreen.svg)
|
15
|
+
|
16
|
+
A collection of small modules used in the dry-rb ecosystem.
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem 'dry-core'
|
24
|
+
```
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
$ bundle
|
29
|
+
|
30
|
+
Or install it yourself as:
|
31
|
+
|
32
|
+
$ gem install dry-core
|
33
|
+
|
34
|
+
## Development
|
35
|
+
|
36
|
+
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.
|
37
|
+
|
38
|
+
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).
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dry-rb/dry-core.
|
43
|
+
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/dry-core.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'dry/core/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'dry-core'
|
7
|
+
spec.version = Dry::Core::VERSION
|
8
|
+
spec.authors = ['Nikita Shilnikov']
|
9
|
+
spec.email = ['fg@flashgordon.ru']
|
10
|
+
|
11
|
+
spec.summary = 'A toolset of small support modules used throughout the dry-rb ecosystem.'
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = 'https://github.com/dry-rb/dry-core'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
20
|
+
else
|
21
|
+
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|bin)/}) }
|
25
|
+
spec.bindir = 'exe'
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
spec.required_ruby_version = '>= 2.1.0'
|
29
|
+
spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
|
30
|
+
|
31
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
32
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
33
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
34
|
+
end
|
data/lib/dry-core.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'dry/core'
|
data/lib/dry/core.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'concurrent/map'
|
2
|
+
|
3
|
+
module Dry
|
4
|
+
module Core
|
5
|
+
# Allows you to cache call results that are solely determined by arguments.
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# require 'dry/core/cache'
|
9
|
+
#
|
10
|
+
# class Foo
|
11
|
+
# extend Dry::Core::Cache
|
12
|
+
#
|
13
|
+
# def heavy_computation(arg1, arg2)
|
14
|
+
# fetch_or_store(arg1, arg2) { arg1 ^ arg2 }
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# @api public
|
19
|
+
module Cache
|
20
|
+
# @api private
|
21
|
+
def self.extended(klass)
|
22
|
+
super
|
23
|
+
klass.include(Methods)
|
24
|
+
klass.instance_variable_set(:@__cache__, Concurrent::Map.new)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @api private
|
28
|
+
def inherited(klass)
|
29
|
+
super
|
30
|
+
klass.instance_variable_set(:@__cache__, cache)
|
31
|
+
end
|
32
|
+
|
33
|
+
# @api private
|
34
|
+
def cache
|
35
|
+
@__cache__
|
36
|
+
end
|
37
|
+
|
38
|
+
# Caches a result of the block evaluation
|
39
|
+
#
|
40
|
+
# @param [Array<Object>] args List of hashable objects
|
41
|
+
# @yield An arbitrary block
|
42
|
+
#
|
43
|
+
# @note beware Proc instance hashes are not equal, i.e. -> { 1 }.hash != -> { 1 }.hash,
|
44
|
+
# this means you shouldn't pass Procs in args unless you're sure
|
45
|
+
# they are always the same instances, otherwise you introduce a memory leak
|
46
|
+
#
|
47
|
+
# @return [Object] block's return value (cached for subsequent calls with the same argument values)
|
48
|
+
def fetch_or_store(*args, &block)
|
49
|
+
cache.fetch_or_store(args.hash, &block)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Instance methods
|
53
|
+
module Methods
|
54
|
+
# Delegates call to the class-level method
|
55
|
+
#
|
56
|
+
# @param [Array<Object>] args List of hashable objects
|
57
|
+
# @yield An arbitrary block
|
58
|
+
#
|
59
|
+
# @return [Object] block's return value
|
60
|
+
def fetch_or_store(*args, &block)
|
61
|
+
self.class.fetch_or_store(*args, &block)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|