Module: UuidProperties
- Defined in:
- lib/uuid_properties.rb,
lib/uuid_properties/version.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- UUID_PATTERN =
/\A[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}\Z/
- VERSION =
"0.1.0"
Class Method Summary collapse
Instance Method Summary collapse
-
#generate_uuid ⇒ Object
The underlying Postgres tables themselves will generate UUIDs by default, but ActiveRecord in general doesn’t play nicely with default databases values so we set UUIDs in our models first.
Class Method Details
.included(klass) ⇒ Object
8 9 10 11 12 |
# File 'lib/uuid_properties.rb', line 8 def self.included(klass) klass.extend(ClassMethods) klass.before_validation :generate_uuid klass.validates_presence_of :uuid end |
Instance Method Details
#generate_uuid ⇒ Object
The underlying Postgres tables themselves will generate UUIDs by default, but ActiveRecord in general doesn’t play nicely with default databases values so we set UUIDs in our models first.
17 18 19 |
# File 'lib/uuid_properties.rb', line 17 def generate_uuid self.uuid ||= SecureRandom.uuid end |