2015-09-08 09:44:40 +00:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: clients
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# name :string not null
|
|
|
|
# key :string not null
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
#
|
|
|
|
|
2015-09-08 09:30:11 +00:00
|
|
|
class Client < ActiveRecord::Base
|
2015-09-09 10:49:24 +00:00
|
|
|
has_many :issued_transactions, as: :issuer, class_name: 'Transaction'
|
2015-09-08 12:26:04 +00:00
|
|
|
before_create :generate_key
|
|
|
|
|
2015-09-08 13:51:23 +00:00
|
|
|
validates :name, presence: true, uniqueness: true
|
|
|
|
|
2015-09-08 12:26:04 +00:00
|
|
|
private
|
|
|
|
def generate_key
|
|
|
|
self.key = SecureRandom.base64(16) unless self.key
|
|
|
|
end
|
2015-09-08 09:30:11 +00:00
|
|
|
end
|