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



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

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.



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

def subauthorities
  []
end

#subauthority_class(name) ⇒ Object



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

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

#subauthority_for(subauthority) ⇒ Object



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

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

#validate_subauthority!(subauthority) ⇒ Object



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

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