Module: SSD::Internals::Entity::ClassMethods
- Defined in:
- lib/ssd/class_methods.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](ssd) ⇒ Object
- #count(ssd) ⇒ Object
-
#delete(*ssds) ⇒ Object
(also: #remove)
alias get ssd alias find ssd.
- #key?(ssd) ⇒ Boolean (also: #exists?)
- #keys(ssd) ⇒ Object
- #last_key(ssd) ⇒ Object
- #setup(ssd) ⇒ Object
- #ssd(ssd, default = nil) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/ssd/class_methods.rb', line 5 def self.extended(base) @@ssd_name = base.new.class.to_s.downcase #FileUtils::mkdir_p 'DS' #@@ssd_path = "DS/#{name}.pstore" #@@ssd_db = PStore.new @@ssd_path, true #@@ssd_db.ultra_safe = true #@@ssd_db.transaction(true) {} #@@ssd_db end |
Instance Method Details
#[](ssd) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/ssd/class_methods.rb', line 49 def [] ssd setup ssd @@ssd_db.transaction true do @@ssd_db[ssd] end end |
#count(ssd) ⇒ Object
77 78 79 80 81 |
# File 'lib/ssd/class_methods.rb', line 77 def count ssd setup ssd $log.info("count") return keys(ssd).count end |
#delete(*ssds) ⇒ Object Also known as: remove
alias get ssd alias find ssd
67 68 69 70 71 72 73 74 |
# File 'lib/ssd/class_methods.rb', line 67 def delete *ssds @@ssd_db.transaction do ssds.each do |ssd| @@ssd_db.delete ssd.to_sym end @@ssd_db.commit end end |
#key?(ssd) ⇒ Boolean Also known as: exists?
40 41 42 43 44 45 |
# File 'lib/ssd/class_methods.rb', line 40 def key? ssd setup ssd @@ssd_db.transaction true do @@ssd_db.root? ssd end end |
#keys(ssd) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/ssd/class_methods.rb', line 33 def keys ssd setup ssd @@ssd_db.transaction true do @@ssd_db.roots end end |
#last_key(ssd) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/ssd/class_methods.rb', line 25 def last_key ssd setup ssd last_key = @@ssd_db.transaction true do @@ssd_db.roots end last_key.last end |
#setup(ssd) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/ssd/class_methods.rb', line 15 def setup ssd @@ssd = ssd FileUtils::mkdir_p ".ssd/#{@@ssd_name}" @@ssd_path = ".ssd/#{@@ssd_name}/#{@@ssd}.ssd" @@ssd_db = PStore.new @@ssd_path, true @@ssd_db.ultra_safe = true @@ssd_db.transaction(true) {} return @@ssd_db end |
#ssd(ssd, default = nil) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/ssd/class_methods.rb', line 56 def ssd ssd, default = nil #TODO add raise if ssd.nil? last_key = (last_key ssd) @@ssd_db.transaction true do @@ssd_db.fetch last_key, default end end |