Sha256: 802e2baf62c1b6f255365535bf70ae91c320cd3608ea0c074d20437a02b43adb

Contents?: true

Size: 870 Bytes

Versions: 7

Compression:

Stored size: 870 Bytes

Contents

module Qa::Authorities
  module AuthorityWithSubAuthority

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

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

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

    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

    # By default, an authority has no subauthorities unless they
    # are defined by the subclassed authority.
    def subauthorities
      []
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
qa-0.10.1 lib/qa/authorities/authority_with_sub_authority.rb
qa-0.10.0 lib/qa/authorities/authority_with_sub_authority.rb
qa-0.9.0 lib/qa/authorities/authority_with_sub_authority.rb
qa-0.8.0 lib/qa/authorities/authority_with_sub_authority.rb
qa-0.7.0 lib/qa/authorities/authority_with_sub_authority.rb
qa-0.6.0 lib/qa/authorities/authority_with_sub_authority.rb
qa-0.5.0 lib/qa/authorities/authority_with_sub_authority.rb