Module: ActiveUUID::UUID

Included in:
Account, AccountDomain, AccountRole, AccountUser, ApiToken, SocialAccount, User, UserInvitation
Defined in:
lib/iugusdk/uuid_mass_assignment_fix.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
# File 'lib/iugusdk/uuid_mass_assignment_fix.rb', line 3

def self.included(base)
  base.before_validation :fix_uuid_strings
end

Instance Method Details

#fix_uuid_stringsObject



7
8
9
10
11
12
13
14
15
# File 'lib/iugusdk/uuid_mass_assignment_fix.rb', line 7

def fix_uuid_strings
  self.class.columns_hash.each do |key, fk|
    next unless fk.type == :binary && fk.limit == 255 && /^.+_id$/.match(key.to_s)
    value = self.send fk.name
    if !value.blank? && value.class != UUIDTools::UUID
      self.send "#{fk.name}=", value.to_uuid
    end
  end
end