Sha256: 64544ae53aeac62540461fac8f26a597c8b1afc50f9a5cceaa88c7f3311038d9

Contents?: true

Size: 842 Bytes

Versions: 60

Compression:

Stored size: 842 Bytes

Contents

# frozen_string_literal: true

module Motor
  module Configs
    module SyncFromFile
      FILE_PATH = Motor::Configs::FILE_PATH
      MUTEXT = Mutex.new
      FILE_TIMESTAMPS_STORE = ActiveSupport::Cache::MemoryStore.new(size: 1.megabyte)

      module_function

      def call(with_exception: false)
        MUTEXT.synchronize do
          file = Rails.root.join(FILE_PATH)

          file_timestamp =
            begin
              file.ctime
            rescue Errno::ENOENT
              raise if with_exception

              nil
            end

          next unless file_timestamp

          FILE_TIMESTAMPS_STORE.fetch(file_timestamp.to_s) do
            Motor::Configs::SyncFromHash.call(
              YAML.safe_load(file.read, permitted_classes: [Time, Date])
            )
          end
        end
      end
    end
  end
end

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
motor-admin-0.1.82 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.81 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.80 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.79 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.78 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.77 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.76 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.75 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.74 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.73 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.72 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.71 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.70 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.68 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.67 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.66 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.65 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.64 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.63 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.62 lib/motor/configs/sync_from_file.rb