Class: SsmConfig::SsmStorage::Db
- Inherits:
-
Object
- Object
- SsmConfig::SsmStorage::Db
- 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
- #hash ⇒ Object
-
#initialize(file_name) ⇒ Db
constructor
A new instance of Db.
- #table_exists? ⇒ Boolean
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
#hash ⇒ Object
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
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 |