memoize_block 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1451eac125fa673e6d57371c0d2706249a944bfd48b89c211ab76b7c9561203b
4
+ data.tar.gz: bb19ad0c959710ccc3cc928946898dcb34ceab48d907b8607d97a88beecd2755
5
+ SHA512:
6
+ metadata.gz: 4670679952ce0b19adea7549047d9bf1e3f807e732c3fde557708727fed1f3819f4da11d961cb6fac31fdb9b5a22c6c3c0baf5149488ea3ce2cda8df4b6c2690
7
+ data.tar.gz: 3a7f159ab8b44fa6e1e49e1bf7e63413a5f2bee4cc60683f998ce44f6c7c4fbb4e34e1c1f90f0a8b8d4cee594c454a87dfaafba667f50f48f8d817e88a0e56b4
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,77 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ Include:
4
+ - 'lib/**/*'
5
+ - 'spec/**/*'
6
+
7
+ Layout/LineLength:
8
+ Max: 120
9
+
10
+ Layout/SpaceBeforeBlockBraces:
11
+ EnforcedStyle: space
12
+
13
+ Layout/SpaceInsideArrayLiteralBrackets:
14
+ Enabled: false
15
+
16
+ Layout/SpaceInsideParens:
17
+ Enabled: false
18
+
19
+ Lint/DuplicateRegexpCharacterClassElement:
20
+ Enabled: true
21
+
22
+ Lint/EmptyBlock:
23
+ Enabled: false
24
+
25
+ Lint/MissingSuper:
26
+ Enabled: false
27
+
28
+ Lint/NoReturnInBeginEndBlocks:
29
+ Enabled: true
30
+
31
+ Lint/ToEnumArguments:
32
+ Enabled: true
33
+
34
+ Lint/UnmodifiedReduceAccumulator:
35
+ Enabled: true
36
+
37
+ Metrics/BlockLength:
38
+ Enabled: false
39
+
40
+ Metrics/MethodLength:
41
+ Enabled: false
42
+
43
+ Style/ArgumentsForwarding:
44
+ Enabled: false # enable when Ruby 2.7 is min. supported version
45
+
46
+ Style/BlockDelimiters:
47
+ Enabled: false
48
+
49
+ Style/CollectionCompact:
50
+ Enabled: true
51
+
52
+ Style/Documentation:
53
+ Enabled: false
54
+
55
+ Style/DocumentDynamicEvalDefinition:
56
+ Enabled: true
57
+
58
+ Style/ExpandPathArguments:
59
+ Enabled: false
60
+
61
+ Style/Lambda:
62
+ Enabled: false
63
+
64
+ Style/MutableConstant:
65
+ Enabled: true
66
+
67
+ Style/MissingRespondToMissing:
68
+ Enabled: false
69
+
70
+ Style/NegatedIfElseCondition:
71
+ Enabled: true
72
+
73
+ Style/StringLiterals:
74
+ Enabled: false
75
+
76
+ Style/SwapValues:
77
+ Enabled: true
@@ -0,0 +1 @@
1
+ ruby 2.7.2
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.5.8
4
+ - 2.6.6
5
+ - 2.7.2
6
+ before_install: gem install bundler -v 2.1.4
7
+ script:
8
+ - bundle exec rspec
9
+ - bundle exec rubocop
@@ -0,0 +1,5 @@
1
+ # CHANGELOG
2
+
3
+ ## 1.0
4
+
5
+ - Initial release
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at adamgsteel@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in memoize_block.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,66 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ memoize_block (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.1)
10
+ coderay (1.1.3)
11
+ diff-lcs (1.4.4)
12
+ method_source (1.0.0)
13
+ parallel (1.19.2)
14
+ parser (2.7.2.0)
15
+ ast (~> 2.4.1)
16
+ pry (0.13.1)
17
+ coderay (~> 1.1)
18
+ method_source (~> 1.0)
19
+ pry-doc (1.1.0)
20
+ pry (~> 0.11)
21
+ yard (~> 0.9.11)
22
+ rainbow (3.0.0)
23
+ rake (12.3.3)
24
+ regexp_parser (1.8.2)
25
+ rexml (3.2.4)
26
+ rspec (3.10.0)
27
+ rspec-core (~> 3.10.0)
28
+ rspec-expectations (~> 3.10.0)
29
+ rspec-mocks (~> 3.10.0)
30
+ rspec-core (3.10.0)
31
+ rspec-support (~> 3.10.0)
32
+ rspec-expectations (3.10.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.10.0)
35
+ rspec-mocks (3.10.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.10.0)
38
+ rspec-support (3.10.0)
39
+ rubocop (1.2.0)
40
+ parallel (~> 1.10)
41
+ parser (>= 2.7.1.5)
42
+ rainbow (>= 2.2.2, < 4.0)
43
+ regexp_parser (>= 1.8)
44
+ rexml
45
+ rubocop-ast (>= 1.0.1)
46
+ ruby-progressbar (~> 1.7)
47
+ unicode-display_width (>= 1.4.0, < 2.0)
48
+ rubocop-ast (1.1.1)
49
+ parser (>= 2.7.1.5)
50
+ ruby-progressbar (1.10.1)
51
+ unicode-display_width (1.7.0)
52
+ yard (0.9.25)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ memoize_block!
59
+ pry
60
+ pry-doc
61
+ rake (~> 12.0)
62
+ rspec (~> 3.0)
63
+ rubocop
64
+
65
+ BUNDLED WITH
66
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Adam Steel
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.
@@ -0,0 +1,11 @@
1
+ [![Build Status](https://travis-ci.org/truecoach/memoize_block.svg?branch=main)](https://travis-ci.org/truecoach/memoize_block)
2
+
3
+ # MemoizeBlock
4
+
5
+ In process of open sourcing, don't use just yet
6
+
7
+ ## Usage
8
+
9
+ ```ruby
10
+ include MemoizeBlock
11
+ ```
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "memoize_block"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "memoize_block/version"
4
+
5
+ module MemoizeBlock
6
+ #
7
+ # A memoization helper designed to DRY up the memoization logic we use
8
+ # across the app. Examples A and B have the same memoization result:
9
+ #
10
+ # Example A:
11
+ # class Processor
12
+ # def calcuate
13
+ # memoize { ExpensiveQuery.call }
14
+ # end
15
+ # end
16
+ #
17
+ # Example B:
18
+ # class Processor
19
+ # def calcuate
20
+ # return @_calculate if defined?(@_caculate)
21
+ # @_calculate = ExpensiveQuery.call
22
+ # end
23
+ # end
24
+ #
25
+ def memoize(ivar_name = nil)
26
+ ivar_name = ivar_name.nil? ? caller_locations[0].label : ivar_name
27
+
28
+ raise 'invalid ivar name' if ivar_name.match(/@|!/)
29
+
30
+ full_ivar_name = "@_#{ivar_name}"
31
+
32
+ return instance_variable_get(full_ivar_name) if instance_variable_defined?(full_ivar_name)
33
+
34
+ instance_variable_set(full_ivar_name, yield)
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MemoizeBlock
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'lib/memoize_block/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "memoize_block"
5
+ spec.version = MemoizeBlock::VERSION
6
+ spec.authors = ["Adam Steel"]
7
+ spec.email = ["adamgsteel@gmail.com"]
8
+ spec.summary = %q{Inline memoize helper method}
9
+ spec.description = %q{
10
+ Easily memoize any operation with this global method that takes a block.
11
+ }
12
+ spec.homepage = "https://github.com/truecoach/memoize_block"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency 'rspec'
30
+ spec.add_development_dependency 'pry'
31
+ spec.add_development_dependency 'pry-doc'
32
+ spec.add_development_dependency 'rubocop'
33
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: memoize_block
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Steel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
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: pry-doc
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: "\n Easily memoize any operation with this global method that takes
70
+ a block.\n "
71
+ email:
72
+ - adamgsteel@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".rubocop.yml"
80
+ - ".tool-versions"
81
+ - ".travis.yml"
82
+ - CHANGELOG.md
83
+ - CODE_OF_CONDUCT.md
84
+ - Gemfile
85
+ - Gemfile.lock
86
+ - LICENSE.txt
87
+ - README.md
88
+ - Rakefile
89
+ - bin/console
90
+ - bin/setup
91
+ - lib/memoize_block.rb
92
+ - lib/memoize_block/version.rb
93
+ - memoize_block.gemspec
94
+ homepage: https://github.com/truecoach/memoize_block
95
+ licenses:
96
+ - MIT
97
+ metadata:
98
+ homepage_uri: https://github.com/truecoach/memoize_block
99
+ source_code_uri: https://github.com/truecoach/memoize_block
100
+ changelog_uri: https://github.com/truecoach/memoize_block/CHANGELOG.md
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 2.3.0
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubygems_version: 3.1.4
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Inline memoize helper method
120
+ test_files: []