Class: MountableFileServer::UniqueIdentifier

Inherits:
String
  • Object
show all
Defined in:
lib/mountable_file_server/unique_identifier.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ UniqueIdentifier

Returns a new instance of UniqueIdentifier.



10
11
12
13
14
15
16
17
18
# File 'lib/mountable_file_server/unique_identifier.rb', line 10

def initialize(string)
  raise MalformedIdentifier.new unless /(\w+)-(.+)$/.match(string)

  @type, @filename = /(\w+)-(.+)$/.match(string).captures

  raise UnknownType.new(type) unless known_type?

  super.freeze
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



8
9
10
# File 'lib/mountable_file_server/unique_identifier.rb', line 8

def filename
  @filename
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/mountable_file_server/unique_identifier.rb', line 8

def type
  @type
end

Class Method Details

.generate_for(type, extension) ⇒ Object



20
21
22
# File 'lib/mountable_file_server/unique_identifier.rb', line 20

def self.generate_for(type, extension)
  new "#{type}-#{SecureRandom.hex}#{extension}"
end

Instance Method Details

#public?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/mountable_file_server/unique_identifier.rb', line 24

def public?
  type == 'public'
end