Class: SafeDb::Show

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

Overview

Show the mini dictionary of key-value pairs within the logged in book at the opened chapter and verse.

If no dictionary exists at the opened chapter and verse a suitable message is pushed out to the console.

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



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/usecase/show.rb', line 16

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 ] )
  chapter_data = get_chapter_data( master_db[ chapter_id ] ) if has_chapter
  has_verse = has_chapter && chapter_data.has_key?( master_db[ KEY_PATH ] )


##global_variables - DONE
##local_variables - DONE
##instance_variables - DONE
##class_variables - tough nut to crack with very little benefit (method class_variables not defined)

=begin
  puts ""
  puts "QQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
  puts "QQQ ~~~~~~~~~~~~~ Global Variable Array List ~~~~~~~~~~~~~~~~ QQQQQ"
  puts "QQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"

  puts global_variables.inspect

  puts "QQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
  puts "QQQ ~~~~~~~~~~~~~ Global Variable Values Printed ~~~~~~~~~~~~~~~~ QQQQQ"
  puts "QQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"

  global_variables.sort.each do |name|

    puts "<<< ------------------------------------------------------------------->>>"
    puts "<<< #{name.to_s} >>>"
    puts "<<< ------------------------------------------------------------------->>>"
    next if name.to_s.eql?( "$FILENAME" )
    global_variable_value = eval "#{name}.inspect"
    puts "<<< #{global_variable_value}"

  end

  puts ""
  puts "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
  puts "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
  puts ""
  puts "QQQQQQQQQQQ QQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
  puts "QQQQQQQQQQQ Bug Finder QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
  puts "QQQQQQQQQQQ QQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
  puts ""
  self.instance_variables.map do |attribute|
    puts "=============================================="
    puts "----------------------------------------------"
    puts attribute
    pp self.instance_variable_get(attribute)
  end
  puts "=============================================="
  puts "QQQQQQQQQQQ QQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
  puts "QQQQQQQQQQQ QQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
  puts ""
  puts "### ------------------------------------"
  puts "### Inspect View"
  puts "### ------------------------------------"
  pp self.inspect
  puts "### ------------------------------------"
  puts "QQQQQQQQQQQ QQQQQQQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
  puts "QQQQQQQQQQQ Local Variables QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"
  puts "QQQQQQQQQQQ QQQQQQQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"

  local_variables.map do |attribute|
    puts "=============================================="
    puts "----------------------------------------------"
    puts attribute
    pp binding.local_variable_get(attribute.to_sym)
  end
  puts "QQQQQQQQQQQ QQQQQQQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"

  puts ""
=end



  return unless has_verse

  line_dictionary = chapter_data[ master_db[ KEY_PATH ] ]

  puts ""
  puts "### ##################################\n"
  puts "### chapter =>> #{master_db[ ENV_PATH ]}\n"
  puts "### & verse =>> #{master_db[ KEY_PATH ]}\n"
  puts "### # lines =>> #{line_dictionary.length}\n"
  puts "### ##################################\n"
  puts "--- ----------------------------------\n"
  puts ""

  showable_content = {}
  line_dictionary.each do | key_str, value_object |

    is_file = key_str.start_with? FILE_KEY_PREFIX
    value_object.store( FILE_CONTENT_KEY, SECRET_MASK_STRING ) if is_file
    showable_content.store( key_str[ FILE_KEY_PREFIX.length .. -1 ], value_object ) if is_file
    next if is_file

    is_secret = key_str.start_with? "@"
    showable_val = SECRET_MASK_STRING if is_secret
    showable_val = value_object unless is_secret
    showable_content.store( key_str, showable_val )

  end

  puts JSON.pretty_generate( showable_content )
  puts "--- ----------------------------------\n"
  puts "### ##################################\n"
  puts ""

end

#get_chapter_data(chapter_key) ⇒ Object



12
13
14
# File 'lib/usecase/show.rb', line 12

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