somecache 0.1.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: 87c3ebe1590cf315cd82cfbf0239809f96883f36e1785770f7bd2294d1b1242f
4
+ data.tar.gz: f1502fe85ffc5b6c09a7fc43cce618f5957db3323161a7041863e2928d2e926f
5
+ SHA512:
6
+ metadata.gz: 14591e0a428bfb6a2ded32d6b599f95834e5ea299fc848307fa0a55178f5f5a29d5fc6ee4a7ae10ea2d2f4e2cb8b6125588a774ca40595d5b8a3fb7a470a0790
7
+ data.tar.gz: a3c10b06b395fe6af8fa2265dda85843222324c0a8ac69fc409af91828eb3947df260ca14f0ded8e0902b18a10d80e957fc32491ab770d952b36f452d36daefa
data/.gitignore ADDED
@@ -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
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.5.1
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in somecache.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ somecache (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activesupport (6.0.2.2)
10
+ concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ i18n (>= 0.7, < 2)
12
+ minitest (~> 5.1)
13
+ tzinfo (~> 1.1)
14
+ zeitwerk (~> 2.2)
15
+ concurrent-ruby (1.1.6)
16
+ diff-lcs (1.3)
17
+ i18n (1.8.2)
18
+ concurrent-ruby (~> 1.0)
19
+ minitest (5.14.0)
20
+ rake (12.3.3)
21
+ rspec (3.9.0)
22
+ rspec-core (~> 3.9.0)
23
+ rspec-expectations (~> 3.9.0)
24
+ rspec-mocks (~> 3.9.0)
25
+ rspec-core (3.9.1)
26
+ rspec-support (~> 3.9.1)
27
+ rspec-expectations (3.9.1)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.9.0)
30
+ rspec-mocks (3.9.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.9.0)
33
+ rspec-support (3.9.2)
34
+ thread_safe (0.3.6)
35
+ tzinfo (1.2.6)
36
+ thread_safe (~> 0.1)
37
+ zeitwerk (2.3.0)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ activesupport
44
+ rake (~> 12.0)
45
+ rspec (~> 3.0)
46
+ somecache!
47
+
48
+ BUNDLED WITH
49
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Carlos Atkinson Ferreira Filho
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,63 @@
1
+ # Somecache
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'somecache'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle install
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install somecache
18
+
19
+ ## Usage
20
+
21
+ Somecache is a wrapper to cache objects (following the `read`, `write`, `fetch` and `delete` api)
22
+
23
+ The aim is to easily create custom caches (with custom namespace or expiration options)
24
+
25
+ When working with cache is easy to spread the logic of creation and deletion, like so:
26
+
27
+ ```ruby
28
+ # Some Class
29
+ Rails.cache.fetch("products/#{product_id}", expires_in: 1.day) { Product.find(product_id) }
30
+
31
+ # Some Worker
32
+ Rails.cache.delete("products/#{product_id}")
33
+ ```
34
+
35
+ Somecache allows you to create and use the cache without spreading cache logic (like the namespace)
36
+
37
+ ```ruby
38
+ # product_cache.rb
39
+ ProductCache = Somecache::Custom.new(namespace: 'products' , cache: Rails.cache, expires_in: 1.day)
40
+
41
+ # Some Class
42
+ ProductCache.fetch(product_id) { Product.find(product_id) }
43
+
44
+ # Some Worker
45
+
46
+ ProductCache.delete(product_id)
47
+
48
+ ```
49
+
50
+ ## Development
51
+
52
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
53
+
54
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
55
+
56
+ ## Contributing
57
+
58
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/somecache.
59
+
60
+
61
+ ## License
62
+
63
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "somecache"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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
data/lib/somecache.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'somecache/version'
2
+ require 'somecache/custom'
3
+
4
+ module Somecache
5
+ end
@@ -0,0 +1,31 @@
1
+ module Somecache
2
+ class Custom
3
+ def initialize(namespace:, cache:, **options)
4
+ @namespace = namespace
5
+ @options = options
6
+ @cache = cache
7
+ end
8
+
9
+ def fetch(key, &block)
10
+ @cache.fetch(key_with_namespace(key), **@options, &block)
11
+ end
12
+
13
+ def write(key, value)
14
+ @cache.write(key_with_namespace(key), value, **@options)
15
+ end
16
+
17
+ def read(key)
18
+ @cache.read(key_with_namespace(key), **@options)
19
+ end
20
+
21
+ def delete(key)
22
+ @cache.delete(key_with_namespace(key))
23
+ end
24
+
25
+ private
26
+
27
+ def key_with_namespace(key)
28
+ "#{@namespace}/#{key}"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Somecache
2
+ VERSION = "0.1.0"
3
+ end
data/somecache.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ require_relative 'lib/somecache/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "somecache"
5
+ spec.version = Somecache::VERSION
6
+ spec.authors = ["Carlos Atkinson Ferreira Filho"]
7
+ spec.email = ["carlos.atkinson@vagas.com.br"]
8
+
9
+ spec.summary = %q{Somecache is a ruby microlib to create custom caches}
10
+ spec.homepage = "https://github.com/VAGAScom/somecache"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency 'activesupport'
26
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: somecache
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Carlos Atkinson Ferreira Filho
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
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
+ description:
28
+ email:
29
+ - carlos.atkinson@vagas.com.br
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".travis.yml"
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/setup
44
+ - lib/somecache.rb
45
+ - lib/somecache/custom.rb
46
+ - lib/somecache/version.rb
47
+ - somecache.gemspec
48
+ homepage: https://github.com/VAGAScom/somecache
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ homepage_uri: https://github.com/VAGAScom/somecache
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 2.3.0
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.7.6
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Somecache is a ruby microlib to create custom caches
73
+ test_files: []