tiny_fake_redis 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 91f1211dfc8f8f0b68e87f387d2ab9ea82824da6cd9f1d9c2232c85c83bf2d17
4
+ data.tar.gz: cb63a8c26ba758315a9ff2c3ae3e0530de134224fb157fb6a765e49ae663b366
5
+ SHA512:
6
+ metadata.gz: 282a1acd7ea4b7ab8f88a2ef7927a4e99a5f83e2751b0f09fe45c15928bb6147aef93a25ea2c4a57b096ff10f8807356a1edd4a2bac55d7cbd4541b24ffb68c7
7
+ data.tar.gz: 3df64efcb0fa614127cbae983c1a1394bb9dcd25521f30f3a4039ad788c623fa813de1fc6409f2fb2c71ead70c3cccfdd24fef86b1bbc2f61bce0c8f27454144
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.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 fake_redis.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
@@ -0,0 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tiny_fake_redis (0.1.0)
5
+ zeitwerk (~> 2, >= 2.2.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ minitest (5.14.1)
11
+ rake (12.3.3)
12
+ zeitwerk (2.4.0)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ minitest (~> 5.0)
19
+ rake (~> 12.0)
20
+ tiny_fake_redis!
21
+
22
+ BUNDLED WITH
23
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Sampson Crowley
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,48 @@
1
+ # TinyFakeRedis
2
+
3
+ Pretend to Access a Redis Server
4
+
5
+ This gem mimics the calls of `redis-rb` to allow running commands in development and test environments without the need to run a redis server instance
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem "tiny_fake_redis"
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install tiny_fake_redis
22
+
23
+ ## Usage
24
+ Create an instance
25
+
26
+ ```ruby
27
+ redis = TinyFakeRedis.new
28
+ ```
29
+
30
+ Treat it the same as an open redis-rb connection
31
+
32
+ ```ruby
33
+ redis.set(:asdf, :asdf)
34
+ ```
35
+ ## Development
36
+
37
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+
39
+ 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).
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/SampsonCrowley/tiny_fake_redis
44
+
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fake_redis"
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__)
@@ -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,109 @@
1
+ require "zeitwerk"
2
+ loader = Zeitwerk::Loader.for_gem
3
+ loader.setup # ready!
4
+
5
+ class TinyFakeRedis
6
+ class Error < StandardError; end
7
+
8
+ def data
9
+ @data ||= {}
10
+ end
11
+
12
+ def incr(key)
13
+ data[key] ||= 0
14
+ data[key] += 1
15
+ end
16
+
17
+ def decr(key)
18
+ data[key] ||= 0
19
+ data[key] -= 1
20
+ end
21
+
22
+ def set(key, val)
23
+ data[key] = val
24
+ end
25
+
26
+ def get(key)
27
+ data[key].dup
28
+ end
29
+
30
+ def lpush(key, val)
31
+ require_array(key)
32
+ data[key].unshift val
33
+ data[key].size
34
+ end
35
+
36
+ def lrem(key, count, val)
37
+ require_array(key)
38
+ arr = get(key)
39
+ removed = 0
40
+
41
+ if count == 0
42
+ removed = (arr.select {|v| v == val}).size
43
+ arr.select! {|v| v != val}
44
+ else
45
+ arr.reverse! if count < 0
46
+
47
+ count.abs.times do
48
+ removed += 1 unless arr.delete_at(arr.index(val) || arr.size).nil?
49
+ end
50
+
51
+ arr.reverse! if count < 0
52
+ end
53
+
54
+ data[key] = arr
55
+ removed
56
+ end
57
+
58
+ def lrange(key, start_idx, end_idx = -1)
59
+ require_array(key)
60
+ data[key][start_idx..end_idx] || []
61
+ end
62
+
63
+ def rpush(key, val)
64
+ require_array(key)
65
+ data[key] << val
66
+ data[key].size
67
+ end
68
+
69
+ def rpushx(key, val)
70
+ return 0 unless data[key]
71
+ rpush key, val
72
+ end
73
+
74
+ def rpop(key)
75
+ require_array(key)
76
+ data[key].pop
77
+ end
78
+
79
+ def rpoplpush(one, two)
80
+ val = rpop(one)
81
+ lpush two, val
82
+ val
83
+ end
84
+
85
+ def keys(pattern = ".*")
86
+ data.keys.filter {|k| k.to_s =~ %r{^#{pattern}$}}
87
+ end
88
+
89
+ def del(*keys)
90
+ keys.flatten!
91
+ i = 0
92
+ keys.map {|k| data.delete(k) && (i += 1) }
93
+ i
94
+ end
95
+
96
+ def method_missing(*)
97
+ return nil
98
+ end
99
+
100
+ private
101
+ def require_array(key)
102
+ data[key] ||= []
103
+ raise_wrong_type unless data[key].is_a?(Array)
104
+ end
105
+
106
+ def raise_wrong_type
107
+ raise Error.new("WRONGTYPE Operation against a key holding the wrong kind of value")
108
+ end
109
+ end
@@ -0,0 +1,3 @@
1
+ class TinyFakeRedis
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,38 @@
1
+ $:.push File.expand_path("lib", __dir__)
2
+
3
+ # Maintain gem's version:
4
+ require "tiny_fake_redis/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tiny_fake_redis"
8
+ spec.version = TinyFakeRedis::VERSION
9
+ spec.authors = ["Sampson Crowley"]
10
+ spec.email = ["sampsonsprojects@gmail.com"]
11
+
12
+ spec.summary = "Pretend to Access a Redis Server"
13
+ spec.description = <<~BODY
14
+ The class in this Gem mimics the calls of `redis-rb` to allow running commands in development and test environments without the need to run a redis server instance
15
+
16
+ It purposefully only implements a small subset of the most useful redis commands
17
+
18
+ To create a fake instance: `redis = TinyFakeRedis.new`
19
+ BODY
20
+ spec.homepage = "https://github.com/SampsonCrowley/tiny_fake_redis"
21
+ spec.license = "MIT"
22
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
23
+
24
+ spec.metadata["homepage_uri"] = spec.homepage
25
+ spec.metadata["source_code_uri"] = spec.homepage
26
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_dependency "zeitwerk", "~> 2", ">= 2.2.2"
38
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tiny_fake_redis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sampson Crowley
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-08-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: zeitwerk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.2.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.2.2
33
+ description: |
34
+ The class in this Gem mimics the calls of `redis-rb` to allow running commands in development and test environments without the need to run a redis server instance
35
+
36
+ It purposefully only implements a small subset of the most useful redis commands
37
+
38
+ To create a fake instance: `redis = TinyFakeRedis.new`
39
+ email:
40
+ - sampsonsprojects@gmail.com
41
+ executables: []
42
+ extensions: []
43
+ extra_rdoc_files: []
44
+ files:
45
+ - ".gitignore"
46
+ - ".travis.yml"
47
+ - Gemfile
48
+ - Gemfile.lock
49
+ - LICENSE.txt
50
+ - README.md
51
+ - Rakefile
52
+ - bin/console
53
+ - bin/setup
54
+ - lib/tiny_fake_redis.rb
55
+ - lib/tiny_fake_redis/version.rb
56
+ - tiny_fake_redis.gemspec
57
+ homepage: https://github.com/SampsonCrowley/tiny_fake_redis
58
+ licenses:
59
+ - MIT
60
+ metadata:
61
+ homepage_uri: https://github.com/SampsonCrowley/tiny_fake_redis
62
+ source_code_uri: https://github.com/SampsonCrowley/tiny_fake_redis
63
+ changelog_uri: https://github.com/SampsonCrowley/tiny_fake_redis/blob/master/CHANGELOG.md
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 2.3.0
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubygems_version: 3.1.3
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Pretend to Access a Redis Server
83
+ test_files: []