radiospieler 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -7,6 +7,7 @@ gem "pg"
7
7
  gem "sqlite3"
8
8
  gem "redis"
9
9
  gem "micro_sql"
10
+ gem "simple_cache"
10
11
  gem "htmlentities"
11
12
 
12
13
  # Add dependencies to develop your gem here.
data/Gemfile.lock CHANGED
@@ -35,6 +35,8 @@ GEM
35
35
  ruby-debug-base19 (>= 0.11.19)
36
36
  ruby_core_source (0.1.5)
37
37
  archive-tar-minitar (>= 0.5.2)
38
+ simple_cache (0.8.1)
39
+ sqlite3
38
40
  simplecov (0.6.1)
39
41
  multi_json (~> 1.0)
40
42
  simplecov-html (~> 0.5.3)
@@ -57,6 +59,7 @@ DEPENDENCIES
57
59
  psych
58
60
  redis
59
61
  ruby-debug19
62
+ simple_cache
60
63
  simplecov
61
64
  sqlite3
62
65
  vcr
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -1,77 +1,86 @@
1
1
  require_relative "config"
2
+ require "simple_cache"
2
3
 
3
- #
4
- # This is a cache module, which keeps entries for a certain time period,
5
- # stored away in a redis store.
4
+ # This is a cache module, which keeps entries for a certain time period (or forever).
6
5
  #
7
6
  # Entries are packed via Marshal.
8
7
  module App
9
8
  module Cache
10
9
  DEFAULT_MAX_AGE = 4 * 3600 # 4 hours.
11
10
 
12
- def self.clear
13
- store.flushdb
14
- end
15
-
16
- def self.uid(key)
17
- case key
18
- when String, Hash then key.uid64
19
- when Fixnum then key
20
- else
21
- App.logger.warn "Don't know how to deal with non-uid key #{key}"
22
- nil
23
- end
11
+ def self.store
12
+ @store ||= Store.create(App.config[:cache]) || Store.fallback
24
13
  end
25
-
26
- def self.cached(key, max_age = DEFAULT_MAX_AGE, &block)
27
- cache_id = uid(key)
28
14
 
29
- return yield if !store || !max_age || !cache_id
30
-
31
- if marshalled = store.get(cache_id)
32
- unmarshal(marshalled)
33
- else
34
- yield.tap { |v|
35
- store.set(cache_id, marshal(v))
36
- store.expire(cache_id, max_age)
37
- }
38
- end
15
+ def self.store=(store)
16
+ @store = store
39
17
  end
40
18
 
41
- def self.unmarshal(marshalled)
42
- Marshal.load Base64.decode64(marshalled) if marshalled
19
+ def self.clear
20
+ store.clear
43
21
  end
44
22
 
45
- def self.marshal(value)
46
- Base64.encode64 Marshal.dump(value)
23
+ module Store
24
+ def self.create(url)
25
+ return unless url
26
+
27
+ uri = URI.parse(url)
28
+ case uri.scheme
29
+ when "redis" then RedisStore.new(url)
30
+ when nil then ::SimpleCache.new(uri.path)
31
+ end
32
+ end
33
+
34
+ def self.fallback
35
+ name = "#{File.basename(App.root)}/a#{App.root.uid64}"
36
+ SimpleCache.new(name).tap do |store|
37
+ App.logger.warn "No, invalid, or unsupported :cache configuration, fallback to #{store.path}"
38
+ end
39
+ end
47
40
  end
48
-
49
- def self.store_from_url(url)
50
- return unless url
51
- uri = URI.parse(url)
52
- case uri.scheme
53
- when "redis"
41
+
42
+ class Store::RedisStore
43
+ def initialize(url)
54
44
  require "redis"
55
- Redis.connect(:url => url)
56
- when nil
57
- SimpleCache.new(uri.path)
45
+ @redis = Redis.connect(:url => url)
58
46
  end
59
- end
60
-
61
- attr :store, true
62
- extend self
63
-
64
- def self.store
65
- @store ||= store_from_url(App.config[:cache]) || begin
66
- name = "#{File.basename(App.root)}-#{App.root.uid64}"
67
- store = SimpleCache.new(name)
68
- App.logger.warn "No or invalid :cache configuration, fallback to #{store.path}"
69
- store
47
+
48
+ include SimpleCache::Marshal
49
+
50
+ def keys
51
+ @redis.keys
52
+ end
53
+
54
+ def clear
55
+ @redis.flushdb
56
+ #debugger
57
+ 1
58
+ end
59
+
60
+ def store(key, value, max_age = DEFAULT_MAX_AGE)
61
+ cache_id = uid(key)
62
+ if value
63
+ @redis.set cache_id, marshal(value)
64
+ @redis.expire cache_id, max_age if max_age
65
+ else
66
+ @redis.del cache_id
67
+ end
68
+ value
69
+ end
70
+
71
+ def fetch(key, &block)
72
+ marshalled = @redis.get(uid(key))
73
+ marshalled ? unmarshal(marshalled) : yield
70
74
  end
71
75
  end
72
76
  end
73
77
 
74
78
  def cached(key, max_age = Cache::DEFAULT_MAX_AGE, &block)
75
- Cache.cached(key, max_age, &block)
79
+ return yield if !max_age
80
+
81
+ cache_store = Cache.store
82
+ cache_store.fetch(key) do
83
+ cache_store.store(key, yield, max_age)
84
+ end
76
85
  end
77
86
  end
@@ -0,0 +1,120 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "radiospieler"
8
+ s.version = "0.3.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["radiospiel"]
12
+ s.date = "2012-04-05"
13
+ s.description = "Some basics that your application could benefit from."
14
+ s.email = "eno@open-lab.org"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "app.tmproj",
28
+ "config/app.yml",
29
+ "lib/core-extensions/array_ext.rb",
30
+ "lib/core-extensions/benchmark-logger.rb",
31
+ "lib/core-extensions/cgi_ext.rb",
32
+ "lib/core-extensions/hash_ext.rb",
33
+ "lib/core-extensions/object_ext.rb",
34
+ "lib/core-extensions/string_ext.rb",
35
+ "lib/core-extensions/string_without_accents.rb",
36
+ "lib/core-extensions/tls.rb",
37
+ "lib/core-extensions/uids.rb",
38
+ "lib/core-extensions/uri_ext.rb",
39
+ "lib/extensions/bitly.rb",
40
+ "lib/extensions/http.rb",
41
+ "lib/radiospieler.rb",
42
+ "lib/radiospieler/radiospieler.rb",
43
+ "lib/radiospieler/radiospieler/cache.rb",
44
+ "lib/radiospieler/radiospieler/config.rb",
45
+ "lib/radiospieler/radiospieler/logger.rb",
46
+ "lib/radiospieler/radiospieler/root.rb",
47
+ "radiospieler.gemspec",
48
+ "script/watchr",
49
+ "test/app_test.rb",
50
+ "test/array_ext_test.rb",
51
+ "test/bitlify_test.rb",
52
+ "test/cache_test.rb",
53
+ "test/cgi_ext_test.rb",
54
+ "test/config.yml",
55
+ "test/config_test.rb",
56
+ "test/fixtures-vcr/bitly_limit_exceeded.yml",
57
+ "test/fixtures-vcr/bitly_ok.yml",
58
+ "test/fixtures-vcr/http_test.yml",
59
+ "test/hash_ext_test.rb",
60
+ "test/http_test.rb",
61
+ "test/string_ext_test.rb",
62
+ "test/test_helper.rb",
63
+ "test/tls_test.rb",
64
+ "test/uid_test.rb"
65
+ ]
66
+ s.homepage = "http://github.com/radiospiel/radiospieler"
67
+ s.licenses = ["MIT"]
68
+ s.require_paths = ["lib"]
69
+ s.rubygems_version = "1.8.17"
70
+ s.summary = "Application base code"
71
+
72
+ if s.respond_to? :specification_version then
73
+ s.specification_version = 3
74
+
75
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
76
+ s.add_runtime_dependency(%q<pg>, [">= 0"])
77
+ s.add_runtime_dependency(%q<sqlite3>, [">= 0"])
78
+ s.add_runtime_dependency(%q<redis>, [">= 0"])
79
+ s.add_runtime_dependency(%q<micro_sql>, [">= 0"])
80
+ s.add_runtime_dependency(%q<simple_cache>, [">= 0"])
81
+ s.add_runtime_dependency(%q<htmlentities>, [">= 0"])
82
+ s.add_development_dependency(%q<bundler>, [">= 0"])
83
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
84
+ s.add_development_dependency(%q<vcr>, [">= 0"])
85
+ s.add_development_dependency(%q<webmock>, [">= 0"])
86
+ s.add_development_dependency(%q<psych>, [">= 0"])
87
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
88
+ s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
89
+ else
90
+ s.add_dependency(%q<pg>, [">= 0"])
91
+ s.add_dependency(%q<sqlite3>, [">= 0"])
92
+ s.add_dependency(%q<redis>, [">= 0"])
93
+ s.add_dependency(%q<micro_sql>, [">= 0"])
94
+ s.add_dependency(%q<simple_cache>, [">= 0"])
95
+ s.add_dependency(%q<htmlentities>, [">= 0"])
96
+ s.add_dependency(%q<bundler>, [">= 0"])
97
+ s.add_dependency(%q<jeweler>, [">= 0"])
98
+ s.add_dependency(%q<vcr>, [">= 0"])
99
+ s.add_dependency(%q<webmock>, [">= 0"])
100
+ s.add_dependency(%q<psych>, [">= 0"])
101
+ s.add_dependency(%q<simplecov>, [">= 0"])
102
+ s.add_dependency(%q<ruby-debug19>, [">= 0"])
103
+ end
104
+ else
105
+ s.add_dependency(%q<pg>, [">= 0"])
106
+ s.add_dependency(%q<sqlite3>, [">= 0"])
107
+ s.add_dependency(%q<redis>, [">= 0"])
108
+ s.add_dependency(%q<micro_sql>, [">= 0"])
109
+ s.add_dependency(%q<simple_cache>, [">= 0"])
110
+ s.add_dependency(%q<htmlentities>, [">= 0"])
111
+ s.add_dependency(%q<bundler>, [">= 0"])
112
+ s.add_dependency(%q<jeweler>, [">= 0"])
113
+ s.add_dependency(%q<vcr>, [">= 0"])
114
+ s.add_dependency(%q<webmock>, [">= 0"])
115
+ s.add_dependency(%q<psych>, [">= 0"])
116
+ s.add_dependency(%q<simplecov>, [">= 0"])
117
+ s.add_dependency(%q<ruby-debug19>, [">= 0"])
118
+ end
119
+ end
120
+
data/test/app_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require_relative 'test_helper'
2
2
 
3
3
  class TestApp < Test::Unit::TestCase
4
4
  def test_root
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'helper'
3
+ require_relative 'test_helper'
4
4
 
5
5
  class ArrayExtTest < Test::Unit::TestCase
6
6
  def test_extract_options
data/test/bitlify_test.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require_relative './helper'
3
+ require_relative './test_helper'
4
4
  require 'vcr'
5
5
 
6
6
  VCR.configure do |c|
data/test/cache_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require_relative 'test_helper'
2
2
 
3
3
  class CacheTest < Test::Unit::TestCase
4
4
  def test_caching
data/test/cgi_ext_test.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'helper'
3
+ require_relative 'test_helper'
4
4
 
5
5
  class CgiExtTest < Test::Unit::TestCase
6
6
  def test_url_for
data/test/config_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require_relative 'test_helper'
2
2
 
3
3
  class TestConfig < Test::Unit::TestCase
4
4
  def test_read_from_test_config
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'helper'
3
+ require_relative 'test_helper'
4
4
 
5
5
  class HashExtTest < Test::Unit::TestCase
6
6
  def test_stringify
data/test/http_test.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'helper'
3
+ require_relative 'test_helper'
4
4
  require 'vcr'
5
5
 
6
6
  VCR.configure do |c|
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'helper'
3
+ require_relative 'test_helper'
4
4
 
5
5
  class StringExtTest < Test::Unit::TestCase
6
6
  def test_html_decode
File without changes
data/test/tls_test.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'helper'
3
+ require_relative 'test_helper'
4
4
 
5
5
  class TlsTest < Test::Unit::TestCase
6
6
  thread_local_attribute :tester
data/test/uid_test.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'helper'
3
+ require_relative 'test_helper'
4
4
 
5
5
  class UidTest < Test::Unit::TestCase
6
6
  def test_string_uids
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiospieler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pg
16
- requirement: &70278898758980 !ruby/object:Gem::Requirement
16
+ requirement: &70359227563120 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70278898758980
24
+ version_requirements: *70359227563120
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &70278898757820 !ruby/object:Gem::Requirement
27
+ requirement: &70359227562000 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70278898757820
35
+ version_requirements: *70359227562000
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: redis
38
- requirement: &70278898756340 !ruby/object:Gem::Requirement
38
+ requirement: &70359227560880 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70278898756340
46
+ version_requirements: *70359227560880
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: micro_sql
49
- requirement: &70278898754320 !ruby/object:Gem::Requirement
49
+ requirement: &70359227559640 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,21 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70278898754320
57
+ version_requirements: *70359227559640
58
+ - !ruby/object:Gem::Dependency
59
+ name: simple_cache
60
+ requirement: &70359227558760 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *70359227558760
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: htmlentities
60
- requirement: &70278898753620 !ruby/object:Gem::Requirement
71
+ requirement: &70359227541000 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ! '>='
@@ -65,10 +76,10 @@ dependencies:
65
76
  version: '0'
66
77
  type: :runtime
67
78
  prerelease: false
68
- version_requirements: *70278898753620
79
+ version_requirements: *70359227541000
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: bundler
71
- requirement: &70278898753140 !ruby/object:Gem::Requirement
82
+ requirement: &70359227540160 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - ! '>='
@@ -76,10 +87,10 @@ dependencies:
76
87
  version: '0'
77
88
  type: :development
78
89
  prerelease: false
79
- version_requirements: *70278898753140
90
+ version_requirements: *70359227540160
80
91
  - !ruby/object:Gem::Dependency
81
92
  name: jeweler
82
- requirement: &70278898752400 !ruby/object:Gem::Requirement
93
+ requirement: &70359227539520 !ruby/object:Gem::Requirement
83
94
  none: false
84
95
  requirements:
85
96
  - - ! '>='
@@ -87,10 +98,10 @@ dependencies:
87
98
  version: '0'
88
99
  type: :development
89
100
  prerelease: false
90
- version_requirements: *70278898752400
101
+ version_requirements: *70359227539520
91
102
  - !ruby/object:Gem::Dependency
92
103
  name: vcr
93
- requirement: &70278898751400 !ruby/object:Gem::Requirement
104
+ requirement: &70359227538720 !ruby/object:Gem::Requirement
94
105
  none: false
95
106
  requirements:
96
107
  - - ! '>='
@@ -98,10 +109,10 @@ dependencies:
98
109
  version: '0'
99
110
  type: :development
100
111
  prerelease: false
101
- version_requirements: *70278898751400
112
+ version_requirements: *70359227538720
102
113
  - !ruby/object:Gem::Dependency
103
114
  name: webmock
104
- requirement: &70278898750540 !ruby/object:Gem::Requirement
115
+ requirement: &70359227537260 !ruby/object:Gem::Requirement
105
116
  none: false
106
117
  requirements:
107
118
  - - ! '>='
@@ -109,10 +120,10 @@ dependencies:
109
120
  version: '0'
110
121
  type: :development
111
122
  prerelease: false
112
- version_requirements: *70278898750540
123
+ version_requirements: *70359227537260
113
124
  - !ruby/object:Gem::Dependency
114
125
  name: psych
115
- requirement: &70278898749860 !ruby/object:Gem::Requirement
126
+ requirement: &70359227535340 !ruby/object:Gem::Requirement
116
127
  none: false
117
128
  requirements:
118
129
  - - ! '>='
@@ -120,10 +131,10 @@ dependencies:
120
131
  version: '0'
121
132
  type: :development
122
133
  prerelease: false
123
- version_requirements: *70278898749860
134
+ version_requirements: *70359227535340
124
135
  - !ruby/object:Gem::Dependency
125
136
  name: simplecov
126
- requirement: &70278898748920 !ruby/object:Gem::Requirement
137
+ requirement: &70359227534760 !ruby/object:Gem::Requirement
127
138
  none: false
128
139
  requirements:
129
140
  - - ! '>='
@@ -131,10 +142,10 @@ dependencies:
131
142
  version: '0'
132
143
  type: :development
133
144
  prerelease: false
134
- version_requirements: *70278898748920
145
+ version_requirements: *70359227534760
135
146
  - !ruby/object:Gem::Dependency
136
147
  name: ruby-debug19
137
- requirement: &70278898748160 !ruby/object:Gem::Requirement
148
+ requirement: &70359227533920 !ruby/object:Gem::Requirement
138
149
  none: false
139
150
  requirements:
140
151
  - - ! '>='
@@ -142,7 +153,7 @@ dependencies:
142
153
  version: '0'
143
154
  type: :development
144
155
  prerelease: false
145
- version_requirements: *70278898748160
156
+ version_requirements: *70359227533920
146
157
  description: Some basics that your application could benefit from.
147
158
  email: eno@open-lab.org
148
159
  executables: []
@@ -178,6 +189,7 @@ files:
178
189
  - lib/radiospieler/radiospieler/config.rb
179
190
  - lib/radiospieler/radiospieler/logger.rb
180
191
  - lib/radiospieler/radiospieler/root.rb
192
+ - radiospieler.gemspec
181
193
  - script/watchr
182
194
  - test/app_test.rb
183
195
  - test/array_ext_test.rb
@@ -190,9 +202,9 @@ files:
190
202
  - test/fixtures-vcr/bitly_ok.yml
191
203
  - test/fixtures-vcr/http_test.yml
192
204
  - test/hash_ext_test.rb
193
- - test/helper.rb
194
205
  - test/http_test.rb
195
206
  - test/string_ext_test.rb
207
+ - test/test_helper.rb
196
208
  - test/tls_test.rb
197
209
  - test/uid_test.rb
198
210
  homepage: http://github.com/radiospiel/radiospieler
@@ -210,7 +222,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
210
222
  version: '0'
211
223
  segments:
212
224
  - 0
213
- hash: -1058781715600460096
225
+ hash: -3145811610061597683
214
226
  required_rubygems_version: !ruby/object:Gem::Requirement
215
227
  none: false
216
228
  requirements: