Module: Dcmgr::Models::UUIDMethods
- Included in:
- Base
- Defined in:
- lib/dcmgr/models/base.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #before_create ⇒ Object
- #generate_uuid ⇒ Object
- #save(*columns) ⇒ Object
- #setup_uuid ⇒ Object
- #to_s ⇒ Object
- #uuid ⇒ Object
Instance Method Details
#before_create ⇒ Object
41 42 43 |
# File 'lib/dcmgr/models/base.rb', line 41 def before_create setup_uuid end |
#generate_uuid ⇒ Object
33 34 35 |
# File 'lib/dcmgr/models/base.rb', line 33 def generate_uuid "%08x" % rand(16 ** 8) end |
#save(*columns) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/dcmgr/models/base.rb', line 45 def save(*columns) super rescue Sequel::DatabaseError => e Dcmgr.logger.info "db error: %s" % e Dcmgr.logger.info " " + e.backtrace.join("\n ") raise DuplicateUUIDError if /^Mysql::Error: Duplicate/ =~ e. raise e end |
#setup_uuid ⇒ Object
37 38 39 |
# File 'lib/dcmgr/models/base.rb', line 37 def setup_uuid self.uuid = generate_uuid unless self.values[:uuid] end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/dcmgr/models/base.rb', line 59 def to_s uuid end |
#uuid ⇒ Object
55 56 57 |
# File 'lib/dcmgr/models/base.rb', line 55 def uuid "%s-%s" % [self.class.prefix_uuid, self.values[:uuid]] end |