shitcan 0.1 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/shitcan.rb +5 -0
- data/lib/shitcan/base.rb +44 -0
- data/lib/shitcan/config.rb +25 -0
- metadata +7 -5
- data/lib/shit_can.rb +0 -40
data/lib/shitcan.rb
ADDED
data/lib/shitcan/base.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Shitcan
|
2
|
+
def self.config=(val)
|
3
|
+
@config = val
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.config
|
7
|
+
return @config if @config
|
8
|
+
@config = Shitcan::Config.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.cache
|
12
|
+
if config.cache
|
13
|
+
return config.cache
|
14
|
+
else
|
15
|
+
raise ShitCan, 'SHITCAN | NO CONNECTION TO MEMCACHED COULD BE ESTABLISHED!'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.set(*args)
|
20
|
+
cache.set(*args)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.get(*args)
|
24
|
+
cache.get(*args)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.get_if_exists(key)
|
28
|
+
get(key) if exists?(key) # Fix this!
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.skip_if_exists(key)
|
32
|
+
yield unless exists?(key)
|
33
|
+
end
|
34
|
+
|
35
|
+
# TODO: Is there a faster way to handle exceptions
|
36
|
+
def self.exists?(key)
|
37
|
+
begin
|
38
|
+
get(key)
|
39
|
+
return true
|
40
|
+
rescue
|
41
|
+
return false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Shitcan
|
2
|
+
class Config
|
3
|
+
attr_accessor :app_root, :env
|
4
|
+
|
5
|
+
def initialize(opts={})
|
6
|
+
@app_root = opts[:app_root] || RAILS_ROOT
|
7
|
+
@env = opts[:rails_env] || RAILS_ENV || 'development'
|
8
|
+
end
|
9
|
+
|
10
|
+
def memcache_conf
|
11
|
+
path = "#{app_root}/config/memcache.yml"
|
12
|
+
@memcache_conf ||= File.exists?(path) ? YAML::load(ERB.new(IO.read(path)).result)[env] : 'localhost:11211'
|
13
|
+
end
|
14
|
+
|
15
|
+
# TODO: Think up some custom configuration options
|
16
|
+
def shitcan_conf
|
17
|
+
path = "#{app_root}/config/shitcan.yml"
|
18
|
+
@shitcan_conf ||= YAML::load(ERB.new(IO.read(path)).result)[env]
|
19
|
+
end
|
20
|
+
|
21
|
+
def cache
|
22
|
+
@cache ||= Memcached.new(memcache_conf)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shitcan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 2
|
9
|
+
version: "0.2"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Tyler Love
|
@@ -14,7 +14,7 @@ autorequire: builder
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-10-05 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -41,7 +41,9 @@ extra_rdoc_files:
|
|
41
41
|
- Rakefile
|
42
42
|
- README.textile
|
43
43
|
files:
|
44
|
-
- lib/
|
44
|
+
- lib/shitcan/base.rb
|
45
|
+
- lib/shitcan/config.rb
|
46
|
+
- lib/shitcan.rb
|
45
47
|
- test/test_helper.rb
|
46
48
|
- test/test_suite.rb
|
47
49
|
- Rakefile
|
data/lib/shit_can.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
module ShitCan
|
2
|
-
require 'memcached'
|
3
|
-
|
4
|
-
def self.load(con_path='localhost:11211')
|
5
|
-
@cache = Memcached.new(con_path)
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.cache
|
9
|
-
if @cache
|
10
|
-
return @cache
|
11
|
-
else
|
12
|
-
raise ShitCan, 'NO CAN HERE!'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.set *args
|
17
|
-
cache.set *args
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.get *args
|
21
|
-
cache.get *args
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.get_if_exists *args
|
25
|
-
get *args if exists?
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.skip_if_exists key
|
29
|
-
yield unless exists? key
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.exists? key
|
33
|
-
begin
|
34
|
-
get key
|
35
|
-
return true
|
36
|
-
rescue
|
37
|
-
return false
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|