Class: Wakame::StatusDB::SequelAdapter
- Inherits:
-
Object
- Object
- Wakame::StatusDB::SequelAdapter
- Defined in:
- lib/wakame/status_db.rb
Instance Method Summary collapse
- #clear_store ⇒ Object
- #delete(id) ⇒ Object
- #exists?(id) ⇒ Boolean
- #find(id) ⇒ Object
-
#find_all(klass) ⇒ Object
Find all rows belong to given klass name.
-
#initialize ⇒ SequelAdapter
constructor
A new instance of SequelAdapter.
- #save(id, hash) ⇒ Object
Constructor Details
#initialize ⇒ SequelAdapter
Returns a new instance of SequelAdapter.
104 105 106 |
# File 'lib/wakame/status_db.rb', line 104 def initialize @model_class = Wakame::Models::ObjectStore end |
Instance Method Details
#clear_store ⇒ Object
148 149 |
# File 'lib/wakame/status_db.rb', line 148 def clear_store end |
#delete(id) ⇒ Object
143 144 145 146 |
# File 'lib/wakame/status_db.rb', line 143 def delete(id) Wakame.log.debug("StatusDB.delete(#{id}) called by #{Thread.current.to_s}") unless Thread.current == WorkerThread.worker_thread @model_class[id].destroy end |
#exists?(id) ⇒ Boolean
127 128 129 |
# File 'lib/wakame/status_db.rb', line 127 def exists?(id) !@model_class[id].nil? end |
#find(id) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/wakame/status_db.rb', line 108 def find(id) Wakame.log.debug("StatusDB.find(#{id}) called by #{Thread.current.to_s}") unless Thread.current == WorkerThread.worker_thread m = @model_class[id] if m hash = eval(m[:dump]) hash[AttributeHelper::CLASS_TYPE_KEY]=m.class_type hash else nil end end |
#find_all(klass) ⇒ Object
Find all rows belong to given klass name. Returns id list which matches class_type == klass
122 123 124 125 |
# File 'lib/wakame/status_db.rb', line 122 def find_all(klass) ds = @model_class.where(:class_type=>klass.to_s) ds.all.map {|r| r[:id] } end |
#save(id, hash) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/wakame/status_db.rb', line 131 def save(id, hash) Wakame.log.debug("StatusDB.save(#{id}) called by #{Thread.current.to_s}") unless Thread.current == WorkerThread.worker_thread m = @model_class[id] if m.nil? m = @model_class.new m.id = id m.class_type = hash[AttributeHelper::CLASS_TYPE_KEY] end m.dump = hash.inspect m.save end |