Class: MountableFileServer::UniqueIdentifier
- Inherits:
-
String
- Object
- String
- MountableFileServer::UniqueIdentifier
- Defined in:
- lib/mountable_file_server/unique_identifier.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(string) ⇒ UniqueIdentifier
constructor
A new instance of UniqueIdentifier.
- #public? ⇒ Boolean
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
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
8 9 10 |
# File 'lib/mountable_file_server/unique_identifier.rb', line 8 def filename @filename end |
#type ⇒ Object (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
24 25 26 |
# File 'lib/mountable_file_server/unique_identifier.rb', line 24 def public? type == 'public' end |