Module: Qa::Authorities::Local

Extended by:
ActiveSupport::Autoload, AuthorityWithSubAuthority
Defined in:
lib/qa/authorities/local.rb,
lib/qa/authorities/local/registry.rb,
lib/qa/authorities/local/mysql_table_based_authority.rb

Defined Under Namespace

Classes: FileBasedAuthority, MysqlTableBasedAuthority, Registry, TableBasedAuthority

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from AuthorityWithSubAuthority

new, subauthorities, subauthority_class, subauthority_for, validate_subauthority!

Class Attribute Details

.configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/qa/authorities/local.rb', line 11

def config
  @config
end

Class Method Details

.load_config(file) ⇒ Object



13
14
15
# File 'lib/qa/authorities/local.rb', line 13

def load_config(file)
  @config = YAML.load_file(file)
end

.namesObject

Local sub-authorities are any YAML files in the subauthorities_path



28
29
30
31
32
33
# File 'lib/qa/authorities/local.rb', line 28

def names
  unless Dir.exist? subauthorities_path
    raise Qa::ConfigDirectoryNotFound, "There's no directory at #{subauthorities_path}. You must create it in order to use local authorities"
  end
  Dir.entries(subauthorities_path).map { |f| File.basename(f, ".yml") if f =~ /yml$/ }.compact
end

.register_subauthority(subauthority, class_name) ⇒ Object

Lookup and add the subauthority to the registry. This should only be used for sub-authorities, not stand-alone authorities such as Tgnlang, MESH, etc.

Parameters:

  • subauthority (String)

    a string representation of the subauthority (e.g. “language”)

  • class_name (String)

    a string representation of an authority class (e.g. “Qa::Authorities::Local::MysqlTableBasedAuthority”)



52
53
54
# File 'lib/qa/authorities/local.rb', line 52

def register_subauthority(subauthority, class_name)
  registry.add(subauthority, class_name)
end

.registryObject



40
41
42
43
44
45
46
# File 'lib/qa/authorities/local.rb', line 40

def registry
  @registry ||= begin
    Registry.new do |reg|
      register_defaults(reg)
    end
  end
end

.subauthoritiesObject



56
57
58
# File 'lib/qa/authorities/local.rb', line 56

def subauthorities
  registry.keys
end

.subauthorities_pathObject

Path to sub-authority files is either the full path to a directory or the path to a directory relative to the Rails application



19
20
21
22
23
24
25
# File 'lib/qa/authorities/local.rb', line 19

def subauthorities_path
  if config[:local_path].starts_with?(File::Separator)
    config[:local_path]
  else
    File.join(Rails.root, config[:local_path])
  end
end

.subauthority_for(subauthority) ⇒ Object



35
36
37
38
# File 'lib/qa/authorities/local.rb', line 35

def subauthority_for(subauthority)
  validate_subauthority!(subauthority)
  registry.instance_for(subauthority)
end