Commit 886a0f480051c898c6d3fa0d559dc25e015c573c

Authored by Fabio Teixeira
Committed by David Silva
1 parent 27953f72

Refactory library.rb

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing 1 changed file with 6 additions and 20 deletions   Show diff stats
lib/library.rb
1 class Library < ActiveRecord::Base 1 class Library < ActiveRecord::Base
2 -  
3 - #TODO missing relations?  
4 -  
5 attr_accessible :name, :version, :license, :software_info_id 2 attr_accessible :name, :version, :license, :software_info_id
6 3
7 - validate :validate_name, :validate_version, :validate_license  
8 - validates :name, length: { within: 0..20 }  
9 - validates_length_of :version, maximum: 20, too_long: _("Library is too long (maximum is 20 characters)")  
10 - validates_length_of :license, maximum: 20, too_long: _("Library is too long (maximum is 20 characters)")  
11 -  
12 - def validate_name  
13 - self.errors.add(:name, _("can't be blank")) if self.name.blank? && self.errors[:name].blank?  
14 - end  
15 -  
16 - def validate_version  
17 - self.errors.add(:version, _("can't be blank")) if self.version.blank? && self.errors[:version].blank?  
18 - end  
19 -  
20 - def validate_license  
21 - self.errors.add(:license, _("can't be blank")) if self.license.blank? && self.errors[:license].blank?  
22 - end  
23 - 4 + validates :name, :version, :license,
  5 + presence: { message: _("can't be blank") },
  6 + length: {
  7 + maximum: 20,
  8 + too_long: _("Too long (maximum is 20 characters)")
  9 + }
24 end 10 end