summaryrefslogtreecommitdiff
path: root/vendor/certificate_authority/lib/certificate_authority/validations.rb
blob: a429c9683a3d1e4dfd6350452888f9c40b8dd718 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#
# This is a super simple replacement for ActiveSupport::Validations
#

module CertificateAuthority
  class Errors < Array
    def add(symbol, msg)
      self.push([symbol, msg])
    end
    def full_messages
      self.map {|i| i[0].to_s + ": " + i[1]}.join("\n")
    end
  end

  module Validations
    def valid?
      @errors = Errors.new
      validate
      errors.empty?
    end

    # must be overridden
    def validate
      raise NotImplementedError
    end

    def errors
      @errors ||= Errors.new
    end
  end
end