active_memoize 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 765ef7f91367f3d5c0e4082344f72416d290c686682c6a2c7c5172b05b407820
4
+ data.tar.gz: 73c96a19c25aa46de8ff66f61a615c977dfb835306509c5a7f999a1e49a56e82
5
+ SHA512:
6
+ metadata.gz: bc6a242231e18909ec4bf77d1390769c9dce92fa3c613bda7afbf5d1f986f2af927a5bcb3cb417f8f75e014475b6f445c93e79a4c16a54917a7978c5c6fbc5b9
7
+ data.tar.gz: d3a06054f0d5e7ae6187cefc44abce073bf6c2806b1ac00a144de2f86d945a05d8ab12e22ca8214f964ef040b58548a2055d438582bf5c9c17545e7259fe8618
data/.fasterer.yml ADDED
@@ -0,0 +1,19 @@
1
+ speedups:
2
+ rescue_vs_respond_to: true
3
+ module_eval: true
4
+ shuffle_first_vs_sample: true
5
+ for_loop_vs_each: true
6
+ each_with_index_vs_while: false
7
+ map_flatten_vs_flat_map: true
8
+ reverse_each_vs_reverse_each: true
9
+ select_first_vs_detect: true
10
+ sort_vs_sort_by: true
11
+ fetch_with_argument_vs_block: true
12
+ keys_each_vs_each_key: true
13
+ hash_merge_bang_vs_hash_brackets: true
14
+ block_vs_symbol_to_proc: true
15
+ proc_call_vs_yield: true
16
+ gsub_vs_tr: true
17
+ select_last_vs_reverse_detect: true
18
+ getter_vs_attr_reader: true
19
+ setter_vs_attr_writer: true
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.irbrc_history
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.irbrc ADDED
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Awesome print
4
+ begin
5
+ require 'awesome_print'
6
+
7
+ AwesomePrint.irb!
8
+ rescue LoadError => err
9
+ warn "Couldn't load awesome_print: #{err}"
10
+ end
11
+
12
+ # IRB
13
+ require 'irb/completion'
14
+
15
+ ARGV.concat %w[--readline --prompt-mode simple]
16
+
17
+ IRB.conf[:PROMPT_MODE] = :SIMPLE
18
+ IRB.conf[:EVAL_HISTORY] = 1000
19
+ IRB.conf[:SAVE_HISTORY] = 1000
20
+ IRB.conf[:HISTORY_FILE] = File.expand_path('.irbrc_history')
21
+
22
+ # Rails
23
+ railsrc_path = File.expand_path('.irbrc_rails')
24
+
25
+ if (ENV['RAILS_ENV'] || defined?(Rails)) && File.exist?(railsrc_path)
26
+ begin
27
+ load railsrc_path
28
+ rescue Exception => err
29
+ warn "Could not load: #{railsrc_path} because of #{err}"
30
+ end
31
+ end
32
+
33
+ # Object
34
+ class Object
35
+
36
+ def interesting_methods
37
+ case self.class
38
+ when Class then public_methods.sort - Object.public_methods
39
+ when Module then public_methods.sort - Module.public_methods
40
+ else public_methods.sort - Object.new.public_methods
41
+ end
42
+ end
43
+
44
+ end
data/.reek.yml ADDED
@@ -0,0 +1,34 @@
1
+ ---
2
+ detectors:
3
+ Attribute:
4
+ enabled: false
5
+ BooleanParameter:
6
+ enabled: false
7
+ ControlParameter:
8
+ enabled: false
9
+ DuplicateMethodCall:
10
+ enabled: false
11
+ FeatureEnvy:
12
+ enabled: false
13
+ IrresponsibleModule:
14
+ enabled: false
15
+ ManualDispatch:
16
+ enabled: false
17
+ MissingSafeMethod:
18
+ enabled: false
19
+ NestedIterators:
20
+ max_allowed_nesting: 2
21
+ NilCheck:
22
+ enabled: false
23
+ RepeatedConditional:
24
+ enabled: false
25
+ TooManyMethods:
26
+ enabled: false
27
+ TooManyStatements:
28
+ max_statements: 10
29
+ UncommunicativeVariableName:
30
+ accept:
31
+ - '/^.$/'
32
+ - '/[0-9]$/'
33
+ UtilityFunction:
34
+ enabled: false
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --backtrace
2
+ --color
3
+ --format progress
4
+ --order random
data/.rubocop.yml ADDED
@@ -0,0 +1,30 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ DisplayStyleGuide: true
4
+ TargetRubyVersion: 2.5
5
+ Exclude:
6
+ - 'spec/**/**/*'
7
+ Performance/RegexpMatch:
8
+ Enabled: false
9
+ Layout/EmptyLinesAroundClassBody:
10
+ Enabled: false
11
+ Layout/EmptyLinesAroundModuleBody:
12
+ Enabled: false
13
+ LineLength:
14
+ Max: 100
15
+ Lint/RescueException:
16
+ Enabled: false
17
+ Metrics/ModuleLength:
18
+ Enabled: false
19
+ Style/Alias:
20
+ EnforcedStyle: prefer_alias_method
21
+ Style/ClassAndModuleChildren:
22
+ Enabled: false
23
+ Style/Documentation:
24
+ Enabled: false
25
+ Style/ExpandPathArguments:
26
+ Enabled: false
27
+ Style/RescueModifier:
28
+ Enabled: false
29
+ Style/RescueStandardError:
30
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - ruby-head
5
+ before_install:
6
+ - sudo apt-get install libxml2-dev
7
+ - gem update --system
8
+ - gem install bundler
9
+ - bundle install
10
+ script:
11
+ - bundle exec rake
12
+ notifications:
13
+ disable: true
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in active_memoize.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Juan Gomez
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,61 @@
1
+ # ActiveMemoize
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/active_memoize.svg)](http://badge.fury.io/rb/active_memoize)
4
+ [![Build Status](https://travis-ci.org/drexed/active_memoize.svg?branch=master)](https://travis-ci.org/drexed/active_memoize)
5
+
6
+ ActiveMemoize provides an API caching and memoizing local
7
+ expensive calculations including those with parameters.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'active_memoize'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install active_memoize
24
+
25
+ ## Table of Contents
26
+
27
+ * [Usage](#usage)
28
+
29
+ ## Usage
30
+
31
+ ```ruby
32
+ class Movies
33
+
34
+ def cache
35
+ @cache ||= ActiveMemoize::Cache.new
36
+ end
37
+
38
+ def random
39
+ cache['random'] ||= HTTP.get('http://movies.com/any')
40
+ end
41
+
42
+ def search(title, force = false)
43
+ cache.clear if force
44
+
45
+ cache.memoize do
46
+ HTTP.get("http://movies.com?title=#{title}")
47
+ end
48
+ end
49
+
50
+ end
51
+ ```
52
+
53
+ ## Contributing
54
+
55
+ Your contribution is welcome.
56
+
57
+ 1. Fork it
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+
5
+ task default: :spec
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'active_memoize/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'active_memoize'
9
+ spec.version = ActiveMemoize::VERSION
10
+ spec.authors = ['Juan Gomez']
11
+ spec.email = ['j.gomez@drexed.com']
12
+
13
+ spec.summary = 'Gem for using a cache and memoization system.'
14
+ spec.description = 'Cache and memoize expensive calculations.'
15
+ spec.homepage = 'http://drexed.github.io/active_memoize'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler'
24
+ spec.add_development_dependency 'fasterer'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'reek'
27
+ spec.add_development_dependency 'rspec'
28
+ spec.add_development_dependency 'rubocop'
29
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'active_memoize'
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
data/bin/rake ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rake' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath)
11
+
12
+ require 'rubygems'
13
+ require 'bundler/setup'
14
+
15
+ load Gem.bin_path('rake', 'rake')
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveMemoize
4
+ class Cache
5
+
6
+ CALLER_METHOD_REGEX ||= /`([^']*)'/.freeze
7
+
8
+ attr_reader :cache
9
+
10
+ def initialize
11
+ @cache = {}
12
+ end
13
+
14
+ def [](key)
15
+ @cache[key]
16
+ end
17
+
18
+ def []=(key, val)
19
+ @cache[key] = val
20
+ end
21
+
22
+ def clear
23
+ @cache.clear
24
+ end
25
+
26
+ def delete(key)
27
+ @cache.delete(key)
28
+ end
29
+
30
+ # :nocov:
31
+ def each
32
+ @cache.each { |key, val| yield(key, val) }
33
+ end
34
+ # :nocov:
35
+
36
+ def empty?
37
+ @cache.empty?
38
+ end
39
+
40
+ alias_method :blank?, :empty?
41
+
42
+ def key?(key)
43
+ @cache.key?(key)
44
+ end
45
+
46
+ alias_method :hit?, :key?
47
+
48
+ def keys
49
+ @cache.keys
50
+ end
51
+
52
+ def merge!(hash)
53
+ @cache.merge!(hash)
54
+ end
55
+
56
+ def memoize(&block)
57
+ method_name = "#{caller_method}:#{caller_locals(block)}"
58
+ return @cache[method_name] if @cache.key?(method_name)
59
+
60
+ @cache[method_name] = yield(block)
61
+ end
62
+
63
+ def present?
64
+ !blank?
65
+ end
66
+
67
+ alias_method :hits?, :present?
68
+
69
+ def size
70
+ @cache.size
71
+ end
72
+
73
+ def to_hash
74
+ @cache
75
+ end
76
+
77
+ alias_method :as_json, :to_hash
78
+ alias_method :hits, :to_hash
79
+
80
+ def values
81
+ @cache.values
82
+ end
83
+
84
+ private
85
+
86
+ # rubocop:disable Metrics/LineLength
87
+ def caller_locals(block)
88
+ local_vars = block.binding.local_variables
89
+ local_vars = local_vars.flat_map { |name| [name, block.binding.local_variable_get(name)].join('=') }
90
+ local_vars.join(',')
91
+ end
92
+ # rubocop:enable Metrics/LineLength
93
+
94
+ def caller_method
95
+ val = caller(2..2).first[CALLER_METHOD_REGEX, 1]
96
+ return val unless val.include?('<top (required)>')
97
+
98
+ caller(1..1).first[CALLER_METHOD_REGEX, 1]
99
+ end
100
+
101
+ end
102
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveMemoize
4
+ VERSION ||= '1.0.0'
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ %w[version cache].each do |file_name|
4
+ require "active_memoize/#{file_name}"
5
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_memoize
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Juan Gomez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-27 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: fasterer
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: rake
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: reek
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
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Cache and memoize expensive calculations.
98
+ email:
99
+ - j.gomez@drexed.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".fasterer.yml"
105
+ - ".gitignore"
106
+ - ".irbrc"
107
+ - ".reek.yml"
108
+ - ".rspec"
109
+ - ".rubocop.yml"
110
+ - ".travis.yml"
111
+ - CODE_OF_CONDUCT.md
112
+ - Gemfile
113
+ - LICENSE.txt
114
+ - README.md
115
+ - Rakefile
116
+ - active_memoize.gemspec
117
+ - bin/console
118
+ - bin/rake
119
+ - bin/setup
120
+ - lib/active_memoize.rb
121
+ - lib/active_memoize/cache.rb
122
+ - lib/active_memoize/version.rb
123
+ homepage: http://drexed.github.io/active_memoize
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubygems_version: 3.0.0
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Gem for using a cache and memoization system.
146
+ test_files: []