dry-core 0.5.0 → 0.6.0

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: 455db6bceb946acab5dbe431c4ba7edf9a7344f09c2b2af9e38c0b8788e3d600
4
- data.tar.gz: c460402f0b99fbe8ad488463cebd828a6a814d0a45f5200fbf1c90302fa66649
3
+ metadata.gz: 45f3b305a44c07e1b2de42160317f823835eafc272bffad043ffdf98e3fcd67c
4
+ data.tar.gz: 5d040687f80c2c6d03a55bc228027f4d094820b7a7f8bcc22edec3e32e99a1a4
5
5
  SHA512:
6
- metadata.gz: c07482895edfb498acc414cc6672c2fa271cbd892f59393b4baa6b3b7ec4e115b29474be85fe42e40660fe06f926442608d693816594bdfcd910411185acad9c
7
- data.tar.gz: c3d0966d660f09a26007e226b57e1cc2c124a420606b4de5d104730c6f5d9c54492a89788fb601722eab10f42dac4cda5d6689c79fe6c53a3df9c6510569fa7e
6
+ metadata.gz: 418356154a80dfd5cc2e31e04c84eeac838ff6d0d37c463db58ae68000d51b3eadb43f62ad5b41b3965b823967cd11967170dd38bc4ca71019ab54f098b14db0
7
+ data.tar.gz: 1afa97c77840ed121fb2b501e3bbafb3854d34aefc47596d435ad405c83153ca4e18fbf2e15e929093a90f81e4113bfd339c80d67056e86d3c349c607cf95749
data/CHANGELOG.md CHANGED
@@ -1,6 +1,22 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
- ## unreleased
3
+ ## 0.6.0 2021-06-03
4
+
5
+
6
+ ### Added
7
+
8
+ - [memoizable] support for `BasicObject` (@oleander)
9
+ - [memoizable] support for methods that accept blocks (@oleander)
10
+ - [deprecations] allow printing frame info on warn when setting up Deprecation module (via #52) (@waiting-for-dev)
11
+
12
+ ### Fixed
13
+
14
+ - [memoizable] works with MRI 2.7+ keyword arguments now (@oleander)
15
+
16
+
17
+ [Compare v0.5.0...v0.6.0](https://github.com/dry-rb/dry-core/compare/v0.5.0...v0.6.0)
18
+
19
+ ## 0.5.0 2012-12-12
4
20
 
5
21
 
6
22
  ### Added
@@ -8,7 +24,7 @@
8
24
  - dry-equalizer has been imported into dry-core as `Dry::Core::Equalizer` but the interface remains the same, which is `include Dry.Equalizer(...)` - we'll be porting all other gems that depend on dry-equalizer to the latest dry-core with equalizer included *gradually*. Eventually dry-equalizer usage will be gone completely in rom-rb/dry-rb/hanami projects (@solnic)
9
25
 
10
26
 
11
- [Compare v0.4.10...master](https://github.com/dry-rb/dry-core/compare/v0.4.10...master)
27
+ [Compare v0.4.10...v0.5.0](https://github.com/dry-rb/dry-core/compare/v0.4.10...v0.5.0)
12
28
 
13
29
  ## 0.4.10 2020-11-19
14
30
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2020 dry-rb team
3
+ Copyright (c) 2015-2021 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/dry-core.gemspec CHANGED
@@ -1,29 +1,30 @@
1
1
  # frozen_string_literal: true
2
- # this file is managed by dry-rb/devtools project
3
2
 
4
- lib = File.expand_path('lib', __dir__)
3
+ # this file is synced from dry-rb/template-gem project
4
+
5
+ lib = File.expand_path("lib", __dir__)
5
6
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
- require 'dry/core/version'
7
+ require "dry/core/version"
7
8
 
8
9
  Gem::Specification.new do |spec|
9
- spec.name = 'dry-core'
10
+ spec.name = "dry-core"
10
11
  spec.authors = ["Nikita Shilnikov"]
11
12
  spec.email = ["fg@flashgordon.ru"]
12
- spec.license = 'MIT'
13
+ spec.license = "MIT"
13
14
  spec.version = Dry::Core::VERSION.dup
14
15
 
15
16
  spec.summary = "A toolset of small support modules used throughout the dry-rb ecosystem"
16
17
  spec.description = spec.summary
17
- spec.homepage = 'https://dry-rb.org/gems/dry-core'
18
+ spec.homepage = "https://dry-rb.org/gems/dry-core"
18
19
  spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-core.gemspec", "lib/**/*"]
19
- spec.bindir = 'bin'
20
+ spec.bindir = "bin"
20
21
  spec.executables = []
21
- spec.require_paths = ['lib']
22
+ spec.require_paths = ["lib"]
22
23
 
23
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
24
- spec.metadata['changelog_uri'] = 'https://github.com/dry-rb/dry-core/blob/master/CHANGELOG.md'
25
- spec.metadata['source_code_uri'] = 'https://github.com/dry-rb/dry-core'
26
- spec.metadata['bug_tracker_uri'] = 'https://github.com/dry-rb/dry-core/issues'
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"
26
+ spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-core"
27
+ spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-core/issues"
27
28
 
28
29
  spec.required_ruby_version = ">= 2.5.0"
29
30
 
@@ -33,17 +33,24 @@ module Dry
33
33
  # Prints a warning
34
34
  #
35
35
  # @param [String] msg Warning string
36
- def warn(msg, tag: nil)
37
- tagged = "[#{tag || 'deprecated'}] #{msg.gsub(/^\s+/, '')}"
38
- logger.warn(tagged)
36
+ # @param [String] tag Tag to help identify the source of the warning.
37
+ # Defaults to "deprecated"
38
+ # @param [Integer] Caller frame to add to the message
39
+ def warn(msg, tag: nil, uplevel: nil)
40
+ caller_info = uplevel.nil? ? nil : caller[uplevel]
41
+ tag = "[#{tag || "deprecated"}]"
42
+ hint = msg.gsub(/^\s+/, "")
43
+ logger.warn(
44
+ [caller_info, tag, hint].compact.join(" ")
45
+ )
39
46
  end
40
47
 
41
48
  # Wraps arguments with a standard message format and prints a warning
42
49
  #
43
50
  # @param [Object] name what is deprecated
44
51
  # @param [String] msg additional message usually containing upgrade instructions
45
- def announce(name, msg, tag: nil)
46
- warn(deprecation_message(name, msg), tag: tag)
52
+ def announce(name, msg, tag: nil, uplevel: nil)
53
+ warn(deprecation_message(name, msg), tag: tag, uplevel: uplevel)
47
54
  end
48
55
 
49
56
  # @api private
@@ -6,64 +6,102 @@ module Dry
6
6
  MEMOIZED_HASH = {}.freeze
7
7
 
8
8
  module ClassInterface
9
- def memoize(*names)
10
- prepend(Memoizer.new(self, names))
9
+ module Base
10
+ def memoize(*names)
11
+ prepend(Memoizer.new(self, names))
12
+ end
11
13
  end
12
14
 
13
- def new(*)
14
- obj = super
15
- obj.instance_variable_set(:'@__memoized__', MEMOIZED_HASH.dup)
16
- obj
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
17
37
  end
18
38
  end
19
39
 
20
40
  def self.included(klass)
21
41
  super
22
- klass.extend(ClassInterface)
23
- end
24
42
 
25
- attr_reader :__memoized__
43
+ if klass <= Object
44
+ klass.extend(ClassInterface::Object)
45
+ else
46
+ klass.extend(ClassInterface::BasicObject)
47
+ end
48
+ end
26
49
 
27
50
  # @api private
28
51
  class Memoizer < Module
29
- attr_reader :klass
30
- attr_reader :names
31
-
32
52
  # @api private
33
53
  def initialize(klass, names)
34
- @names = names
35
- @klass = klass
36
- define_memoizable_names!
54
+ names.each do |name|
55
+ define_memoizable(
56
+ method: klass.instance_method(name)
57
+ )
58
+ end
37
59
  end
38
60
 
39
61
  private
40
62
 
41
63
  # @api private
42
- def define_memoizable_names!
43
- names.each do |name|
44
- meth = klass.instance_method(name)
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) }
45
68
 
46
- if meth.parameters.size > 0
47
- define_method(name) do |*args|
48
- name_with_args = :"#{name}_#{args.hash}"
49
-
50
- if __memoized__.key?(name_with_args)
51
- __memoized__[name_with_args]
52
- else
53
- __memoized__[name_with_args] = super(*args)
54
- end
55
- end
56
- else
57
- define_method(name) do
58
- if __memoized__.key?(name)
59
- __memoized__[name]
60
- else
61
- __memoized__[name] = super()
62
- end
69
+ if @__memoized__.key?(key)
70
+ @__memoized__[key]
71
+ else
72
+ @__memoized__[key] = super
63
73
  end
64
74
  end
75
+ RUBY
76
+
77
+ if respond_to?(:ruby2_keywords, true)
78
+ ruby2_keywords(method.name)
65
79
  end
66
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
67
105
  end
68
106
  end
69
107
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Core
5
- VERSION = "0.5.0".freeze
5
+ VERSION = "0.6.0".freeze
6
6
  end
7
7
  end
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.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Shilnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-12 00:00:00.000000000 Z
11
+ date: 2021-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  - !ruby/object:Gem::Version
115
115
  version: '0'
116
116
  requirements: []
117
- rubygems_version: 3.1.4
117
+ rubygems_version: 3.1.6
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: A toolset of small support modules used throughout the dry-rb ecosystem