Sha256: f668679560eda5665b072277a6f0c9449522fd11adb4dbe43fe89bbf73b5bb7e

Contents?: true

Size: 735 Bytes

Versions: 1

Compression:

Stored size: 735 Bytes

Contents

module Traitor
  module ConflictCheck
    class TraitConflict < StandardError
    end

    def check(host_class)
      conflicts = []
      traits = host_class.traits
      traits.each do |t|
        traits.reject { |other| other == t }.each do |other|
          t.trait_methods.each do |m|
            conflicts << m if other.implements?(m)
          end
        end
      end
      conflicts.delete_if do |c|
        host_class.instance_methods(false).include?(c)
      end
      return false if conflicts.empty?

      output = "Conflicting methods: #{conflicts.uniq.map {|c| "##{c}"}.join(', ')}"
      raise TraitConflict, output
    end
    module_function :check
  end
end

TraitConflict = Traitor::ConflictCheck::TraitConflict

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
traitor-0.0.1 lib/traitor/conflict_check.rb