Class: App::AccountSqlStorageConverter

Inherits:
Object
  • Object
show all
Defined in:
app/converters/account_sql_storage_converter.rb

Constant Summary collapse

STATUS_MAP =
Hash.new { |h, k|
  raise ArgumentError, "Status #{k.inspect} not known"
}.update(
  active: 1,
  inactive: 2,
  deleted: 3
).freeze
REVERSE_STATUS_MAP =
Hash.new { |h, k|
  raise ArgumentError, "Status #{k.inspect} not known"
}.update(
  Hash[STATUS_MAP.to_a.map(&:reverse)]
).freeze

Instance Method Summary collapse

Instance Method Details

#attributes_list_to_storage(list) ⇒ Object



17
18
19
# File 'app/converters/account_sql_storage_converter.rb', line 17

def attributes_list_to_storage(list)
  list
end

#from_storage(attrs) ⇒ Object



21
22
23
24
25
# File 'app/converters/account_sql_storage_converter.rb', line 21

def from_storage(attrs)
  attrs.dup.tap { |copy|
    copy[:status] = REVERSE_STATUS_MAP[copy[:status]] if copy[:status]
  }
end

#to_storage(attrs) ⇒ Object



27
28
29
30
31
# File 'app/converters/account_sql_storage_converter.rb', line 27

def to_storage(attrs)
  attrs.dup.tap { |copy|
    copy[:status] = STATUS_MAP[copy[:status]] if copy[:status]
  }
end