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
# File 'lib/qa/authorities/local.rb', line 28

def names
  raise Qa::ConfigDirectoryNotFound, "There's no directory at #{subauthorities_path}. You must create it in order to use local authorities" unless Dir.exist? subauthorities_path
  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”)



48
49
50
# File 'lib/qa/authorities/local.rb', line 48

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

.registryObject



38
39
40
41
42
# File 'lib/qa/authorities/local.rb', line 38

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

.subauthoritiesObject



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

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
    Rails.root.join(config[:local_path]).to_s # TODO: Rails.root.join returns class Pathname, which may be ok.  Added to_s because of failing regression test.
  end
end

.subauthority_for(subauthority) ⇒ Object



33
34
35
36
# File 'lib/qa/authorities/local.rb', line 33

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