Class: ImportManager::Status
- Inherits:
-
Hash
- Object
- Hash
- ImportManager::Status
- Defined in:
- lib/import_manager/status.rb,
lib/import_manager/status/counts.rb
Defined Under Namespace
Classes: Counts
Instance Method Summary collapse
- #init_missing_values ⇒ Object
-
#initialize(status) ⇒ Status
constructor
A new instance of Status.
- #normalize_init_args(status) ⇒ Object
- #unstringify_keys(hash) ⇒ Object
Constructor Details
Instance Method Details
#init_missing_values ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/import_manager/status.rb', line 15 def init_missing_values self[:errors] ||= Hash.new { |h, k| h[k] = [] } self[:reports] ||= Hash.new { |h, k| h[k] = [] } %i[imported skipped overridden failed].each do |n| self[n] ||= {} end end |
#normalize_init_args(status) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/import_manager/status.rb', line 23 def normalize_init_args status sym_hash = case status when Integer { counts: { total: status } } when String JSON.parse status when Hash status else {} end unstringify_keys sym_hash rescue JSON::ParserError => _e {} end |
#unstringify_keys(hash) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/import_manager/status.rb', line 39 def unstringify_keys hash hash.deep_symbolize_keys! hash.keys.each do |k| next if k == :counts || !hash[k].is_a?(Hash) hash[k] = hash[k].each_with_object({}) do |(key, value), | [(Integer(key.to_s) rescue key)] = value end end hash end |