Class: SsmConfig::SsmStorage::Db

Inherits:
Object
  • Object
show all
Defined in:
lib/ssm_config/ssm_storage/db.rb

Constant Summary collapse

TABLE_NAME =
'ssm_config_records'.freeze
ACTIVE_RECORD_MODEL =
'SsmConfigRecord'.freeze
VALID_DATATYPES =
['s', 'i', 'b', 'f', 'e'].freeze

Instance Method Summary collapse

Constructor Details

#initialize(file_name) ⇒ Db

Returns a new instance of Db.



7
8
9
# File 'lib/ssm_config/ssm_storage/db.rb', line 7

def initialize(file_name)
  @file_name = file_name
end

Instance Method Details

#hashObject



18
19
20
21
22
# File 'lib/ssm_config/ssm_storage/db.rb', line 18

def hash
  match_file = ACTIVE_RECORD_MODEL.constantize.where(:file => @file_name.to_s).order(:accessor_keys)
  hashes = match_file.each_with_object({}) { |row, hash| hash[row.accessor_keys] = transform_class(row.value, row.datatype); }
  insert_arrays(reconstruct_hash(hashes)).try(:with_indifferent_access)
end

#table_exists?Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
# File 'lib/ssm_config/ssm_storage/db.rb', line 11

def table_exists?
  return active_record_model_exists? if active_record_exists? && constant_exists?
  false
rescue ActiveRecord::NoDatabaseError, Mysql2::Error::ConnectionError
  return false
end