Class: SafeDb::DeleteMe
Overview
The delete use case delete’s one or more of the safe’s entities.
-
at
verselevel - it can delete one or more lines -
at
chapterlevel - it can delete one or more verses -
at
booklevel - it can delete one or more chapters -
at
safelevel - it can delete one book
Constant Summary
Constants inherited from UseCase
UseCase::APP_DIR_NAME, UseCase::COMMANDMENT, UseCase::ENV_VAR_KEY_NAME, UseCase::ENV_VAR_PREFIX_A, UseCase::ENV_VAR_PREFIX_B, UseCase::FILE_CONTENT_KEY, UseCase::FILE_KEY_PREFIX, UseCase::FILE_NAME_KEY
Instance Attribute Summary collapse
-
#entity_id ⇒ Object
writeonly
Sets the attribute entity_id.
Attributes inherited from UseCase
Instance Method Summary collapse
-
#execute ⇒ Object
Deletion that currently expects an open chapter and verse and always wants to delete only one line (key/value pair).
Methods inherited from UseCase
#check_post_conditions, #check_pre_conditions, #cleanup, #config_directory, #config_file, #flow_of_events, #get_master_database, #initialize, #post_validation, #pre_validation
Constructor Details
This class inherits a constructor from SafeDb::UseCase
Instance Attribute Details
#entity_id=(value) ⇒ Object (writeonly)
Sets the attribute entity_id
14 15 16 |
# File 'lib/usecase/edit/delete.rb', line 14 def entity_id=(value) @entity_id = value end |
Instance Method Details
#execute ⇒ Object
Deletion that currently expects an open chapter and verse and always wants to delete only one line (key/value pair).
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/usecase/edit/delete.rb', line 18 def execute return unless ops_key_exists? master_db = KeyApi.read_master_db() return if unopened_envelope?( master_db ) chapter_id = ENVELOPE_KEY_PREFIX + master_db[ ENV_PATH ] chapter_exists = KeyApi.db_envelope_exists?( master_db[ chapter_id ] ) chapter_data = KeyDb.from_json( KeyApi.content_unlock( master_db[ chapter_id ] ) ) if chapter_exists chapter_data = KeyDb.new() unless chapter_exists content_hdr = create_header() master_db[ chapter_id ] = {} unless chapter_exists verse_id = master_db[ KEY_PATH ] chapter_data.delete_entry( verse_id, @entity_id ) chapter_data.delete_entry( verse_id, "#{FILE_KEY_PREFIX}#{@entity_id}" ) KeyApi.content_lock( master_db[ chapter_id ], chapter_data.to_json, content_hdr ) KeyApi.write_master_db( content_hdr, master_db ) Show.new.flow_of_events end |