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.104 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.103 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.102 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.101 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.100 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.99 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.98 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.97 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.96 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.93 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.92 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.91 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.90 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.89 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.88 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.87 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.86 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.85 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.84 lib/motor/configs/sync_from_file.rb
motor-admin-0.1.83 lib/motor/configs/sync_from_file.rb