Class: Rod::Berkeley::CollectionProxy
- Inherits:
-
Object
- Object
- Rod::Berkeley::CollectionProxy
- Includes:
- Enumerable
- Defined in:
- lib/rod/berkeley/collection_proxy.rb
Instance Method Summary collapse
- #&(other) ⇒ Object
- #<<(element) ⇒ Object
- #[](object_index) ⇒ Object
- #clear ⇒ Object
- #delete(element) ⇒ Object
- #delete_at(index) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(database, key) ⇒ CollectionProxy
constructor
Initializes the proxy with given Berkeley
database
. - #insert(index, element) ⇒ Object
- #save ⇒ Object
- #to_s ⇒ Object
- #|(other) ⇒ Object
Constructor Details
#initialize(database, key) ⇒ CollectionProxy
Initializes the proxy with given Berkeley database
.
7 8 9 10 |
# File 'lib/rod/berkeley/collection_proxy.rb', line 7 def initialize(database,key) @database = database @key = key end |
Instance Method Details
#&(other) ⇒ Object
32 33 34 |
# File 'lib/rod/berkeley/collection_proxy.rb', line 32 def &(other) raise "#{self.class}##{__method__} not implemented yet." end |
#<<(element) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/rod/berkeley/collection_proxy.rb', line 36 def <<(element) # TODO #207 this doesn't work for not persited objects rod_id = element.rod_id raise "Not implemented #207" if rod_id.nil? || rod_id == 0 @database.put(@key,rod_id) end |
#[](object_index) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rod/berkeley/collection_proxy.rb', line 12 def [](object_index) if object_index == 0 begin return object_for(@database.get_first(@key)) rescue KeyMissing => ex return nil end else # TODO This should be optimized! self.each.with_index do |object,index| return object if index == object_index end end nil end |
#clear ⇒ Object
60 61 62 |
# File 'lib/rod/berkeley/collection_proxy.rb', line 60 def clear raise "#{self.class}##{__method__} not implemented yet." end |
#delete(element) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/rod/berkeley/collection_proxy.rb', line 47 def delete(element) begin @database.delete(@key,element) element rescue KeyMissing => ex nil end end |
#delete_at(index) ⇒ Object
56 57 58 |
# File 'lib/rod/berkeley/collection_proxy.rb', line 56 def delete_at(index) raise "#{self.class}##{__method__} not implemented yet." end |
#each ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rod/berkeley/collection_proxy.rb', line 64 def each if block_given? begin @database.each_for(@key) do |rod_id| yield object_for(rod_id) end rescue KeyMissing nil end else enum_for(:each) end end |
#empty? ⇒ Boolean
82 83 84 |
# File 'lib/rod/berkeley/collection_proxy.rb', line 82 def empty? raise "#{self.class}##{__method__} not implemented yet." end |
#insert(index, element) ⇒ Object
43 44 45 |
# File 'lib/rod/berkeley/collection_proxy.rb', line 43 def insert(index,element) raise "#{self.class}##{__method__} not implemented yet." end |
#save ⇒ Object
86 87 88 |
# File 'lib/rod/berkeley/collection_proxy.rb', line 86 def save raise "#{self.class}##{__method__} not implemented yet." end |
#to_s ⇒ Object
78 79 80 |
# File 'lib/rod/berkeley/collection_proxy.rb', line 78 def to_s raise "#{self.class}##{__method__} not implemented yet." end |
#|(other) ⇒ Object
28 29 30 |
# File 'lib/rod/berkeley/collection_proxy.rb', line 28 def |(other) raise "#{self.class}##{__method__} not implemented yet." end |