Module: SharedBehaviors::ClassMethods

Defined in:
lib/daily/shared_behaviors.rb

Instance Method Summary collapse

Instance Method Details

#generate_guid(field) ⇒ Object



40
41
42
43
44
# File 'lib/daily/shared_behaviors.rb', line 40

def generate_guid(field)
  @guid_field = field.to_sym
  validates_presence_of @guid_field
  before_validation :generate_guid_if_needed
end

#guid_fieldObject



45
46
47
# File 'lib/daily/shared_behaviors.rb', line 45

def guid_field
  @guid_field
end

#validates_stripped_presence_of(field) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/daily/shared_behaviors.rb', line 49

def validates_stripped_presence_of(field)
  validates_presence_of field
  method = "strip_before_validation_#{field}"
  define_method method do
    return true if send(field).nil?
    send("#{field}=", send(field).strip)
  end
  before_validation method
end

#validates_unique_presence_of(field) ⇒ Object



59
60
61
62
# File 'lib/daily/shared_behaviors.rb', line 59

def validates_unique_presence_of(field)
  validates_stripped_presence_of field
  validates_uniqueness_of field, :case_sensitive => false
end