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.

Raises:



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

def initialize(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.



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

def filename
  @filename
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Class Method Details

.generate_for(type, extension) ⇒ Object



17
18
19
# File 'lib/mountable_file_server/unique_identifier.rb', line 17

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

Instance Method Details

#public?Boolean

Returns:



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

def public?
  type == 'public'
end