retrospring/lib/use_case/data_export/base.rb
Georg Gadinger 9413d23a02 let Zeitwerk autoload the lib/ directory
this also allows the UseCase classes to be hot reloaded in dev 🎉

- remove use_case requires (except for the exporter as Zeitwerk
  doesn't know about the subclasses)
- move version.rb to lib/retrospring so that Zeitwerk knows where
  to find Retrospring::Version
2022-12-29 20:57:28 +01:00

25 lines
694 B
Ruby

# frozen_string_literal: true
require "json"
module UseCase
module DataExport
class Base < UseCase::Base
# the user that is being exported
option :user
def call = files
# returns a hash with `{ "file_name" => "file_contents\n" }`
def files = raise NotImplementedError
# helper method that returns the column names of `model` as symbols
def column_names(model) = model.column_names.map(&:to_sym)
# helper method that generates the content of a json file
#
# it ensures the final newline exists, as the exporter only uses File#write
def json_file!(**hash) = "#{JSON.pretty_generate(hash.as_json)}\n"
end
end
end