Module: Diaspora::Fields::Guid

Included in:
Comment, Conversation, Like, Message, Notification, Participation, Person, Poll, PollAnswer, PollParticipation
Defined in:
lib/diaspora/fields/guid.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(model) ⇒ Object

Creates a after_initialize callback which calls #set_guid


7
8
9
10
11
12
# File 'lib/diaspora/fields/guid.rb', line 7

def self.included(model)
  model.class_eval do
    after_initialize :set_guid
    validates :guid, uniqueness: true
  end
end

Instance Method Details

#set_guidString

Returns The model's guid.

Returns:

  • (String)

    The model's guid.


15
16
17
# File 'lib/diaspora/fields/guid.rb', line 15

def set_guid
  self.guid = UUID.generate(:compact) if guid.blank?
end