Skip to content

Commit

Permalink
Merge b54ecc4 into 83a70a7
Browse files Browse the repository at this point in the history
  • Loading branch information
0exp committed Aug 22, 2018
2 parents 83a70a7 + b54ecc4 commit f094b12
Show file tree
Hide file tree
Showing 56 changed files with 2,056 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ AllCops:
- Gemfile
- Rakefile
- any_cache.gemspec

Layout/MultilineOperationIndentation:
Enabled: false
86 changes: 82 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,83 @@
sudo: false
language: ruby
rvm:
- 2.5.1
before_install: gem install bundler -v 1.16.2
sudo: false
before_install: gem install bundler
cache: bundler
script: bundle exec rspec
services:
- redis-server
- memcached
matrix:
fast_finish: true
include:
- rvm: 2.3.7
gemfile: gemfiles/active_support.gemfile
env: TEST_AS_MEMORY_STORE_CACHE=true
- rvm: 2.4.4
gemfile: gemfiles/active_support.gemfile
env: TEST_AS_MEMORY_STORE_CACHE=true
- rvm: 2.5.1
gemfile: gemfiles/active_support.gemfile
env: TEST_AS_MEMORY_STORE_CACHE=true
- rvm: ruby-head
gemfile: gemfiles/active_support.gemfile
env: TEST_AS_MEMORY_STORE_CACHE=true
- rvm: 2.3.7
gemfile: gemfiles/active_support.gemfile
env: TEST_AS_FILE_STORE_CACHE=true
- rvm: 2.4.4
gemfile: gemfiles/active_support.gemfile
env: TEST_AS_FILE_STORE_CACHE=true
- rvm: 2.5.1
gemfile: gemfiles/active_support.gemfile
env: TEST_AS_FILE_STORE_CACHE=true
- rvm: ruby-head
gemfile: gemfiles/active_support.gemfile
env: TEST_AS_FILE_STORE_CACHE=true
- rvm: 2.3.7
gemfile: gemfiles/active_support_with_redis.gemfile
env: TEST_AS_REDIS_CACHE_STORE_CACHE=true
- rvm: 2.4.4
gemfile: gemfiles/active_support_with_redis.gemfile
env: TEST_AS_REDIS_CACHE_STORE_CACHE=true
- rvm: 2.5.1
gemfile: gemfiles/active_support_with_redis.gemfile
env: TEST_AS_REDIS_CACHE_STORE_CACHE=true
- rvm: ruby-head
gemfile: gemfiles/active_support_with_redis.gemfile
env: TEST_AS_REDIS_CACHE_STORE_CACHE=true
- rvm: 2.3.7
gemfile: gemfiles/dalli.gemfile
env: TEST_DALLI_CACHE=true
- rvm: 2.4.4
gemfile: gemfiles/dalli.gemfile
env: TEST_DALLI_CACHE=true
- rvm: 2.5.1
gemfile: gemfiles/dalli.gemfile
env: TEST_DALLI_CACHE=true
- rvm: ruby-head
gemfile: gemfiles/dalli.gemfile
env: TEST_DALLI_CACHE=true
- rvm: 2.3.7
gemfile: gemfiles/redis_store.gemfile
env: TEST_REDIS_STORE_CACHE=true
- rvm: 2.4.4
gemfile: gemfiles/redis_store.gemfile
env: TEST_REDIS_STORE_CACHE=true
- rvm: 2.5.1
gemfile: gemfiles/redis_store.gemfile
env: TEST_REDIS_STORE_CACHE=true
- rvm: ruby-head
gemfile: gemfiles/redis_store.gemfile
env: TEST_REDIS_STORE_CACHE=true
- rvm: 2.3.7
gemfile: gemfiles/redis_store.gemfile
env: TEST_REDIS_CACHE=true
- rvm: 2.4.4
gemfile: gemfiles/redis_store.gemfile
env: TEST_REDIS_CACHE=true
- rvm: 2.5.1
gemfile: gemfiles/redis_store.gemfile
env: TEST_REDIS_CACHE=true
- rvm: ruby-head
gemfile: gemfiles/redis_store.gemfile
env: TEST_REDIS_CACHE=true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# AnyCache
# AnyCache · [![Gem Version](https://badge.fury.io/rb/any_cache.svg)](https://badge.fury.io/rb/any_cache) [![Build Status](https://travis-ci.org/0exp/any_cache.svg?branch=master)](https://travis-ci.org/0exp/any_cache) [![Coverage Status](https://coveralls.io/repos/github/0exp/any_cache/badge.svg)](https://coveralls.io/github/0exp/any_cache)

In active development.

Expand Down
7 changes: 4 additions & 3 deletions any_cache.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'any_cache/version'

Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.3.7'

spec.name = 'any_cache'
spec.version = AnyCache::VERSION

spec.authors = ['Rustam Ibragimov']
spec.email = ['iamdaiver@icloud.com']
spec.summary = 'Soon'
spec.description = 'Soon'
spec.homepage = 'https://github.com/0exp/any_cache'
spec.license = 'MIT'

spec.bindir = 'bin'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
Expand All @@ -23,7 +23,8 @@ Gem::Specification.new do |spec|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|features)/}) }
end

spec.add_dependency 'qonfig', '~> 0.5'
spec.add_dependency 'qonfig', '~> 0.5'
spec.add_dependency 'concurrent-ruby', '~> 1.0'

spec.add_development_dependency 'coveralls', '~> 0.8'
spec.add_development_dependency 'simplecov', '~> 0.16'
Expand Down
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
require 'bundler/setup'
require 'any_cache'

require "pry"
require 'pry'
Pry.start
119 changes: 119 additions & 0 deletions bin/rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'pathname'
require 'optparse'

module AnyCacheSpecRunner
extend self

def expand_gemfile_path(gemfile_name)
File.expand_path(
File.join('..', '..', 'gemfiles', gemfile_name),
Pathname.new(__FILE__).realpath
)
end

GEMFILES = {
redis: expand_gemfile_path('redis.gemfile'),
redis_store: expand_gemfile_path('redis_store.gemfile'),
dalli: expand_gemfile_path('dalli.gemfile'),
active_support_with_redis: expand_gemfile_path('active_support_with_redis.gemfile'),
active_support: expand_gemfile_path('active_support.gemfile')
}.freeze

# rubocop:disable Metrics/MethodLength, Metrics/BlockLength
def run!
OptionParser.new do |opts|
opts.banner = 'Usage: bin/rspec [options]'

opts.on(
'--test-redis',
'Run specs with Redis cache storage'
) { run_redis_cache_specs! }

opts.on(
'--test-redis-store',
'Run specs with Redis::Store cache storage'
) { run_redis_store_cache_specs! }

opts.on(
'--test-dalli',
'Run specs with Dalli spec storage'
) { run_dalli_cache_specs! }

opts.on(
'--test-as-redis-cache-store',
'Run specs with ActiveSupport::Cache::RedisCacheStore cache storage'
) { run_as_redis_cache_store_cache_specs! }

opts.on(
'--test-as-file-store',
'Run specs with ActiveSupport::Cache::FileStore cache storage'
) { run_as_file_store_cache_specs! }

opts.on(
'--test-as-memory-store',
'Run specs with ActiveSupport::Cache::MemoryStore cache storage'
) { run_as_memory_store_cache_specs! }

opts.on(
'-h', '--help',
'Show this message'
) { puts opts }
end.parse!
end
# rubocop:enable Metrics/MethodLength, Metrics/BlockLength

private

def run_redis_cache_specs!
ENV['TEST_REDIS_CACHE'] = 'true'
ENV['BUNDLE_GEMFILE'] = GEMFILES[:redis]

run_tests!
end

def run_redis_store_cache_specs!
ENV['TEST_REDIS_STORE_CACHE'] = 'true'
ENV['BUNDLE_GEMFILE'] = GEMFILES[:redis_store]

run_tests!
end

def run_dalli_cache_specs!
ENV['TEST_DALLI_CACHE'] = 'true'
ENV['BUNDLE_GEMFILE'] = GEMFILES[:dalli]

run_tests!
end

def run_as_redis_cache_store_cache_specs!
ENV['TEST_AS_REDIS_CACHE_STORE_CACHE'] = 'true'
ENV['BUNDLE_GEMFILE'] = GEMFILES[:active_support_with_redis]

run_tests!
end

def run_as_file_store_cache_specs!
ENV['TEST_AS_FILE_STORE_CACHE'] = 'true'
ENV['BUNDLE_GEMFILE'] = GEMFILES[:active_support]

run_tests!
end

def run_as_memory_store_cache_specs!
ENV['TEST_AS_MEMORY_STORE_CACHE'] = 'true'
ENV['BUNDLE_GEMFILE'] = GEMFILES[:active_support]

run_tests!
end

def run_tests!
require 'rubygems'
require 'bundler/setup'
load Gem.bin_path('rspec-core', 'rspec')
end
end

AnyCacheSpecRunner.run!
7 changes: 7 additions & 0 deletions gemfiles/active_support.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'activesupport', '~> 5.2'

gemspec path: '..'
8 changes: 8 additions & 0 deletions gemfiles/active_support_with_redis.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'redis', '~> 4.0'
gem 'activesupport', '~> 5.2'

gemspec path: '..'
7 changes: 7 additions & 0 deletions gemfiles/dalli.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'dalli', '~> 2.7'

gemspec path: '..'
7 changes: 7 additions & 0 deletions gemfiles/redis.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'redis', '~> 4.0'

gemspec path: '..'
7 changes: 7 additions & 0 deletions gemfiles/redis_store.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'redis-store', '~> 1.5'

gemspec path: '..'
40 changes: 38 additions & 2 deletions lib/any_cache.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,44 @@
# frozen_string_literal: true

require 'any_cache/version'
require 'securerandom'
require 'qonfig'
require 'concurrent/atomic/reentrant_read_write_lock'

# @api public
# @since 0.1.0
module AnyCache
class AnyCache
require_relative 'any_cache/version'
require_relative 'any_cache/adapters'

# @since 0.1.0
extend Forwardable

class << self
# @param driver [Object]
# @return [AnyCache]
#
# @api private
# @since 0.1.0
def build(driver)
new(Adapters.build(driver))
end
end

# @since 0.1.0
def_delegators :adapter, :read, :write, :delete, :increment, :decrement, :re_expire, :clear

# @return [AnyCache::Adapters::Basic]
#
# @api private
# @since 0.1.0
attr_reader :adapter

# @param adapter [AnyCache::Adapters::Basic]
# @return [void]
#
# @api private
# @since 0.1.0
def initialize(adapter)
@adapter = adapter
end
end
40 changes: 40 additions & 0 deletions lib/any_cache/adapters.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

# @api private
# @since 0.1.0
module AnyCache::Adapters
require_relative 'adapters/basic'
require_relative 'adapters/delegator'
require_relative 'adapters/dalli'
require_relative 'adapters/redis'
require_relative 'adapters/redis_store'
require_relative 'adapters/active_support_naive_store'
require_relative 'adapters/active_support_file_store'
require_relative 'adapters/active_support_redis_cache_store'
require_relative 'adapters/active_support_memory_store'

class << self
# @param driver [Object]
# @return [AnyCache::Adapters::Basic]
#
# @raise [AnyCache::UnsupportedCacheDriverError]
#
# @api private
# @since 0.1.0
# rubocop:disable Metrics/LineLength
def build(driver)
case
when RedisStore.supported_driver?(driver) then RedisStore.new(driver)
when Redis.supported_driver?(driver) then Redis.new(driver)
when Dalli.supported_driver?(driver) then Dalli.new(driver)
when ActiveSupportRedisCacheStore.supported_driver?(driver) then ActiveSupportRedisCacheStore.new(driver)
when ActiveSupportMemoryStore.supported_driver?(driver) then ActiveSupportMemoryStore.new(driver)
when ActiveSupportFileStore.supported_driver?(driver) then ActiveSupportFileStore.new(driver)
when Delegator.supported_driver?(driver) then Delegator.new(driver)
else
raise AnyCache::UnsupportedCacheDriverError
end
end
# rubocop:enable Metrics/LineLength
end
end
Loading

0 comments on commit f094b12

Please sign in to comment.