dry-core 0.4.7 → 0.6.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +162 -43
- data/LICENSE +20 -0
- data/README.md +18 -36
- data/dry-core.gemspec +31 -28
- data/lib/dry-core.rb +3 -1
- data/lib/dry/core.rb +3 -1
- data/lib/dry/core/cache.rb +3 -1
- data/lib/dry/core/class_attributes.rb +32 -10
- data/lib/dry/core/class_builder.rb +3 -3
- data/lib/dry/core/constants.rb +52 -12
- data/lib/dry/core/deprecations.rb +23 -14
- data/lib/dry/core/descendants_tracker.rb +3 -1
- data/lib/dry/core/equalizer.rb +151 -0
- data/lib/dry/core/errors.rb +2 -0
- data/lib/dry/core/extensions.rb +3 -1
- data/lib/dry/core/inflector.rb +6 -3
- data/lib/dry/core/memoizable.rb +75 -35
- data/lib/dry/core/version.rb +3 -1
- metadata +25 -30
- data/.gitignore +0 -10
- data/.inch.yml +0 -4
- data/.rspec +0 -3
- data/.rubocop.yml +0 -31
- data/.travis.yml +0 -31
- data/CONTRIBUTING.md +0 -29
- data/Gemfile +0 -22
- data/LICENSE.txt +0 -21
- data/Rakefile +0 -6
data/lib/dry/core/errors.rb
CHANGED
data/lib/dry/core/extensions.rb
CHANGED
data/lib/dry/core/inflector.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Dry
|
2
4
|
module Core
|
3
5
|
# Helper module providing thin interface around an inflection backend.
|
@@ -5,15 +7,15 @@ module Dry
|
|
5
7
|
# List of supported backends
|
6
8
|
BACKENDS = {
|
7
9
|
activesupport: [
|
8
|
-
|
10
|
+
"active_support/inflector",
|
9
11
|
proc { ::ActiveSupport::Inflector }
|
10
12
|
],
|
11
13
|
dry_inflector: [
|
12
|
-
|
14
|
+
"dry/inflector",
|
13
15
|
proc { Dry::Inflector.new }
|
14
16
|
],
|
15
17
|
inflecto: [
|
16
|
-
|
18
|
+
"inflecto",
|
17
19
|
proc { ::Inflecto }
|
18
20
|
]
|
19
21
|
}.freeze
|
@@ -47,6 +49,7 @@ module Dry
|
|
47
49
|
if name && !BACKENDS.key?(name)
|
48
50
|
raise NameError, "Invalid inflector library selection: '#{name}'"
|
49
51
|
end
|
52
|
+
|
50
53
|
@inflector = name ? realize_backend(*BACKENDS[name]) : detect_backend
|
51
54
|
end
|
52
55
|
|
data/lib/dry/core/memoizable.rb
CHANGED
@@ -1,67 +1,107 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Dry
|
2
4
|
module Core
|
3
5
|
module Memoizable
|
4
6
|
MEMOIZED_HASH = {}.freeze
|
5
7
|
|
6
8
|
module ClassInterface
|
7
|
-
|
8
|
-
|
9
|
+
module Base
|
10
|
+
def memoize(*names)
|
11
|
+
prepend(Memoizer.new(self, names))
|
12
|
+
end
|
9
13
|
end
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
+
module BasicObject
|
16
|
+
include Base
|
17
|
+
|
18
|
+
def new(*)
|
19
|
+
obj = super
|
20
|
+
obj.instance_eval { @__memoized__ = MEMOIZED_HASH.dup }
|
21
|
+
obj
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Object
|
26
|
+
include Base
|
27
|
+
|
28
|
+
def new(*)
|
29
|
+
obj = super
|
30
|
+
obj.instance_variable_set(:'@__memoized__', MEMOIZED_HASH.dup)
|
31
|
+
obj
|
32
|
+
end
|
33
|
+
|
34
|
+
if respond_to?(:ruby2_keywords, true)
|
35
|
+
ruby2_keywords(:new)
|
36
|
+
end
|
15
37
|
end
|
16
38
|
end
|
17
39
|
|
18
40
|
def self.included(klass)
|
19
41
|
super
|
20
|
-
klass.extend(ClassInterface)
|
21
|
-
end
|
22
42
|
|
23
|
-
|
43
|
+
if klass <= Object
|
44
|
+
klass.extend(ClassInterface::Object)
|
45
|
+
else
|
46
|
+
klass.extend(ClassInterface::BasicObject)
|
47
|
+
end
|
48
|
+
end
|
24
49
|
|
25
50
|
# @api private
|
26
51
|
class Memoizer < Module
|
27
|
-
attr_reader :klass
|
28
|
-
attr_reader :names
|
29
|
-
|
30
52
|
# @api private
|
31
53
|
def initialize(klass, names)
|
32
|
-
|
33
|
-
|
34
|
-
|
54
|
+
names.each do |name|
|
55
|
+
define_memoizable(
|
56
|
+
method: klass.instance_method(name)
|
57
|
+
)
|
58
|
+
end
|
35
59
|
end
|
36
60
|
|
37
61
|
private
|
38
62
|
|
39
63
|
# @api private
|
40
|
-
def
|
41
|
-
|
42
|
-
|
64
|
+
def define_memoizable(method:)
|
65
|
+
module_eval <<~RUBY, __FILE__, __LINE__ + 1
|
66
|
+
def #{method.name}(#{to_declaration(method.parameters)})
|
67
|
+
key = [Kernel.__method__] + Kernel.local_variables.map { |var| Kernel.eval(var.to_s) }
|
43
68
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
if __memoized__.key?(name_with_args)
|
49
|
-
__memoized__[name_with_args]
|
50
|
-
else
|
51
|
-
__memoized__[name_with_args] = super(*args)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
else
|
55
|
-
define_method(name) do
|
56
|
-
if __memoized__.key?(name)
|
57
|
-
__memoized__[name]
|
58
|
-
else
|
59
|
-
__memoized__[name] = super()
|
60
|
-
end
|
69
|
+
if @__memoized__.key?(key)
|
70
|
+
@__memoized__[key]
|
71
|
+
else
|
72
|
+
@__memoized__[key] = super
|
61
73
|
end
|
62
74
|
end
|
75
|
+
RUBY
|
76
|
+
|
77
|
+
if respond_to?(:ruby2_keywords, true)
|
78
|
+
ruby2_keywords(method.name)
|
63
79
|
end
|
64
80
|
end
|
81
|
+
|
82
|
+
# @api private
|
83
|
+
def to_declaration(params, lookup = params.to_h)
|
84
|
+
params.map do |type, name|
|
85
|
+
case type
|
86
|
+
when :req
|
87
|
+
name
|
88
|
+
when :rest
|
89
|
+
"*#{name}"
|
90
|
+
when :keyreq
|
91
|
+
"#{name}:"
|
92
|
+
when :keyrest
|
93
|
+
"**#{name}"
|
94
|
+
when :block
|
95
|
+
"&#{name}"
|
96
|
+
when :opt
|
97
|
+
lookup.key?(:rest) ? nil : "*args"
|
98
|
+
when :key
|
99
|
+
lookup.key?(:keyrest) ? nil : "**kwargs"
|
100
|
+
else
|
101
|
+
raise NotImplementedError, "type: #{type}, name: #{name}"
|
102
|
+
end
|
103
|
+
end.compact.join(", ")
|
104
|
+
end
|
65
105
|
end
|
66
106
|
end
|
67
107
|
end
|
data/lib/dry/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Shilnikov
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -28,62 +28,54 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
69
|
-
description: A toolset of small support modules used throughout the dry-rb ecosystem
|
68
|
+
version: '0'
|
69
|
+
description: A toolset of small support modules used throughout the dry-rb ecosystem
|
70
70
|
email:
|
71
71
|
- fg@flashgordon.ru
|
72
72
|
executables: []
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- ".gitignore"
|
77
|
-
- ".inch.yml"
|
78
|
-
- ".rspec"
|
79
|
-
- ".rubocop.yml"
|
80
|
-
- ".travis.yml"
|
81
76
|
- CHANGELOG.md
|
82
|
-
-
|
83
|
-
- Gemfile
|
84
|
-
- LICENSE.txt
|
77
|
+
- LICENSE
|
85
78
|
- README.md
|
86
|
-
- Rakefile
|
87
79
|
- dry-core.gemspec
|
88
80
|
- lib/dry-core.rb
|
89
81
|
- lib/dry/core.rb
|
@@ -93,16 +85,20 @@ files:
|
|
93
85
|
- lib/dry/core/constants.rb
|
94
86
|
- lib/dry/core/deprecations.rb
|
95
87
|
- lib/dry/core/descendants_tracker.rb
|
88
|
+
- lib/dry/core/equalizer.rb
|
96
89
|
- lib/dry/core/errors.rb
|
97
90
|
- lib/dry/core/extensions.rb
|
98
91
|
- lib/dry/core/inflector.rb
|
99
92
|
- lib/dry/core/memoizable.rb
|
100
93
|
- lib/dry/core/version.rb
|
101
|
-
homepage: https://
|
94
|
+
homepage: https://dry-rb.org/gems/dry-core
|
102
95
|
licenses:
|
103
96
|
- MIT
|
104
97
|
metadata:
|
105
98
|
allowed_push_host: https://rubygems.org
|
99
|
+
changelog_uri: https://github.com/dry-rb/dry-core/blob/master/CHANGELOG.md
|
100
|
+
source_code_uri: https://github.com/dry-rb/dry-core
|
101
|
+
bug_tracker_uri: https://github.com/dry-rb/dry-core/issues
|
106
102
|
post_install_message:
|
107
103
|
rdoc_options: []
|
108
104
|
require_paths:
|
@@ -111,16 +107,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
107
|
requirements:
|
112
108
|
- - ">="
|
113
109
|
- !ruby/object:Gem::Version
|
114
|
-
version: 2.
|
110
|
+
version: 2.5.0
|
115
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
112
|
requirements:
|
117
113
|
- - ">="
|
118
114
|
- !ruby/object:Gem::Version
|
119
115
|
version: '0'
|
120
116
|
requirements: []
|
121
|
-
|
122
|
-
rubygems_version: 2.7.6
|
117
|
+
rubygems_version: 3.1.6
|
123
118
|
signing_key:
|
124
119
|
specification_version: 4
|
125
|
-
summary: A toolset of small support modules used throughout the dry-rb ecosystem
|
120
|
+
summary: A toolset of small support modules used throughout the dry-rb ecosystem
|
126
121
|
test_files: []
|
data/.gitignore
DELETED
data/.inch.yml
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
@@ -1,31 +0,0 @@
|
|
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
DELETED
@@ -1,31 +0,0 @@
|
|
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/CONTRIBUTING.md
DELETED
@@ -1,29 +0,0 @@
|
|
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).
|