Class: Trax::Model::UUID
- Inherits:
-
String
- Object
- String
- Trax::Model::UUID
- Defined in:
- lib/trax/model/uuid.rb
Class Method Summary collapse
- .generate(prefix = nil) ⇒ Object
- .klass_prefix_map ⇒ Object
- .prefix(prefix_value, klass) ⇒ Object
- .register(&block) ⇒ Object
Instance Method Summary collapse
Class Method Details
.generate(prefix = nil) ⇒ Object
12 13 14 15 16 |
# File 'lib/trax/model/uuid.rb', line 12 def self.generate(prefix = nil) uuid = ::SecureRandom.uuid uuid[0..1] = prefix if prefix uuid end |
.klass_prefix_map ⇒ Object
8 9 10 |
# File 'lib/trax/model/uuid.rb', line 8 def self.klass_prefix_map prefix_map.invert end |
.prefix(prefix_value, klass) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/trax/model/uuid.rb', line 18 def self.prefix(prefix_value, klass) if prefix_map.has_key(:"#{prefix_value}") && prefix_map[:"#{prefix_value}"] == klass raise ::Trax::Model::Errors::DuplicatePrefix.new(prefix_value) end prefix_map[:"#{prefix_value}"] = klass end |
.register(&block) ⇒ Object
26 27 28 |
# File 'lib/trax/model/uuid.rb', line 26 def self.register(&block) instance_exec(&block) end |
Instance Method Details
#record ⇒ Object
30 31 32 |
# File 'lib/trax/model/uuid.rb', line 30 def record @record ||= record_type ? record_type.find_by(:"#{record_type.unique_id_config.uuid_column}" => self) : nil end |
#record_type ⇒ Object
34 35 36 |
# File 'lib/trax/model/uuid.rb', line 34 def record_type @record_type ||= ::Trax::Model::Registry.model_type_for_uuid(self) end |