Skip to content

Commit

Permalink
Merge 50e399b into 4ef85f2
Browse files Browse the repository at this point in the history
  • Loading branch information
i2bskn committed Apr 20, 2017
2 parents 4ef85f2 + 50e399b commit 138c914
Show file tree
Hide file tree
Showing 22 changed files with 128 additions and 491 deletions.
2 changes: 0 additions & 2 deletions .rspec

This file was deleted.

6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: ruby
rvm:
- 2.1.7
- 2.2.3
before_install: gem install bundler -v 1.10.6
- 2.3.3
- 2.4.1
before_install: gem install bundler -v 1.14.6
services:
- redis-server
13 changes: 0 additions & 13 deletions CODE_OF_CONDUCT.md

This file was deleted.

2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in redis_eval.gemspec
gemspec
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/i2bskn/redis_eval. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.

Bug reports and pull requests are welcome on GitHub at https://github.com/i2bskn/redis_eval.

## License

Expand Down
10 changes: 7 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "rake/testtask"

RSpec::Core::RakeTask.new(:spec)
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList['test/**/*_test.rb']
end

task :default => :spec
task :default => :test
1 change: 1 addition & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

Expand Down
3 changes: 1 addition & 2 deletions lib/redis_eval.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
require "redis"

require "redis_eval/version"
require "redis_eval/configuration"
require "redis_eval/generator_methods"
require "redis_eval/script"
require "redis_eval/script_set"
58 changes: 0 additions & 58 deletions lib/redis_eval/configuration.rb

This file was deleted.

50 changes: 0 additions & 50 deletions lib/redis_eval/generator_methods.rb

This file was deleted.

50 changes: 22 additions & 28 deletions lib/redis_eval/script.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
module RedisEval
class Script
attr_reader :name, :script, :sha
attr_accessor :script_set
attr_reader :script, :sha

class << self
# @param path [Pathname]
# @return [RedisEval::Script]
def build_from_path(path)
name = path.basename(".*").to_s
script = File.read(path)
new(name, script)
end

def load(script)
redis.script(:load, script)
end

def flush
redis.script(:flush)
end
def initialize(script, script_set: nil, with_load: true)
@script = script
@sha = Digest::SHA1.hexdigest(script)
self.load if with_load
end

def redis
RedisEval.config.redis
end
def load
redis.script(:load, script)
end

def initialize(name, script)
@name = name
@script = script
@sha = Digest::SHA1.hexdigest(script)
def exist?
redis.script(:exists, sha)
end

def execute(keys = [], argv = [])
Expand All @@ -40,12 +27,19 @@ def execute(keys = [], argv = [])
end
end

def exist?
redis.script(:exists, sha)
def redis
case
when instance_variable_defined?(:@redis)
@redis
when !script_set.nil?
script_set.redis
else
Redis.current
end
end

def redis
self.class.redis
def redis=(conn)
@redis = conn
end
end
end
59 changes: 59 additions & 0 deletions lib/redis_eval/script_set.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module RedisEval
class ScriptSet
attr_reader :src_path

SCRIPT_SUFFIX = ".lua"

def initialize(path)
@src_path = pathname(path)
end

def load(name)
script = script_path(name).read
loaded_scripts[name.to_s] ||= RedisEval::Script.new(script, script_set: self)
end

def load_all_script
src_path.children(false).each do |path|
name = path.basename(SCRIPT_SUFFIX).to_s
script = script_path(name).read
loaded_scripts[name] ||= RedisEval::Script.new(script, script_set: self)
end
true
end

def redis
instance_variable_defined?(:@redis) ? @redis : Redis.current
end

def redis=(conn)
@redis = conn
end

private

def pathname(path)
path.is_a?(Pathname) ? path : Pathname.new(path)
end

def loaded_scripts
@loaded_scripts ||= {}
end

def script_path(name)
src_path.join(name.to_s).sub_ext(SCRIPT_SUFFIX)
end

def method_missing(name, *args, &block)
super unless respond_to?(name)

self.load(name)
define_singleton_method(name) { |*a, &b| loaded_scripts[name.to_s] }
send(name, *args, &block)
end

def respond_to_missing?(name, include_private = false)
loaded_scripts.has_key?(name.to_s) || script_path(name).exist? || super
end
end
end
12 changes: 7 additions & 5 deletions redis_eval.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'redis_eval/version'
require "redis_eval/version"

Gem::Specification.new do |spec|
spec.name = "redis_eval"
Expand All @@ -14,16 +14,18 @@ Gem::Specification.new do |spec|
spec.homepage = "https://github.com/i2bskn/redis_eval"
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "redis"

spec.add_development_dependency "bundler", "~> 1.10"
spec.add_development_dependency "bundler", "~> 1.14"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec"
spec.add_development_dependency "minitest", "~> 5.0"
spec.add_development_dependency "pry"
spec.add_development_dependency "coveralls"
spec.add_development_dependency "simplecov"
Expand Down
1 change: 0 additions & 1 deletion spec/lua_scripts/hello.lua

This file was deleted.

0 comments on commit 138c914

Please sign in to comment.