redis-roc 0.5.0

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/roc/store.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'roc/store/redis_store'
2
+ require 'roc/store/transient_store'
@@ -0,0 +1,41 @@
1
+ require 'roc/types/method_generators'
2
+
3
+ module ROC
4
+ module Types
5
+ module AllTypes
6
+ extend(ROC::Types::MethodGenerators)
7
+
8
+ zero_arg_method :exists
9
+
10
+ alias exists? exists
11
+
12
+ zero_arg_method :del
13
+
14
+ alias forget del
15
+
16
+ nonserializing_method :expire
17
+
18
+ nonserializing_method :expireat
19
+
20
+ zero_arg_method :ttl
21
+
22
+ zero_arg_method :persist
23
+
24
+ def eval(script, *args)
25
+ keys = [self.key]
26
+ argv = []
27
+ args.each do |a|
28
+ if a.is_a?(ROC::Base)
29
+ keys << a.key
30
+ else
31
+ argv << a
32
+ end
33
+ end
34
+ self.storage.call :eval, script, keys.size, *keys, *argv
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+
41
+
@@ -0,0 +1,106 @@
1
+ require 'roc/types/method_generators'
2
+
3
+ module ROC
4
+ module Types
5
+ module ArrayType
6
+
7
+ def self.included(base)
8
+ base.send :delegate_methods, :on => [], :to => :values
9
+ end
10
+
11
+ ## methods that must be implemented
12
+
13
+ def size
14
+ raise NotImplementedError, 'size must be overriden in any class including ArrayType'
15
+ end
16
+
17
+ def clobber(data)
18
+ raise NotImplementedError, 'clobber must be overriden in any class including ArrayType'
19
+ end
20
+
21
+ # note - overriden methods should always return an array, never nil
22
+ def values
23
+ raise NotImplementedError, 'values must be overriden in any class including ArrayType'
24
+ end
25
+
26
+ ## common stuff
27
+
28
+ # can't alias - it will to find the method in subclass
29
+ def to_array
30
+ self.values
31
+ end
32
+ def to_ary
33
+ self.values
34
+ end
35
+ def to_a
36
+ self.values
37
+ end
38
+
39
+ def values=(data)
40
+ self.clobber(data)
41
+ end
42
+
43
+ def inspect
44
+ "<#{self.class} @storage=#{self.storage.inspect} @key=#{self.key.inspect} @size=#{self.size}>"
45
+ end
46
+
47
+ ## destructive methods that we can implement here
48
+
49
+ def replace(val)
50
+ self.clobber(val)
51
+ self
52
+ end
53
+
54
+ def clear
55
+ self.replace([])
56
+ end
57
+
58
+ ## destructive methods that would otherwise be delegated -- override if possible (these are in addition to a ny methods ending in ! or =, which are caught by method_missing)
59
+
60
+ def delete(val)
61
+ raise NotImplementedError
62
+ end
63
+
64
+ def delete_at(ind)
65
+ raise NotImplementedError
66
+ end
67
+
68
+ def delete_if
69
+ raise NotImplementedError
70
+ end
71
+
72
+ def <<(val)
73
+ raise NotImplementedError
74
+ end
75
+
76
+ def fill(*args)
77
+ raise NotImplementedError
78
+ end
79
+
80
+ def insert(*args)
81
+ raise NotImplementedError
82
+ end
83
+
84
+ def keep_if
85
+ raise NotImplementedError
86
+ end
87
+
88
+ def push(*args)
89
+ raise NotImplementedError
90
+ end
91
+
92
+ def pop(*args)
93
+ raise NotImplementedError
94
+ end
95
+
96
+ def shift(*args)
97
+ raise NotImplementedError
98
+ end
99
+
100
+ def unshift(*args)
101
+ raise NotImplementedError
102
+ end
103
+
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,38 @@
1
+ module ROC
2
+ module Types
3
+ module MethodGenerators
4
+
5
+ def serializing_method(method_name)
6
+ self.send :define_method, method_name do |val|
7
+ self.call method_name, self.serialize(val)
8
+ end
9
+ end
10
+
11
+ def deserializing_method(method_name)
12
+ self.send :define_method, method_name do
13
+ self.deserialize(self.call method_name)
14
+ end
15
+ end
16
+
17
+ def serializing_and_deserializing_method(method_name)
18
+ self.send :define_method, method_name do |val|
19
+ self.deserialize(self.call method_name, self.serialize(val))
20
+ end
21
+ end
22
+
23
+ def zero_arg_method(method_name)
24
+ self.send :define_method, method_name do
25
+ self.call method_name
26
+ end
27
+ end
28
+
29
+ def nonserializing_method(method_name)
30
+ self.send :define_method, method_name do |val|
31
+ self.call method_name, val
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+
@@ -0,0 +1,58 @@
1
+ require 'roc/types/method_generators'
2
+
3
+ module ROC
4
+ module Types
5
+ module ScalarType
6
+ extend ROC::Types::MethodGenerators
7
+
8
+ deserializing_method :get
9
+
10
+ alias value get
11
+
12
+ serializing_method :set
13
+
14
+ alias value= set
15
+
16
+ serializing_method :setnx
17
+
18
+ serializing_and_deserializing_method :getset
19
+
20
+ def setex(secs, val)
21
+ self.set(val)
22
+ self.expire(secs)
23
+ end
24
+
25
+ def clobber(data)
26
+ self.set(data)
27
+ end
28
+
29
+ def inspect
30
+ "<#{self.class} @storage=#{self.storage.inspect} @key=#{self.key.inspect} @value=#{self.value.inspect}>"
31
+ end
32
+
33
+ def serialize(val)
34
+ raise "serialize must be overriden in any class including ScalarType"
35
+ end
36
+
37
+ def deserialize(val)
38
+ raise "deserialize must be overriden in any class including ScalarType"
39
+ end
40
+
41
+ # def respond_to?(method_name)
42
+ # ## todo - what about :value, deserialize, etc!!
43
+ # self.value.respond_to?(method_name)
44
+ # end
45
+
46
+ # def method_missing(method_name, *args, &block)
47
+ # v = self.value
48
+ # if v.respond_to?(method_name)
49
+ # v.send(method_name, *args, &block)
50
+ # else
51
+ # super(method_name, *args, &block)
52
+ # end
53
+ # end
54
+
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,32 @@
1
+ module ROC
2
+ module Types
3
+ module SortableType
4
+
5
+ # c.value :by
6
+ # c.splat :limit
7
+ # c.multi :get
8
+ # c.words :order
9
+ # c.value :store
10
+
11
+ def sort(opts={})
12
+ raise ":by not yet supported" if opts.has_key?(:by)
13
+ raise ":get not yet supported" if opts.has_key?(:by)
14
+
15
+ store = opts[:store]
16
+ if store.is_a?(ROC::List)
17
+ store = store.key
18
+ elsif !store.nil? && !store.is_a?(::String)
19
+ raise "unsupported :store value"
20
+ end
21
+
22
+ self.call :sort, {:store => store, :limit => opts[:limit], :order => opts[:order]}
23
+ end
24
+
25
+ def sort!(opts={})
26
+ raise ":store is self in sort!" if opts.has_key?(:store)
27
+ self.sort({:store => self.key}.merge(opts.dup))
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module ROC
2
+ VERSION = '0.5.0'
3
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redis-roc
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 5
8
+ - 0
9
+ version: 0.5.0
10
+ platform: ruby
11
+ authors:
12
+ - Ben Lund
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-08-08 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: redis
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: cim_attributes
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ description: Collection of Ruby classes wrapping the Redis data structures
47
+ email: ben@benlund.com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files: []
53
+
54
+ files:
55
+ - lib/redis-roc.rb
56
+ - lib/roc/objects.rb
57
+ - lib/roc/store.rb
58
+ - lib/roc/version.rb
59
+ - lib/roc/ext/redis_ext.rb
60
+ - lib/roc/objects/base.rb
61
+ - lib/roc/objects/float.rb
62
+ - lib/roc/objects/hash.rb
63
+ - lib/roc/objects/integer.rb
64
+ - lib/roc/objects/list.rb
65
+ - lib/roc/objects/lock.rb
66
+ - lib/roc/objects/set.rb
67
+ - lib/roc/objects/sorted_set.rb
68
+ - lib/roc/objects/string.rb
69
+ - lib/roc/objects/time.rb
70
+ - lib/roc/store/object_initializers.rb
71
+ - lib/roc/store/redis_eval.rb
72
+ - lib/roc/store/redis_store.rb
73
+ - lib/roc/store/roc_store.rb
74
+ - lib/roc/store/transient_eval.rb
75
+ - lib/roc/store/transient_store.rb
76
+ - lib/roc/types/all_types.rb
77
+ - lib/roc/types/array_type.rb
78
+ - lib/roc/types/method_generators.rb
79
+ - lib/roc/types/scalar_type.rb
80
+ - lib/roc/types/sortable_type.rb
81
+ has_rdoc: true
82
+ homepage: http://github.com/benlund/roc
83
+ licenses: []
84
+
85
+ post_install_message:
86
+ rdoc_options: []
87
+
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ requirements: []
107
+
108
+ rubyforge_project:
109
+ rubygems_version: 1.3.7
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: ROC::String, ROC::Integer, ROC::List, ROC::SortedSet, etc. Also a Ruby in-memory implementation of the Redis commmands to allow you to use the ROC classes without a connection to Redis.
113
+ test_files: []
114
+