uinit-memoizable 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a6e96fd5162b0ac7891315f622fbd893569d2530e4930527226720133a7766d6
4
+ data.tar.gz: dfeb83ce1c42fd978c07815d8f33f48a21824a37fce03cb4ddb7d47648ec77e5
5
+ SHA512:
6
+ metadata.gz: e7ec6bc23e03ba5b66e9b8784d8bde48bb901da01a6ca40acf2d965060c0a0bdcf194c14624519e65498bb14ab8d1cb16f2d23ce1e2128ce29e5ebe27d7b81bc
7
+ data.tar.gz: 7922c31eb04a101efd152837cdfad7c0fb030ae2f40b35c274eab60ada734a8ca47d0d5416d769f222bdf6234d97fa5089adf01aba0b08ffa1489645f149a354
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Kimoja
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,2 @@
1
+ # uinit-memoizable
2
+ Memoize method
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Uinit
4
+ module Memoizable
5
+ VERSION = '0.1.0'
6
+
7
+ def self.included(base)
8
+ base.extend(ClassMethods)
9
+ end
10
+
11
+ module ClassMethods
12
+ def memo(method_sym)
13
+ method = instance_method(method_sym)
14
+ ivar = memo_variable_name(method_sym)
15
+
16
+ define_method(method_sym) do |*args, **kwargs|
17
+ return instance_variable_get(ivar) if instance_variable_defined?(ivar)
18
+
19
+ instance_variable_set(ivar, method.bind_call(self, *args, **kwargs))
20
+ end
21
+ end
22
+
23
+ def memo_self(method_sym)
24
+ method = singleton_class.instance_method(method_sym)
25
+ ivar = memo_variable_name(method_sym)
26
+
27
+ define_singleton_method(method_sym) do |*args, **kwargs|
28
+ return singleton_class.instance_variable_get(ivar) if singleton_class.instance_variable_defined?(ivar)
29
+
30
+ singleton_class.instance_variable_set(ivar, method.bind_call(self, *args, **kwargs))
31
+ end
32
+ end
33
+
34
+ def memo_unset(method_sym)
35
+ singleton_class.remove_instance_variable(memo_variable_name(method_sym))
36
+ end
37
+
38
+ def memo_variable_name(method_sym)
39
+ predicate = method_sym.to_s.end_with?('?')
40
+
41
+ :"@#{predicate ? '__memois_' : '__memo_'}#{method_sym.to_s.tr('?', '_')}"
42
+ end
43
+ end
44
+
45
+ def memo_unset(method_sym)
46
+ remove_instance_variable(self.class.memo_variable_name(method_sym))
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'uinit/memoizable'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'uinit-memoizable'
10
+ spec.version = Uinit::Memoizable::VERSION
11
+ spec.authors = ['Kimoja']
12
+ spec.email = ['joakim.carrilho@cheerz.com']
13
+
14
+ spec.summary = 'Memoize method'
15
+ spec.description = 'Memoize method'
16
+ spec.homepage = 'https://github.com/Kimoja/uinit-memoizable'
17
+ spec.license = 'MIT'
18
+ spec.required_ruby_version = '>= 3.2.1'
19
+ spec.files = Dir['CHANGELOG.md', 'LICENSE.txt', 'README.md', 'uinit-memoizable.gemspec', 'lib/**/*']
20
+ spec.require_paths = ['lib']
21
+ spec.executables = []
22
+
23
+ spec.metadata['homepage_uri'] = spec.homepage
24
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
25
+ spec.metadata['source_code_uri'] = 'https://github.com/Kimoja/uinit-memoizable'
26
+ spec.metadata['changelog_uri'] = 'https://github.com/Kimoja/uinit-memoizable/blob/main/CHANGELOG.md'
27
+ spec.metadata['bug_tracker_uri'] = 'https://github.com/Kimoja/uinit-memoizable/issues'
28
+
29
+ spec.add_development_dependency 'bundler'
30
+ spec.add_development_dependency 'pry'
31
+ spec.add_development_dependency 'rspec'
32
+ spec.add_development_dependency 'rubocop'
33
+ spec.metadata['rubygems_mfa_required'] = 'true'
34
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uinit-memoizable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kimoja
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-05-08 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Memoize method
70
+ email:
71
+ - joakim.carrilho@cheerz.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - LICENSE.txt
77
+ - README.md
78
+ - lib/uinit/memoizable.rb
79
+ - uinit-memoizable.gemspec
80
+ homepage: https://github.com/Kimoja/uinit-memoizable
81
+ licenses:
82
+ - MIT
83
+ metadata:
84
+ homepage_uri: https://github.com/Kimoja/uinit-memoizable
85
+ allowed_push_host: https://rubygems.org
86
+ source_code_uri: https://github.com/Kimoja/uinit-memoizable
87
+ changelog_uri: https://github.com/Kimoja/uinit-memoizable/blob/main/CHANGELOG.md
88
+ bug_tracker_uri: https://github.com/Kimoja/uinit-memoizable/issues
89
+ rubygems_mfa_required: 'true'
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: 3.2.1
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubygems_version: 3.4.6
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Memoize method
109
+ test_files: []