object_cacheable 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5b703416923183e0df7b7f7f4d58deb6e429f655
4
+ data.tar.gz: 2e2f3cfb5a785eac0eee3df52e5bc1496932f82e
5
+ SHA512:
6
+ metadata.gz: e35c99306cc8616c2336a26ef79ee1ee682d87493bfb843758960389564f4a2c19be204f4d0cc6c0a3638decc8fb2b5b65af549009072baa1f1e4f9cf5b32223
7
+ data.tar.gz: 89289e2429805107df10710985553d863094e1aadd35590ddd49be8a9e02c92700c98213788dc213783cacd8d5c68e6c9077b0beb220e3f395666c1b9181c848
data/Gemfile CHANGED
File without changes
File without changes
@@ -14,28 +14,42 @@ module Cacheable
14
14
  @@cache_instance = nil
15
15
  @@logger_instance = nil
16
16
 
17
- def self.load_config
18
- configs = YAML.load_file("#{File.dirname(__FILE__)}/cache_configs.yml")
19
- env = environment
17
+ class << self
18
+ def load_config
19
+ base_path = File.expand_path('.')
20
+ config_file = nil
21
+ ['conf', 'config'].each do |sub_path|
22
+ if File.exist?("#{base_path}/#{sub_path}/cache_configs.yml")
23
+ config_file = "#{base_path}/#{sub_path}/cache_configs.yml"
24
+ end
25
+ end
26
+
27
+ raise("You must have the file cache_configs.yml in either 'conf' or 'config' directory of your application") unless config_file
28
+
29
+ configs = YAML.load_file(config_file)
30
+ env = environment
31
+
32
+ @@cache_instance = eval(configs[env]['cache'])
33
+ @@logger_instance = eval(configs[env]['logger'])
34
+ end
20
35
 
21
- @@cache_instance = eval(configs[env]['cache'])
22
- @@logger_instance = eval(configs[env]['logger'])
23
- end
24
-
25
- def self.environment
26
- Rails.env
27
- rescue => error
28
- 'test'
29
- end
30
-
31
- def self.cache
32
- load_config if @@cache_instance.nil?
33
- @@cache_instance
34
- end
35
-
36
- def self.logger
37
- load_config if @@logger_instance.nil?
38
- @@logger_instance
39
- end
40
- end
36
+ def environment
37
+ return Rails.env if defined? Rails
38
+ return ENV['RACK_ENV'] if ENV['RACK_ENV']
39
+ 'test'
40
+ rescue => error
41
+ 'test'
42
+ end
43
+
44
+ def cache
45
+ load_config if @@cache_instance.nil?
46
+ @@cache_instance
47
+ end
48
+
49
+ def logger
50
+ load_config if @@logger_instance.nil?
51
+ @@logger_instance
52
+ end
53
+ end # class methods
54
+ end # class CacheConfiguration
41
55
  end
data/lib/cache_utils.rb CHANGED
File without changes
@@ -1,13 +1,13 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'object_cacheable'
3
- s.version = '1.0.0'
3
+ s.version = '1.1.1'
4
4
  s.summary = "Object-level caching"
5
5
  s.description = "A gem for object-level caching."
6
6
  s.authors = ['Linh Chau']
7
7
  s.email = 'chauhonglinh@gmail.com'
8
8
  s.files = [
9
- './Gemfile', './object_cacheable.gemspec',
10
- 'lib/cache_configs.yml', 'lib/cache_configuration.rb', 'lib/cache_utils.rb', 'lib/cacheable.rb',
9
+ './Gemfile', './object_cacheable.gemspec', './object_cacheable.rb',
10
+ 'conf/cache_configs.yml', 'lib/cache_configuration.rb', 'lib/cache_utils.rb', 'lib/cacheable.rb',
11
11
  'test/models/cacheable_test.rb'
12
12
  ]
13
13
  s.homepage = 'https://github.com/linhchauatl/object_cacheable.git'
@@ -0,0 +1 @@
1
+ require './lib/cacheable'
@@ -66,9 +66,10 @@ describe Cacheable do
66
66
  cached_obj.must_equal obj
67
67
 
68
68
  # Make sure that it doesn't make a real call to fetch the second time
69
- TestCacheable.stubs(:fetch).returns(nil) # If this gets called, the result_obj will be nil
70
- result_obj = TestCacheable.fetch_by_id(1)
71
- result_obj.must_equal obj
69
+ TestCacheable.stub(:fetch, nil) do
70
+ result_obj = TestCacheable.fetch_by_id(1)
71
+ result_obj.must_equal obj
72
+ end
72
73
 
73
74
  # clean the cache after finish
74
75
  obj.delete_from_cache
metadata CHANGED
@@ -1,68 +1,50 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: object_cacheable
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 0
8
- - 0
9
- version: 1.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.1
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Linh Chau
13
8
  autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
-
17
- date: 2013-03-28 00:00:00 -05:00
18
- default_executable:
11
+ date: 2014-11-16 00:00:00.000000000 Z
19
12
  dependencies: []
20
-
21
13
  description: A gem for object-level caching.
22
14
  email: chauhonglinh@gmail.com
23
15
  executables: []
24
-
25
16
  extensions: []
26
-
27
17
  extra_rdoc_files: []
28
-
29
- files:
30
- - ./Gemfile
31
- - ./object_cacheable.gemspec
32
- - lib/cache_configs.yml
18
+ files:
19
+ - "./Gemfile"
20
+ - "./object_cacheable.gemspec"
21
+ - "./object_cacheable.rb"
22
+ - conf/cache_configs.yml
33
23
  - lib/cache_configuration.rb
34
24
  - lib/cache_utils.rb
35
25
  - lib/cacheable.rb
36
26
  - test/models/cacheable_test.rb
37
- has_rdoc: true
38
27
  homepage: https://github.com/linhchauatl/object_cacheable.git
39
28
  licenses: []
40
-
29
+ metadata: {}
41
30
  post_install_message:
42
31
  rdoc_options: []
43
-
44
- require_paths:
32
+ require_paths:
45
33
  - lib
46
- required_ruby_version: !ruby/object:Gem::Requirement
47
- requirements:
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
48
36
  - - ">="
49
- - !ruby/object:Gem::Version
50
- segments:
51
- - 0
52
- version: "0"
53
- required_rubygems_version: !ruby/object:Gem::Requirement
54
- requirements:
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
55
41
  - - ">="
56
- - !ruby/object:Gem::Version
57
- segments:
58
- - 0
59
- version: "0"
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
60
44
  requirements: []
61
-
62
45
  rubyforge_project:
63
- rubygems_version: 1.3.6
46
+ rubygems_version: 2.4.3
64
47
  signing_key:
65
- specification_version: 3
48
+ specification_version: 4
66
49
  summary: Object-level caching
67
50
  test_files: []
68
-