Skip to content

Commit d905b2a

Browse files
committed
add jruby compatibility
1 parent ada0421 commit d905b2a

File tree

9 files changed

+52
-8
lines changed

9 files changed

+52
-8
lines changed

.github/workflows/publish.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,19 @@ jobs:
2121
gem push cache_store_redis-*.gem
2222
env:
2323
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
24+
25+
- uses: actions/checkout@v3
26+
- name: Publish JRuby version to RubyGems
27+
uses: ruby/setup-ruby@v1
28+
with:
29+
ruby-version: jruby
30+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
31+
run: |
32+
mkdir -p $HOME/.gem
33+
touch $HOME/.gem/credentials
34+
chmod 0600 $HOME/.gem/credentials
35+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
36+
jruby -S bundle exec rake build cache_store_redis.gemspec
37+
gem push cache_store_redis-*.gem
38+
env:
39+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ services:
33
- redis-server
44
rvm:
55
- 2.3.5
6+
- jruby
67
cache: bundler
78
before_script:
89
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64

Dockerfile-jruby

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM jruby
2+
3+
RUN apk add --no-cache --update bash
4+
5+
# Create application directory and set it as the WORKDIR.
6+
ENV APP_HOME /code
7+
RUN mkdir -p $APP_HOME
8+
WORKDIR $APP_HOME
9+
10+
COPY . $APP_HOME
11+
12+
RUN jruby -S bundle install

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ source 'https://rubygems.org'
33
# Specify your gem's dependencies in cache_store_redis.gemspec
44
gemspec
55

6-
gem 'oj', '3.6.10'
6+
gem 'oj', '3.6.10' unless RUBY_PLATFORM == 'java'
77
gem 'pry'
88
gem 'simplecov', '< 0.18.0'

cache_store_redis.gemspec

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ Gem::Specification.new do |spec|
1919
spec.require_paths = ['lib']
2020

2121
spec.add_development_dependency 'bundler'
22-
spec.add_development_dependency 'pry-byebug'
22+
# spec.add_development_dependency 'pry-byebug'
2323
spec.add_development_dependency 'rake', '~> 10.0'
2424
spec.add_development_dependency 'rspec'
2525
spec.add_development_dependency 'simplecov'
2626
spec.add_development_dependency 'timecop'
2727

28-
spec.add_dependency 'oj'
28+
if RUBY_PLATFORM =~ /java/
29+
spec.platform = 'java'
30+
else
31+
spec.add_dependency 'oj'
32+
end
33+
2934
spec.add_dependency 'redis'
3035
end

lib/cache_store_redis.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
require 'cache_store_redis/version'
55
require 'redis'
66
require 'securerandom'
7-
require 'oj'
87
require 'logger'
98

109
require_relative 'cache_store_redis/redis_connection'

lib/cache_store_redis/redis_cache_store.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ class RedisCacheStore
44
DEFAULT_TTL = 3_600
55

66
def initialize(namespace = nil, config = nil)
7+
unless RUBY_PLATFORM == 'java'
8+
require 'oj'
9+
end
10+
711
@connection_pool = RedisConnectionPool.new(namespace, config)
812

913
@namespace = namespace
@@ -143,11 +147,19 @@ def ping
143147
private
144148

145149
def serialize(object)
146-
Oj.dump(object)
150+
if RUBY_PLATFORM == 'java'
151+
Marshal::dump(object)
152+
else
153+
Oj.dump(object)
154+
end
147155
end
148156

149157
def deserialize(object)
150-
Oj.load(object)
158+
if RUBY_PLATFORM == 'java'
159+
Marshal::load(object)
160+
else
161+
Oj.load(object)
162+
end
151163
end
152164

153165
def build_key(key)

lib/cache_store_redis/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module CacheStoreRedis
2-
VERSION = '2.2.1'
2+
VERSION = '2.3.0.rc1'
33
end

spec/spec_helper.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
require 'timecop'
77
require 'pry'
8-
require 'pry-byebug'
98
require_relative 'test_object'
109
require_relative '../lib/cache_store_redis'
1110

0 commit comments

Comments
 (0)