summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2017-10-02 16:54:33 +0200
committerHarald Eilertsen <haraldei@anduin.net>2017-10-02 16:54:33 +0200
commit1bce43d6a51ee09631f55cf427a2e110d901ecb2 (patch)
tree872cf8d6d975c5c17d446e7ec7d45e52ce669242 /lib
parentac268300ef9e97f8b1a3e2fc6d0bf5903bf7067b (diff)
downloadnorsk-urskog-registrations-1bce43d6a51ee09631f55cf427a2e110d901ecb2.tar.gz
norsk-urskog-registrations-1bce43d6a51ee09631f55cf427a2e110d901ecb2.tar.bz2
norsk-urskog-registrations-1bce43d6a51ee09631f55cf427a2e110d901ecb2.zip
Don't validate again when checking if valid.
Unless validation has not yet been performed, of course.
Diffstat (limited to 'lib')
-rw-r--r--lib/band.rb11
-rw-r--r--lib/contact.rb2
2 files changed, 6 insertions, 7 deletions
diff --git a/lib/band.rb b/lib/band.rb
index 9b949c7..dc69642 100644
--- a/lib/band.rb
+++ b/lib/band.rb
@@ -7,7 +7,6 @@ class Band
attr_accessor :errors
def initialize(params = nil)
- @errors = []
@contact = Contact.new
@members = ""
@songs = []
@@ -31,13 +30,13 @@ class Band
end
def valid?
- validate!
- errors.length == 0
+ validate! unless errors
+ !has_errors?
end
def validate!
@errors = []
-
+
if @name.nil? || @name.strip.empty?
errors << "Bandnavn mangler"
end
@@ -49,8 +48,8 @@ class Band
end
end
- def has_errors
- errors.length > 0
+ def has_errors?
+ errors && errors.length > 0
end
def name_and_city
diff --git a/lib/contact.rb b/lib/contact.rb
index d5fd267..0a7a449 100644
--- a/lib/contact.rb
+++ b/lib/contact.rb
@@ -17,7 +17,7 @@ class Contact
end
def valid?
- validate!
+ validate! unless @errors
@errors.length == 0
end