class Copyable::AssociationChecker

Public Instance Methods

associations(associations) click to toggle source
# File lib/copyable/syntax_checking/association_checker.rb, line 4
def associations(associations)
  @associations = associations.keys.map(&:to_s)
end

Private Instance Methods

expected_entries() click to toggle source
# File lib/copyable/syntax_checking/association_checker.rb, line 10
def expected_entries
  all_associations = model_class.reflect_on_all_associations
  required_associations = all_associations.select do |ass|
    !ass.is_a?(ActiveRecord::Reflection::BelongsToReflection) &&
    !ass.is_a?(ActiveRecord::Reflection::ThroughReflection)
  end
  required_associations.map(&:name).map(&:to_s)
end
extra_entries_found(extra_entries) click to toggle source
# File lib/copyable/syntax_checking/association_checker.rb, line 32
def extra_entries_found(extra_entries)
  message = "The following associations were listed in copyable's associations in the model '#{model_class.name}' "
  message << "but are either (1) not actually associations on this model or "
  message << "(2) an association that does not need to be listed "
  message << "(belongs to, has many through, or has one through):\n"
  extra_entries.each {|ass| message << "  association: #{ass}\n" }
  raise AssociationError.new(message)
end
missing_entries_found(missing_entries) click to toggle source
# File lib/copyable/syntax_checking/association_checker.rb, line 23
def missing_entries_found(missing_entries)
  message = "The following associations were not listed "
  message << "in copyable's associations in the model '#{model_class.name}':\n"
  missing_entries.each {|ass| message << "  association: #{ass}\n" }
  message << "Basically, if you just added a new association to this model, you need to update "
  message << "the copyable declaration to instruct it how to deal with copying the associated models.\n"
  raise AssociationError.new(message)
end
provided_entries() click to toggle source
# File lib/copyable/syntax_checking/association_checker.rb, line 19
def provided_entries
  @associations
end