thoughtless-moneta 0.6.0.1 → 0.6.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/moneta/sdbm.rb DELETED
@@ -1,33 +0,0 @@
1
- require "sdbm"
2
-
3
- module Moneta
4
- class BasicSDBM < ::SDBM
5
- include Defaults
6
-
7
- def [](key)
8
- if val = super
9
- Marshal.load(val)
10
- end
11
- end
12
-
13
- def []=(key, value)
14
- super(key, Marshal.dump(value))
15
- end
16
-
17
- def delete(key)
18
- if val = super
19
- Marshal.load(val)
20
- end
21
- end
22
- end
23
-
24
- class SDBM < BasicSDBM
25
- include Expires
26
-
27
- def initialize(options = {})
28
- raise "No :file option specified" unless file = options[:file]
29
- @expiration = BasicSDBM.new("#{file}_expires")
30
- super(file)
31
- end
32
- end
33
- end
data/lib/moneta/tyrant.rb DELETED
@@ -1,58 +0,0 @@
1
- begin
2
- require "rufus/tokyo/tyrant"
3
- rescue LoadError
4
- puts "You need the rufus gem to use the Tyrant moneta store"
5
- exit
6
- end
7
-
8
- module Moneta
9
- class Tyrant < ::Rufus::Tokyo::Tyrant
10
- include Defaults
11
-
12
- module Implementation
13
- def initialize(options = {})
14
- host = options[:host]
15
- port = options[:port]
16
- super(host, port)
17
- end
18
-
19
- def key?(key)
20
- !!self[key]
21
- end
22
-
23
- def [](key)
24
- if val = super
25
- Marshal.load(val.unpack("m")[0])
26
- end
27
- end
28
-
29
- def []=(key, value)
30
- super(key, [Marshal.dump(value)].pack("m"))
31
- end
32
- end
33
-
34
- include Implementation
35
- include Expires
36
-
37
- def initialize(options = {})
38
- super
39
- @expiration = Expiration.new(options)
40
- end
41
-
42
- class Expiration < ::Rufus::Tokyo::Tyrant
43
- include Implementation
44
-
45
- def [](key)
46
- super("#{key}__expiration")
47
- end
48
-
49
- def []=(key, value)
50
- super("#{key}__expiration", value)
51
- end
52
-
53
- def delete(key)
54
- super("#{key}__expiration")
55
- end
56
- end
57
- end
58
- end
data/lib/moneta/xattr.rb DELETED
@@ -1,58 +0,0 @@
1
- begin
2
- require "xattr"
3
- rescue LoadError
4
- puts "You need the xattr gem to use the Xattr moneta store"
5
- exit
6
- end
7
- require "fileutils"
8
-
9
- module Moneta
10
- class Xattr
11
- include Defaults
12
-
13
- def initialize(options = {})
14
- file = options[:file]
15
- @hash = ::Xattr.new(file)
16
- FileUtils.mkdir_p(::File.dirname(file))
17
- FileUtils.touch(file)
18
- unless options[:skip_expires]
19
- @expiration = Moneta::Xattr.new(:file => "#{file}_expiration", :skip_expires => true)
20
- self.extend(Expires)
21
- end
22
- end
23
-
24
- module Implementation
25
-
26
- def key?(key)
27
- @hash.list.include?(key)
28
- end
29
-
30
- alias has_key? key?
31
-
32
- def [](key)
33
- return nil unless key?(key)
34
- Marshal.load(@hash.get(key))
35
- end
36
-
37
- def []=(key, value)
38
- @hash.set(key, Marshal.dump(value))
39
- end
40
-
41
- def delete(key)
42
- return nil unless key?(key)
43
- value = self[key]
44
- @hash.remove(key)
45
- value
46
- end
47
-
48
- def clear
49
- @hash.list.each do |item|
50
- @hash.remove(item)
51
- end
52
- end
53
-
54
- end
55
- include Implementation
56
-
57
- end
58
- end
data/lib/moneta/yaml.rb DELETED
@@ -1,92 +0,0 @@
1
- require "yaml"
2
- require "fileutils"
3
-
4
- module Moneta
5
- class YAML
6
- class Expiration
7
- def initialize(file)
8
- @file = file
9
- end
10
-
11
- def [](key)
12
- yaml[key]['expires'] if yaml.has_key?(key)
13
- end
14
-
15
- def []=(key, value)
16
- hash = yaml
17
- if hash.has_key?(key)
18
- hash[key]['expires'] = value
19
- save(hash)
20
- end
21
- end
22
-
23
- def delete(key)
24
- hash = yaml
25
- if hash.has_key?(key)
26
- hash[key].delete("expires")
27
- save(hash)
28
- end
29
- end
30
-
31
- private
32
- def yaml
33
- ::YAML.load_file(@file)
34
- end
35
-
36
- def save(hash)
37
- ::File.open(@file, "w") { |file| file << hash.to_yaml }
38
- end
39
- end
40
-
41
- def initialize(options = {})
42
- @file = File.expand_path(options[:path])
43
- unless ::File.exists?(@file)
44
- File.open(@file, "w") { |file| file << {}.to_yaml }
45
- end
46
-
47
- @expiration = Expiration.new(@file)
48
- end
49
-
50
- module Implementation
51
- def key?(key)
52
- yaml.has_key?(key)
53
- end
54
-
55
- alias has_key? key?
56
-
57
- def [](key)
58
- yaml[key]['value'] if yaml.has_key?(key)
59
- end
60
-
61
- def []=(key, value)
62
- hash = yaml
63
- (hash[key] ||= {})['value'] = value
64
- save(hash)
65
- end
66
-
67
- def delete(key)
68
- hash = yaml
69
- value = self[key]
70
- hash.delete(key)
71
- save(hash)
72
- value
73
- end
74
-
75
- def clear
76
- save
77
- end
78
-
79
- private
80
- def yaml
81
- ::YAML.load_file(@file)
82
- end
83
-
84
- def save(hash = {})
85
- ::File.open(@file, "w") { |file| file << hash.to_yaml }
86
- end
87
- end
88
- include Implementation
89
- include Defaults
90
- include Expires
91
- end
92
- end