Sha256: cf916e695e38720e81d904fa2b08b50301681f776b783e97c9039699e8244794
Contents?: true
Size: 1.79 KB
Versions: 8
Compression:
Stored size: 1.79 KB
Contents
module Jazzy class SourceDeclaration class AccessControlLevel include Comparable attr_reader :level ACCESSIBILITY_PRIVATE = 'source.lang.swift.accessibility.private' ACCESSIBILITY_INTERNAL = 'source.lang.swift.accessibility.internal' ACCESSIBILITY_PUBLIC = 'source.lang.swift.accessibility.public' def initialize(accessibility) if accessibility == ACCESSIBILITY_PRIVATE @level = :private elsif accessibility == ACCESSIBILITY_INTERNAL @level = :internal elsif accessibility == ACCESSIBILITY_PUBLIC @level = :public else raise "cannot initialize AccessControlLevel with '#{accessibility}'" end end def self.from_doc(doc) accessibility = doc['key.accessibility'] if accessibility acl = new(accessibility) if acl return acl end end acl = from_explicit_declaration(doc['key.parsed_declaration']) acl || AccessControlLevel.public # fallback on public ACL end def self.from_explicit_declaration(declaration_string) if declaration_string =~ /private\ / return AccessControlLevel.private elsif declaration_string =~ /public\ / return AccessControlLevel.public elsif declaration_string =~ /internal\ / return AccessControlLevel.internal end end def self.private new(ACCESSIBILITY_PRIVATE) end def self.internal new(ACCESSIBILITY_INTERNAL) end def self.public new(ACCESSIBILITY_PUBLIC) end LEVELS = { private: 0, internal: 1, public: 2, }.freeze def <=>(other) LEVELS[level] <=> LEVELS[other.level] end end end end
Version data entries
8 entries across 8 versions & 1 rubygems