Class: SafeDb::Print

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

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

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

#key_name=(value) ⇒ Object (writeonly)

Sets the attribute key_name

Parameters:

  • value

    the value to set the attribute key_name to.



7
8
9
# File 'lib/usecase/print.rb', line 7

def key_name=(value)
  @key_name = value
end

Instance Method Details

#executeObject

Raises:

  • (ArgumentError)


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

def execute

  return unless ops_key_exists?

  master_db = get_master_database()

  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 ] )

  chapter_data = get_chapter_data( master_db[ chapter_id ] ) if has_chapter
  has_verse = has_chapter && chapter_data.has_key?( master_db[ KEY_PATH ] )

  chapter_err_msg = "Nothing was found at chapter " + master_db[ ENV_PATH ]
  raise ArgumentError, chapter_err_msg unless has_chapter
  verse_err_msg = "Nothing was found at chapter " + master_db[ ENV_PATH ] + " verse " + master_db[ KEY_PATH ]
  raise ArgumentError, verse_err_msg unless has_verse

  print chapter_data[ master_db[ KEY_PATH ] ][ @key_name ]

end

#get_chapter_data(chapter_key) ⇒ Object



9
10
11
# File 'lib/usecase/print.rb', line 9

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