Sha256: 35194a0176c87cbe874ac9e2c5637a1bf22cfb19ab4230c969a651d0ed06324c

Contents?: true

Size: 669 Bytes

Versions: 5

Compression:

Stored size: 669 Bytes

Contents

# frozen_string_literal: true

module Consent
  # Rails file reloader to detect permission changes and apply them to consent
  class Reloader
    attr_reader :paths
    delegate :updated?, :execute, :execute_if_updated, to: :updater

    def initialize(default_path, mechanism)
      @paths = [default_path]
      @mechanism = mechanism
    end

    private

    def reload!
      Consent.subjects.clear
      Consent.load_subjects! paths, @mechanism
    end

    def updater
      @updater ||= ActiveSupport::FileUpdateChecker.new([], globs) { reload! }
    end

    def globs
      pairs = paths.map { |path| [path.to_s, %w[rb]] }
      Hash[pairs]
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
consent-1.0.1 lib/consent/reloader.rb
consent-1.0.0 lib/consent/reloader.rb
consent-0.6.0 lib/consent/reloader.rb
consent-0.5.2 lib/consent/reloader.rb
consent-0.5.0 lib/consent/reloader.rb