dry-core 0.7.1 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb330574bba6050e9a3d0fd466fdbd276ce76749b2661b8091ebf6178a2ef6c9
4
- data.tar.gz: c1319b83600515df992a91556000989aa092d4229f69669b8f544368d93d21a8
3
+ metadata.gz: 5c263a2d5bf720ac7d9e68c202b3552e4e82bba0b253ddc75a1aff5055463f9a
4
+ data.tar.gz: 955cdffe644913ba567129a73aaf3ea0b748b2b2fd5244b5d559da013bd05df9
5
5
  SHA512:
6
- metadata.gz: 2b1967bb0c991637ea01da5d267df78daa12e4801288932372eca2ecf8aff0c5933ef2cb9cdc06d978d6223da963a31dc5e362f1ad1052490e10ebbc2b39fae6
7
- data.tar.gz: 22662f066d46742cfd12d79eddcfb1e76811ab00b0080be8bac8fef53a1229fa91f5501b9f0b34f09182f5843c7bf995332fc16d1fe192daeadff186cd543cb7
6
+ metadata.gz: da527ac6a598046f9c8c7c2c1264b3e18c979b2ca5c2df65a6709952a3238afe733e3c52e92e0322946c46ff7b54141d986e2cdfe41ad5c0ae125bc96ad52c80
7
+ data.tar.gz: 64a8f1688c6781b2a10f3157747f8130c59072be29ed9b238500700166bb9c8e5d4b30e8a5493407c8354f71fd83d246dd3b9f9778dda6c23105dedcb209ae92
data/CHANGELOG.md CHANGED
@@ -1,5 +1,73 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
+ ## 1.0.1 2023-08-06
4
+
5
+
6
+ ### Fixed
7
+
8
+ - [equalizer] Add `Dry::Core.Equalizer` method to make `include Dry::Core.Equalizer(...)` work as documented (via #79) (@timriley)
9
+
10
+ Users of Equalizer should now only need to `require "dry/core"` first.
11
+
12
+
13
+
14
+ [Compare v1.0.0...v1.0.1](https://github.com/dry-rb/dry-core/compare/v1.0.0...v1.0.1)
15
+
16
+ ## 1.0.0 2022-11-04
17
+
18
+
19
+ ### Added
20
+
21
+ - Import dry-container as `Dry::Core::Container` (via #77) (@solnic)
22
+
23
+
24
+ [Compare v0.9.1...v1.0.0](https://github.com/dry-rb/dry-core/compare/v0.9.1...v1.0.0)
25
+
26
+ ## 0.9.1 2022-10-18
27
+
28
+
29
+ ### Changed
30
+
31
+ - Correct missing constant for IDENTITY (issue #75 fixed via #76) (@poloka)
32
+
33
+ [Compare v0.9.0...v0.9.1](https://github.com/dry-rb/dry-core/compare/v0.9.0...v0.9.1)
34
+
35
+ ## 0.9.0 2022-10-15
36
+
37
+
38
+ ### Changed
39
+
40
+ - dry-core now uses zeitwerk for autoloading (@solnic)
41
+
42
+ [Compare v0.8.1...v0.9.0](https://github.com/dry-rb/dry-core/compare/v0.8.1...v0.9.0)
43
+
44
+ ## 0.8.1 2022-07-27
45
+
46
+
47
+ ### Fixed
48
+
49
+ - [memoizable] plays better with inheritance.
50
+ There were cases when cached values from base claesses were used, see #70 (@flash-gordon)
51
+
52
+
53
+
54
+ [Compare v0.8.0...v0.8.1](https://github.com/dry-rb/dry-core/compare/v0.8.0...v0.8.1)
55
+
56
+ ## 0.8.0 2022-07-15
57
+
58
+
59
+ ### Added
60
+
61
+ - `Dry::Core::BasicObject` ported from hanami-utils (@jodosha)
62
+
63
+ ### Changed
64
+
65
+ - [BREAKING] [descendants tracker] switch to using `Class#subclasses` on Ruby 3.1+.
66
+ This changes the order of returned subclasses (immediate subclasses now go first) (@flash-gordon)
67
+
68
+
69
+ [Compare v0.7.1...v0.8.0](https://github.com/dry-rb/dry-core/compare/v0.7.1...v0.8.0)
70
+
3
71
  ## 0.7.1 2021-07-10
4
72
 
5
73
 
@@ -43,7 +111,7 @@ has unnamed params (e.g. happens when the new `...` syntax is used) (@flash-gord
43
111
 
44
112
  [Compare v0.5.0...v0.6.0](https://github.com/dry-rb/dry-core/compare/v0.5.0...v0.6.0)
45
113
 
46
- ## 0.5.0 2012-12-12
114
+ ## 0.5.0 2020-12-12
47
115
 
48
116
 
49
117
  ### Added
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2021 dry-rb team
3
+ Copyright (c) 2015-2023 dry-rb team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -1,29 +1,21 @@
1
1
  <!--- this file is synced from dry-rb/template-gem project -->
2
2
  [gem]: https://rubygems.org/gems/dry-core
3
3
  [actions]: https://github.com/dry-rb/dry-core/actions
4
- [codacy]: https://www.codacy.com/gh/dry-rb/dry-core
5
- [chat]: https://dry-rb.zulipchat.com
6
- [inchpages]: http://inch-ci.org/github/dry-rb/dry-core
7
4
 
8
- # dry-core [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
9
-
10
- [![Gem Version](https://badge.fury.io/rb/dry-core.svg)][gem]
11
- [![CI Status](https://github.com/dry-rb/dry-core/workflows/ci/badge.svg)][actions]
12
- [![Codacy Badge](https://api.codacy.com/project/badge/Grade/40946292b9094624beec604a149a6023)][codacy]
13
- [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/40946292b9094624beec604a149a6023)][codacy]
14
- [![Inline docs](http://inch-ci.org/github/dry-rb/dry-core.svg?branch=master)][inchpages]
5
+ # dry-core [![Gem Version](https://badge.fury.io/rb/dry-core.svg)][gem] [![CI Status](https://github.com/dry-rb/dry-core/workflows/ci/badge.svg)][actions]
15
6
 
16
7
  ## Links
17
8
 
18
9
  * [User documentation](https://dry-rb.org/gems/dry-core)
19
10
  * [API documentation](http://rubydoc.info/gems/dry-core)
11
+ * [Forum](https://discourse.dry-rb.org)
20
12
 
21
13
  ## Supported Ruby versions
22
14
 
23
15
  This library officially supports the following Ruby versions:
24
16
 
25
- * MRI `>= 2.6.0`
26
- * ~~jruby~~ `>= 9.3` (we are waiting for [2.6 support](https://github.com/jruby/jruby/issues/6161))
17
+ * MRI `>= 3.0.0`
18
+ * jruby `>= 9.4` (not tested on CI)
27
19
 
28
20
  ## License
29
21
 
data/dry-core.gemspec CHANGED
@@ -22,14 +22,15 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ["lib"]
23
23
 
24
24
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
25
- spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-core/blob/master/CHANGELOG.md"
25
+ spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-core/blob/main/CHANGELOG.md"
26
26
  spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-core"
27
27
  spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-core/issues"
28
28
 
29
- spec.required_ruby_version = ">= 2.6.0"
29
+ spec.required_ruby_version = ">= 3.0.0"
30
30
 
31
31
  # to update dependencies edit project.yml
32
32
  spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
33
+ spec.add_runtime_dependency "zeitwerk", "~> 2.6"
33
34
 
34
35
  spec.add_development_dependency "bundler"
35
36
  spec.add_development_dependency "rake"
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This implementation was imported from `hanami-utils` gem.
4
+ module Dry
5
+ module Core
6
+ # BasicObject
7
+ #
8
+ # @since 0.8.0
9
+ class BasicObject < ::BasicObject
10
+ # Lookups constants at the top-level namespace, if they are missing in the
11
+ # current context.
12
+ #
13
+ # @param name [Symbol] the constant name
14
+ #
15
+ # @return [Object, Module] the constant
16
+ #
17
+ # @raise [NameError] if the constant cannot be found
18
+ #
19
+ # @since 0.8.0
20
+ # @api private
21
+ #
22
+ # @see https://ruby-doc.org/core/Module.html#method-i-const_missing
23
+ def self.const_missing(name)
24
+ ::Object.const_get(name)
25
+ end
26
+
27
+ # Returns the class for debugging purposes.
28
+ #
29
+ # @since 0.8.0
30
+ #
31
+ # @see http://ruby-doc.org/core/Object.html#method-i-class
32
+ def class
33
+ (class << self; self; end).superclass
34
+ end
35
+
36
+ # Bare minimum inspect for debugging purposes.
37
+ #
38
+ # @return [String] the inspect string
39
+ #
40
+ # @since 0.8.0
41
+ #
42
+ # @see http://ruby-doc.org/core/Object.html#method-i-inspect
43
+ inspect_method = ::Kernel.instance_method(:inspect)
44
+ define_method(:inspect) do
45
+ original = inspect_method.bind_call(self)
46
+ "#{original[0...-1]}#{__inspect}>"
47
+ end
48
+
49
+ # @!macro [attach] instance_of?(class)
50
+ #
51
+ # Determines if self is an instance of given class or module
52
+ #
53
+ # @param class [Class,Module] the class of module to verify
54
+ #
55
+ # @return [TrueClass,FalseClass] the result of the check
56
+ #
57
+ # @raise [TypeError] if the given argument is not of the expected types
58
+ #
59
+ # @since 0.8.0
60
+ #
61
+ # @see http://ruby-doc.org/core/Object.html#method-i-instance_of-3F
62
+ define_method :instance_of?, ::Object.instance_method(:instance_of?)
63
+
64
+ # @!macro [attach] is_a?(class)
65
+ #
66
+ # Determines if self is of the type of the object class or module
67
+ #
68
+ # @param class [Class,Module] the class of module to verify
69
+ #
70
+ # @return [TrueClass,FalseClass] the result of the check
71
+ #
72
+ # @raise [TypeError] if the given argument is not of the expected types
73
+ #
74
+ # @since 0.8.0
75
+ #
76
+ # @see http://ruby-doc.org/core/Object.html#method-i-is_a-3F
77
+ define_method :is_a?, ::Object.instance_method(:is_a?)
78
+
79
+ # @!macro [attach] kind_of?(class)
80
+ #
81
+ # Determines if self is of the kind of the object class or module
82
+ #
83
+ # @param class [Class,Module] the class of module to verify
84
+ #
85
+ # @return [TrueClass,FalseClass] the result of the check
86
+ #
87
+ # @raise [TypeError] if the given argument is not of the expected types
88
+ #
89
+ # @since 0.8.0
90
+ #
91
+ # @see http://ruby-doc.org/core/Object.html#method-i-kind_of-3F
92
+ define_method :kind_of?, ::Object.instance_method(:kind_of?)
93
+
94
+ # Alias for __id__
95
+ #
96
+ # @return [Fixnum] the object id
97
+ #
98
+ # @since 0.8.0
99
+ #
100
+ # @see http://ruby-doc.org/core/Object.html#method-i-object_id
101
+ def object_id
102
+ __id__
103
+ end
104
+
105
+ # Interface for pp
106
+ #
107
+ # @param printer [PP] the Pretty Printable printer
108
+ # @return [String] the pretty-printable inspection of the object
109
+ #
110
+ # @since 0.8.0
111
+ #
112
+ # @see https://ruby-doc.org/stdlib/libdoc/pp/rdoc/PP.html
113
+ def pretty_print(printer)
114
+ printer.text(inspect)
115
+ end
116
+
117
+ # Returns true if responds to the given method.
118
+ #
119
+ # @return [TrueClass,FalseClass] the result of the check
120
+ #
121
+ # @since 0.8.0
122
+ #
123
+ # @see http://ruby-doc.org/core/Object.html#method-i-respond_to-3F
124
+ def respond_to?(method_name, include_all = false) # rubocop:disable Style/OptionalBooleanParameter
125
+ respond_to_missing?(method_name, include_all)
126
+ end
127
+
128
+ private
129
+
130
+ # Must be overridden by descendants
131
+ #
132
+ # @since 0.8.0
133
+ # @api private
134
+ def respond_to_missing?(_method_name, _include_all)
135
+ ::Kernel.raise ::NotImplementedError
136
+ end
137
+
138
+ # @since 0.8.0
139
+ # @api private
140
+ def __inspect # rubocop:disable Style/EmptyMethod
141
+ end
142
+ end
143
+ end
144
+ end
@@ -60,8 +60,8 @@ module Dry
60
60
  # @yield An arbitrary block
61
61
  #
62
62
  # @return [Object] block's return value
63
- def fetch_or_store(*args, &block)
64
- self.class.fetch_or_store(*args, &block)
63
+ def fetch_or_store(...)
64
+ self.class.fetch_or_store(...)
65
65
  end
66
66
  end
67
67
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "dry/core/constants"
4
- require "dry/core/errors"
5
4
 
6
5
  module Dry
7
6
  module Core
@@ -10,7 +9,6 @@ module Dry
10
9
  # @api public
11
10
  module ClassAttributes
12
11
  include Constants
13
-
14
12
  # Specify what attributes a class will use
15
13
  #
16
14
  # @example
@@ -80,13 +78,13 @@ module Dry
80
78
  if Undefined.equal?(value)
81
79
  if instance_variable_defined?(ivar)
82
80
  instance_variable_get(ivar)
83
- else # rubocop:disable Style/EmptyElse
81
+ else
84
82
  nil
85
83
  end
86
84
  elsif type === value # rubocop:disable Style/CaseEquality
87
85
  instance_variable_set(ivar, coerce.call(value))
88
86
  else
89
- raise InvalidClassAttributeValue.new(name, value)
87
+ raise InvalidClassAttributeValueError.new(name, value)
90
88
  end
91
89
  end
92
90
  end
@@ -62,7 +62,7 @@ module Dry
62
62
  # 1 + Undefined.default(val, 2)
63
63
  # end
64
64
  #
65
- def undefined.default(x, y = self) # rubocop:disable Naming/MethodParameterName
65
+ def undefined.default(x, y = self)
66
66
  if equal?(x)
67
67
  if equal?(y)
68
68
  yield
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dry
4
+ module Core
5
+ class Container
6
+ # @api public
7
+ class Config
8
+ DEFAULT_NAMESPACE_SEPARATOR = "."
9
+ DEFAULT_RESOLVER = Resolver.new
10
+ DEFAULT_REGISTRY = Registry.new
11
+
12
+ # @api public
13
+ attr_accessor :namespace_separator
14
+
15
+ # @api public
16
+ attr_accessor :resolver
17
+
18
+ # @api public
19
+ attr_accessor :registry
20
+
21
+ # @api private
22
+ def initialize(
23
+ namespace_separator: DEFAULT_NAMESPACE_SEPARATOR,
24
+ resolver: DEFAULT_RESOLVER,
25
+ registry: DEFAULT_REGISTRY
26
+ )
27
+ @namespace_separator = namespace_separator
28
+ @resolver = resolver
29
+ @registry = registry
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dry
4
+ module Core
5
+ class Container
6
+ # @api public
7
+ module Configuration
8
+ # Use dry/configurable if it's available
9
+ begin
10
+ require "dry/configurable"
11
+
12
+ # @api private
13
+ def self.extended(klass)
14
+ super
15
+ klass.class_eval do
16
+ extend Dry::Configurable
17
+
18
+ setting :namespace_separator, default: Config::DEFAULT_NAMESPACE_SEPARATOR
19
+ setting :resolver, default: Config::DEFAULT_RESOLVER
20
+ setting :registry, default: Config::DEFAULT_REGISTRY
21
+ end
22
+ end
23
+ rescue LoadError
24
+ # @api private
25
+ def config
26
+ @config ||= Container::Config.new
27
+ end
28
+ end
29
+
30
+ # @api private
31
+ def configure
32
+ yield config
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dry
4
+ module Core
5
+ class Container
6
+ class Item
7
+ # Callable class to returns a item call
8
+ #
9
+ # @api public
10
+ #
11
+ class Callable < Item
12
+ # Returns the result of item call or item
13
+ #
14
+ # @return [Mixed]
15
+ def call
16
+ callable? ? item.call : item
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dry
4
+ module Core
5
+ class Container
6
+ class Item
7
+ # Factory for create an Item to register inside of container
8
+ #
9
+ # @api public
10
+ class Factory
11
+ # Creates an Item Memoizable or Callable
12
+ # @param [Mixed] item
13
+ # @param [Hash] options
14
+ #
15
+ # @raise [Dry::Core::Container::Error]
16
+ #
17
+ # @return [Dry::Core::Container::Item::Base]
18
+ def call(item, options = {})
19
+ if options[:memoize]
20
+ Item::Memoizable.new(item, options)
21
+ else
22
+ Item::Callable.new(item, options)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dry
4
+ module Core
5
+ class Container
6
+ class Item
7
+ # Memoizable class to store and execute item calls
8
+ #
9
+ # @api public
10
+ #
11
+ class Memoizable < Item
12
+ # @return [Mutex] the stored mutex
13
+ attr_reader :memoize_mutex
14
+
15
+ # Returns a new Memoizable instance
16
+ #
17
+ # @param [Mixed] item
18
+ # @param [Hash] options
19
+ #
20
+ # @raise [Dry::Core::Container::Error]
21
+ #
22
+ # @return [Dry::Core::Container::Item::Base]
23
+ def initialize(item, options = {})
24
+ super
25
+ raise_not_supported_error unless callable?
26
+
27
+ @memoize_mutex = ::Mutex.new
28
+ end
29
+
30
+ # Returns the result of item call using a syncronized mutex
31
+ #
32
+ # @return [Dry::Core::Container::Item::Base]
33
+ def call
34
+ memoize_mutex.synchronize do
35
+ @memoized_item ||= item.call
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ # @private
42
+ def raise_not_supported_error
43
+ raise ::Dry::Core::Container::Error, "Memoize only supported for a block or a proc"
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dry
4
+ module Core
5
+ class Container
6
+ # Base class to abstract Memoizable and Callable implementations
7
+ #
8
+ # @api abstract
9
+ #
10
+ class Item
11
+ # @return [Mixed] the item to be solved later
12
+ attr_reader :item
13
+
14
+ # @return [Hash] the options to memoize, call or no.
15
+ attr_reader :options
16
+
17
+ # @api abstract
18
+ def initialize(item, options = {})
19
+ @item = item
20
+ @options = {
21
+ call: item.is_a?(::Proc) && item.parameters.empty?
22
+ }.merge(options)
23
+ end
24
+
25
+ # @api abstract
26
+ def call
27
+ raise NotImplementedError
28
+ end
29
+
30
+ # @private
31
+ def value?
32
+ !callable?
33
+ end
34
+
35
+ # @private
36
+ def callable?
37
+ options[:call]
38
+ end
39
+
40
+ # Build a new item with transformation applied
41
+ #
42
+ # @private
43
+ def map(func)
44
+ if callable?
45
+ self.class.new(-> { func.(item.call) }, options)
46
+ else
47
+ self.class.new(func.(item), options)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end