Kouhei Sutou
null+****@clear*****
Mon Dec 5 18:23:17 JST 2016
Kouhei Sutou 2016-12-05 18:23:17 +0900 (Mon, 05 Dec 2016) New Revision: 6cf5a0e9fe24b103fb343ebf797d020d59f795fd https://github.com/ranguba/groonga-client-model/commit/6cf5a0e9fe24b103fb343ebf797d020d59f795fd Message: Support destroy Modified files: lib/groonga_client_model/record.rb Modified: lib/groonga_client_model/record.rb (+25 -1) =================================================================== --- lib/groonga_client_model/record.rb 2016-12-05 18:15:47 +0900 (7b6db65) +++ lib/groonga_client_model/record.rb 2016-12-05 18:23:17 +0900 (6f56019) @@ -110,6 +110,7 @@ module GroongaClientModel assign_attributes(attributes) if attributes @new_record = true + @destroyed = false end def save(validate: false) @@ -131,6 +132,23 @@ module GroongaClientModel end end + def destroy + if persisted? + Client.open do |client| + table = self.class.schema.tables[self.class.table_name] + response = client.delete(table: table.name, + filter: "_id == #{_id}") + unless response.success? + message = "Failed to delete the record: " + message << "#{response.error_code}: #{response.error_message}" + raise Error.new(message, self) + end + end + end + @destroyed = true + freeze + end + def update(attributes) assign_attributes(attributes) save @@ -160,8 +178,14 @@ module GroongaClientModel @new_record end + def destroyed? + @destroyed + end + def persisted? - not @new_record + return false if @new_record + return false if @destroyed + true end private -------------- next part -------------- HTML����������������������������...Download