mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-01-19 05:56:03 +01:00
9413d23a02
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
25 lines
694 B
Ruby
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
|