Class: SafeDb::Export

Inherits:
UseCase show all
Defined in:
lib/usecase/export.rb

Overview

Export the entire book if no chapter and verse is specified (achieved with a safe close), or the chapter if only the chapter is open (safe shut or safe open <<chapter>>, or the mini-dictionary at the verse if both chapter and verse are open.

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

Attributes inherited from UseCase

#from_script

Instance Method Summary collapse

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 Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/usecase/export.rb', line 14

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 ]
  has_chapter = KeyApi.db_envelope_exists?( master_db[ chapter_id ] )

  unless has_chapter
    puts "{}"
    return
  end

  chapter_data = get_chapter_data( master_db[ chapter_id ] )
  puts JSON.pretty_generate( chapter_data )

  return

end

#get_chapter_data(chapter_key) ⇒ Object



10
11
12
# File 'lib/usecase/export.rb', line 10

def get_chapter_data( chapter_key )
  return KeyDb.from_json( KeyApi.content_unlock( chapter_key ) )
end