module Eco::API::UseCases::GraphQL::Samples::Location::Service module TreeDiff module Convertible module Inputable class << self def included(base) super(base) base.send :include, Eco::Data::Files end end include Eco::API::UseCases::GraphQL::Helpers::Base::CaseEnv IN_FILENAME = /requested_tree\.csv/.freeze IN_FOLDER = 'sftp'.freeze private def input_encoding options.dig(:input, :file, :encoding) || 'utf-8' end def input_file @input_file ||= (options.dig(:input, :file, :name) || newest_file).tap do |file| if file log(:info) { "Using input file '#{file}'" } else log(:warn) { "Could not find any input file" } exit(1) end end end def newest_file @newest_file ||= csv_files.last end #@note via Eco::Data::Files def csv_files self.class.csv_files(input_folder, regexp: input_file_pattern) end def input_file_pattern self.class::IN_FILENAME end def input_folder "#{config.active_enviro}/#{self.class::IN_FOLDER}" end end end end end