Sha256: 26bcac299206598e48d340ff99c15992f3cff8e59116087e1c0e76a2a738d7b1

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

module MixinComment
  class Verifier
    def initialize(part)
      @part = part
    end

    def call
      included_classes(@part.module_name).each do |klass|
        @part.attributes.each do |attr|
          send("verify_#{@part.label.gsub(' ', '_')}", klass, attr)
        end
      end
    end

    private

    def included_classes(module_name)
      mod = module_name.constantize
      klasses = ObjectSpace.each_object(Class).to_a
      klasses.select { |klass| klass.included_modules.include?(mod) }.sort_by(&:name)
    end

    def verify_required_methods(klass, attr)
      unless klass.method_defined?(attr)
        @part.errors << [klass, attr]
      end
    end

    def verify_required_class_methods(klass, attr)
      unless klass.singleton_class.method_defined?(attr)
        @part.errors << [klass, attr]
      end
    end

    def verify_required_override_methods(klass, attr)
      unless klass.method_defined?(attr, false)
        @part.errors << [klass, attr]
      end
    end

    def verify_required_columns(klass, attr)
      unless klass.column_names.include?(attr)
        @part.errors << [klass, attr]
      end
    end

    def verify_required_associations(klass, attr)
      unless klass.reflect_on_association(attr)
        @part.errors << [klass, attr]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mixin_comment-0.1.2 lib/mixin_comment/verifier.rb
mixin_comment-0.1.1 lib/mixin_comment/verifier.rb
mixin_comment-0.1.0 lib/mixin_comment/verifier.rb