Skip to content

Instantly share code, notes, and snippets.

@lgrains
Last active December 22, 2015 18:49
Show Gist options
  • Save lgrains/6515452 to your computer and use it in GitHub Desktop.
Save lgrains/6515452 to your computer and use it in GitHub Desktop.
module Seed
class CourseRequirement < OpenStruct
include Gardener
def self.destroyable?
true
end
def attributes
{ coming_soon: coming_soon }
end
def degree
::Degree.find_by(title: degree_title)
end
def target
::CourseRequirement.find_or_create_by(
degree_id: degree.id,
requirement_type: requirement_type,
title: requirement_title
)
end
def valid?
degree && fields
end
def fields
!(requirement_type.empty? || requirement_title.empty?)
end
def log_error
puts "Degree by title: #{degree_title} not found" unless degree
puts "CourseRequirement by title: #{requirement_title} and type: #{requirement_type} not found" unless target
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment