Class: Dam::Storage
- Inherits:
-
Object
- Object
- Dam::Storage
- Defined in:
- lib/dam/storage.rb
Class Method Summary collapse
- .database ⇒ Object
- .database=(database) ⇒ Object
- .get(stream_name) ⇒ Object
- .head(stream_name) ⇒ Object
- .insert(activity, streams) ⇒ Object
- .keys(spec = '*') ⇒ Object
- .register(name, engine) ⇒ Object
- .save(activity) ⇒ Object
Class Method Details
.database ⇒ Object
10 11 12 |
# File 'lib/dam/storage.rb', line 10 def self.database return @database if instance_variable_defined? '@database' end |
.database=(database) ⇒ Object
14 15 16 |
# File 'lib/dam/storage.rb', line 14 def self.database=(database) @database = database end |
.get(stream_name) ⇒ Object
27 28 29 |
# File 'lib/dam/storage.rb', line 27 def self.get(stream_name) self.database.mget(self.database.list_range("stream:#{stream_name}", 0, -1)) end |
.head(stream_name) ⇒ Object
31 32 33 |
# File 'lib/dam/storage.rb', line 31 def self.head(stream_name) self.database[self.database.list_index("stream:#{stream_name}", 0)] end |
.insert(activity, streams) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/dam/storage.rb', line 18 def self.insert(activity, streams) id = self.save(activity) streams.each do |stream| self.database.push_head("stream:#{stream.name}", "activity:#{id}") self.database.ltrim("stream:#{stream.name}", 0, (stream.limit || 10) - 1) end end |
.keys(spec = '*') ⇒ Object
35 36 37 |
# File 'lib/dam/storage.rb', line 35 def self.keys(spec='*') self.database.keys("stream:#{spec}").collect {|key| key.sub(/^stream:/, '')} end |
.register(name, engine) ⇒ Object
5 6 7 8 |
# File 'lib/dam/storage.rb', line 5 def Storage.register(name, engine) @engines ||= {} @engines[name] = engine end |
.save(activity) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/dam/storage.rb', line 39 def self.save activity id = self.generate_unique_id! self.database["activity:#{id}"] = activity.to_json id end |