Module: ScoutTKRZW
- Defined in:
- lib/scout/persist/engine/tkrzw.rb
Instance Attribute Summary collapse
-
#open_options ⇒ Object
Returns the value of attribute open_options.
-
#persistence_class ⇒ Object
Returns the value of attribute persistence_class.
-
#persistence_path ⇒ Object
Returns the value of attribute persistence_path.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#open_options ⇒ Object
Returns the value of attribute open_options.
4 5 6 |
# File 'lib/scout/persist/engine/tkrzw.rb', line 4 def @open_options end |
#persistence_class ⇒ Object
Returns the value of attribute persistence_class.
4 5 6 |
# File 'lib/scout/persist/engine/tkrzw.rb', line 4 def persistence_class @persistence_class end |
#persistence_path ⇒ Object
Returns the value of attribute persistence_path.
4 5 6 |
# File 'lib/scout/persist/engine/tkrzw.rb', line 4 def persistence_path @persistence_path end |
Class Method Details
.open(path, write = true, persistence_class = 'tkh', options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/scout/persist/engine/tkrzw.rb', line 6 def self.open(path, write = true, persistence_class = 'tkh', = {}) = IndiferentHash.add_defaults , truncate: true, num_buckets: 100, dbm: "HashDBM", sync_hard: true, encoding: "UTF-8" path = path.find if Path === path dir = File.dirname(File.(path)) Open.mkdir(dir) unless File.exist?(dir) database = Persist::CONNECTIONS[[persistence_class, path]*":"] ||= Tkrzw::DBM.new database.close if database.open? database.open(path, write, ) database.extend ScoutTKRZW database.persistence_path ||= path database. = #Persist::CONNECTIONS[[persistence_class, path]*":"] = database database end |
Instance Method Details
#close ⇒ Object
29 30 31 32 33 |
# File 'lib/scout/persist/engine/tkrzw.rb', line 29 def close @closed = true @writable = false super end |
#keys ⇒ Object
64 65 66 |
# File 'lib/scout/persist/engine/tkrzw.rb', line 64 def keys search("contain", "") end |
#read(force = false) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/scout/persist/engine/tkrzw.rb', line 35 def read(force = false) return if open? && ! writable? && ! force self.close if open? if !self.open(@persistence_path, false, @open_options) ecode = self.ecode raise "Open error: #{self.errmsg(ecode)}. Trying to open file #{@persistence_path}" end @writable = false @closed = false self end |
#write(force = true) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/scout/persist/engine/tkrzw.rb', line 49 def write(force = true) return if open? && writable? && ! force self.close if self.open? if !self.open(@persistence_path, true, @open_options) ecode = self.ecode raise "Open error: #{self.errmsg(ecode)}. Trying to open file #{@persistence_path}" end @writable = true @closed = false self end |