Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing of class fails if class name is defined based on condition. #260

Open
yami0101 opened this issue Feb 5, 2018 · 0 comments
Open

Comments

@yami0101
Copy link

yami0101 commented Feb 5, 2018

RubyCritic 3.3.0
Ruby 2.3.1

When running rubycritic on such a module, it fails with with the following exception 'Reek::Errors::IncomprehensibleSourceError'.

module ExceptionHandler
    # => Class (inheritance dependent on whether db option is available)
    self::Exception = Class.new(
      (ExceptionHandler.config.try(:db) && defined?(ActiveRecord)) ? ActiveRecord::Base : Object
    ) do
      #Some code
    end
end

It seems that the ternary operator in the class name definition is causing this. Because if we change the code to:

module ExceptionHandler
    # => Class (inheritance dependent on whether db option is available)
    foo =(ExceptionHandler.config.try(:db) && defined?(ActiveRecord)) ? ActiveRecord::Base : Object
    self::Exception = Class.new(foo) do
      #Some code
    end
  end

there is no exception.

The exception happens on examiner.rb:107:in `rescue in run': !!! (Reek::Errors::IncomprehensibleSourceError)

Exception message:
undefined method `name' for #<#<Class:0x007f82aa196e58>:0x007f82aa1957d8>

I stumbled upon this exception when trying to run rubycritic on a project with the exception_handler GEM. The code in the above example is generated automatically by their GEM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant