Skip to content

Commit

Permalink
Rubify save and valid?
Browse files Browse the repository at this point in the history
  • Loading branch information
netzpirat committed Mar 7, 2011
1 parent 3667448 commit 6e91865
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions lib/active_conductor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,15 @@ def new_record?
# @return [true, false] the error status
#
def valid?
result = true

models.each do |model|
if !model.valid?
result = false
end
models.inject(true) do |result, model|
valid = model.valid?

model.errors.each do |field, value|
errors.add(field, value)
end
end

result
result && valid
end
end

# Returns the errors of the conductor. The errors
Expand All @@ -121,15 +117,7 @@ def models
# @return [true, false] the saved status
#
def save
if valid?
models.each do |model|
unless model.save
return false
end
end

true
end
models.each { |model| return false unless model.save } if valid?
end

# Create and persist a new conductor in one step.
Expand Down

0 comments on commit 6e91865

Please sign in to comment.