Skip to content

Commit

Permalink
add jruby compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Karl-H committed Aug 22, 2024
1 parent ada0421 commit d905b2a
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 8 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,19 @@ jobs:
gem push cache_store_redis-*.gem
env:
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"

- uses: actions/checkout@v3
- name: Publish JRuby version to RubyGems
uses: ruby/setup-ruby@v1
with:
ruby-version: jruby
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
jruby -S bundle exec rake build cache_store_redis.gemspec
gem push cache_store_redis-*.gem
env:
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ services:
- redis-server
rvm:
- 2.3.5
- jruby
cache: bundler
before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
Expand Down
12 changes: 12 additions & 0 deletions Dockerfile-jruby
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM jruby

RUN apk add --no-cache --update bash

# Create application directory and set it as the WORKDIR.
ENV APP_HOME /code
RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME

COPY . $APP_HOME

RUN jruby -S bundle install
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in cache_store_redis.gemspec
gemspec

gem 'oj', '3.6.10'
gem 'oj', '3.6.10' unless RUBY_PLATFORM == 'java'
gem 'pry'
gem 'simplecov', '< 0.18.0'
9 changes: 7 additions & 2 deletions cache_store_redis.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'pry-byebug'
# spec.add_development_dependency 'pry-byebug'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'timecop'

spec.add_dependency 'oj'
if RUBY_PLATFORM =~ /java/
spec.platform = 'java'
else
spec.add_dependency 'oj'
end

spec.add_dependency 'redis'
end
1 change: 0 additions & 1 deletion lib/cache_store_redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require 'cache_store_redis/version'
require 'redis'
require 'securerandom'
require 'oj'
require 'logger'

require_relative 'cache_store_redis/redis_connection'
Expand Down
16 changes: 14 additions & 2 deletions lib/cache_store_redis/redis_cache_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ class RedisCacheStore
DEFAULT_TTL = 3_600

def initialize(namespace = nil, config = nil)
unless RUBY_PLATFORM == 'java'
require 'oj'
end

@connection_pool = RedisConnectionPool.new(namespace, config)

@namespace = namespace
Expand Down Expand Up @@ -143,11 +147,19 @@ def ping
private

def serialize(object)
Oj.dump(object)
if RUBY_PLATFORM == 'java'
Marshal::dump(object)
else
Oj.dump(object)
end
end

def deserialize(object)
Oj.load(object)
if RUBY_PLATFORM == 'java'
Marshal::load(object)
else
Oj.load(object)
end
end

def build_key(key)
Expand Down
2 changes: 1 addition & 1 deletion lib/cache_store_redis/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CacheStoreRedis
VERSION = '2.2.1'
VERSION = '2.3.0.rc1'
end
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

require 'timecop'
require 'pry'
require 'pry-byebug'
require_relative 'test_object'
require_relative '../lib/cache_store_redis'

Expand Down

0 comments on commit d905b2a

Please sign in to comment.