Class: Clickwrap::Services::LoadPolicies

Inherits:
Object
  • Object
show all
Defined in:
lib/clickwrap/services/load_policies.rb

Overview

Loads the host's document, policy, and retention declarations.

They live in ordinary Ruby files — config/clickwrap.rb and config/clickwrap/*.rb by default — because that makes them reviewable in a pull request and deployable like the code they are. The engine re-reads them through to_prepare, so a development reload picks up an edit the same way it picks up a model change.

Compilation happens here, at boot, and a mistake raises. A policy that references a document nobody declared, a consent statement with no withdrawal route, a one-time authorization with no expiry — each of those is a bug that would otherwise be discovered by the first person who tried to sign up, and each one gets a sentence explaining what to do about it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths: nil, root: nil) ⇒ LoadPolicies

Returns a new instance of LoadPolicies.



19
20
21
22
# File 'lib/clickwrap/services/load_policies.rb', line 19

def initialize(paths: nil, root: nil)
  @paths = paths || Clickwrap.config.policy_paths
  @root = root || default_root
end

Instance Attribute Details

#pathsObject (readonly)

Returns the value of attribute paths.



24
25
26
# File 'lib/clickwrap/services/load_policies.rb', line 24

def paths
  @paths
end

#rootObject (readonly)

Returns the value of attribute root.



24
25
26
# File 'lib/clickwrap/services/load_policies.rb', line 24

def root
  @root
end

Instance Method Details

#callObject



26
27
28
29
30
31
32
33
34
# File 'lib/clickwrap/services/load_policies.rb', line 26

def call
  files = resolve_files
  return [] if files.empty?

  reset_registries!
  files.each { |file| load_file(file) }
  ValidatePolicyReferences.call
  files
end

#resolve_filesObject



36
37
38
39
40
# File 'lib/clickwrap/services/load_policies.rb', line 36

def resolve_files
  return [] if root.nil?

  paths.flat_map { |pattern| Dir[File.join(root, pattern)] }.uniq.sort
end