Skip to content

Commit 269010c

Browse files
committed
update cache using to not add rails gem
1 parent d666b45 commit 269010c

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

Gemfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@ gem 'rake'
66
gem 'pry'
77
gem 'test-unit'
88
gem 'webmock', require: false
9-
# Add these lines to your Gemfile
10-
gem 'rails'
119
gem 'activesupport'

lib/ontologies_api_client/request_federation.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
require 'active_support/core_ext/hash'
2+
require 'active_support/cache'
23

34
module LinkedData
45
module Client
56
module RequestFederation
67

8+
CACHE = ActiveSupport::Cache::MemoryStore.new
9+
710
def self.included(base)
811
base.extend(ClassMethods)
912
end
@@ -17,8 +20,8 @@ def federated_get(params = {}, &link)
1720
portal_name = portal_name_from_id(conn.url_prefix.to_s)
1821
portal_status = true
1922

20-
unless Rails.cache.read("federation_portal_up_#{portal_name}").nil?
21-
portal_status = Rails.cache.read("federation_portal_up_#{portal_name}")
23+
unless CACHE.read("federation_portal_up_#{portal_name}").nil?
24+
portal_status = CACHE.read("federation_portal_up_#{portal_name}")
2225
end
2326

2427
unless portal_status
@@ -29,7 +32,7 @@ def federated_get(params = {}, &link)
2932
begin
3033
HTTP.get(link.call(conn.url_prefix.to_s.chomp('/')), params, connection: conn)
3134
rescue Exception => e
32-
Rails.cache.write("federation_portal_up_#{portal_name}", false, expires_in: 10.minutes)
35+
CACHE.write("federation_portal_up_#{portal_name}", false, expires_in: 10.minutes)
3336
[OpenStruct.new(errors: "Problem retrieving #{link.call(conn.url_prefix.to_s.chomp('/')) || conn.url_prefix}")]
3437
end
3538
end

test/test_case.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77

88
WebMock.allow_net_connect!
99

10-
module Rails
11-
def self.cache
12-
@cache ||= ActiveSupport::Cache::MemoryStore.new
13-
end
14-
end
10+
# Set up a cache for testing
11+
CACHE = ActiveSupport::Cache::MemoryStore.new
1512

1613
module LinkedData
1714
module Client
1815
class TestCase < Test::Unit::TestCase
16+
# You can use CACHE in your tests if needed
1917
end
2018
end
2119
end

0 commit comments

Comments
 (0)