Module: Qa::Authorities::AuthorityWithSubAuthority

Included in:
AssignFast, Getty, Loc, Local, Oclcts
Defined in:
lib/qa/authorities/authority_with_sub_authority.rb

Instance Method Summary collapse

Instance Method Details

#new(subauthority = nil) ⇒ Object



3
4
5
# File 'lib/qa/authorities/authority_with_sub_authority.rb', line 3

def new(subauthority = nil)
  raise "Initializing with as sub authority is removed. use #{self.class}.subauthority_for(#{subauthority.inspect}) instead"
end

#subauthoritiesObject

By default, an authority has no subauthorities unless they are defined by the subclassed authority.



22
23
24
# File 'lib/qa/authorities/authority_with_sub_authority.rb', line 22

def subauthorities
  []
end

#subauthority_class(name) ⇒ Object



12
13
14
# File 'lib/qa/authorities/authority_with_sub_authority.rb', line 12

def subauthority_class(name)
  [self, name].join('::').classify.constantize
end

#subauthority_for(subauthority) ⇒ Object



7
8
9
10
# File 'lib/qa/authorities/authority_with_sub_authority.rb', line 7

def subauthority_for(subauthority)
  validate_subauthority!(subauthority)
  subauthority_class(subauthority).new
end

#validate_subauthority!(subauthority) ⇒ Object



16
17
18
# File 'lib/qa/authorities/authority_with_sub_authority.rb', line 16

def validate_subauthority!(subauthority)
  raise Qa::InvalidSubAuthority, "Unable to initialize sub-authority #{subauthority} for #{self}. Valid sub-authorities are #{subauthorities.inspect}" unless subauthorities.include?(subauthority)
end