class ExtractSpecificObject
Public Class Methods
call(id:, table:)
click to toggle source
# File lib/extract_specific_object.rb, line 9 def call(id:, table:) initialize_configuration return table_not_exist(table) unless ActiveRecord::Base.connection.tables.include?(table) result = ActiveRecord::Base.connection.execute("SELECT * FROM #{table} WHERE id='#{id}'").to_a return not_found(table, id) if result.blank? remove_timestamps(result) associated_object = [{ table: table, attributes: result }] ExtractAssociatedObject.new(result, associated_object).call end
Private Class Methods
not_found(table, id)
click to toggle source
# File lib/extract_specific_object.rb, line 28 def not_found(table, id) print "Can't find id=#{id} in table=#{table}" end
remove_timestamps(result)
click to toggle source
# File lib/extract_specific_object.rb, line 23 def remove_timestamps(result) result[0].delete('updated_at') result[0].delete('created_at') end
table_not_exist(table)
click to toggle source
# File lib/extract_specific_object.rb, line 32 def table_not_exist(table) print "Table #{table} does not exist in your DB" end