Module: UniversalIdentifiable

Defined in:
lib/universal_identifiable.rb,
lib/universal_identifiable/version.rb

Constant Summary collapse

NAMESPACER =
"."
REGEX =
Regexp.new("\\#{NAMESPACER}(.*)")
VERSION =
"0.1.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



10
11
12
# File 'lib/universal_identifiable.rb', line 10

def self.included(base)
  base.validates :uuid, :presence => true, :uniqueness => true
end

Instance Method Details

#uuid(options = {}) ⇒ Object



14
15
16
17
# File 'lib/universal_identifiable.rb', line 14

def uuid(options={})
  options[:namespaced] = true if options[:namespaced].nil?
  options[:namespaced] ? read_attribute(:uuid) : short_uuid
end

#uuid=(uuid) ⇒ Object



19
20
21
22
# File 'lib/universal_identifiable.rb', line 19

def uuid=(uuid)
  uuid = "#{self.class.name.underscore}#{NAMESPACER}#{uuid}" if uuid
  super uuid
end