Parent

Class/Module Index [+]

Quicksearch

Key

Public Class Methods

find_or_create(user, typ, parent=nil) click to toggle source
# File app/models/key.rb, line 11
  def self.find_or_create(user, typ, parent=nil)
    if parent.nil? || !parent
      kk=Key.where(user_id: user.id, typ: typ, is_valid: true).first
      if kk.nil?
        kk=Key.new 
        kk.user=user 
        kk.typ = typ 
        kk.is_valid = true
        kk.save
      end
    else
      kk=Key.where(user_id: user.id, typ: typ, is_valid: true, parent_type: parent.class.to_s, parent_id: parent.id).first

      if kk.nil?
        kk=Key.new 
        kk.user=user 
        kk.typ = typ 
        kk.is_valid = true
kk.parent=parent
        kk.save
      end
    end
    kk
  end

Public Instance Methods

create_unique_identifier() click to toggle source
# File app/models/key.rb, line 6
def create_unique_identifier
  begin
    self.uuid = SecureRandom.hex(10) # or whatever you chose like UUID tools
  end while self.class.exists?(:uuid => uuid)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.