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

Multiple enum_attr's and annotate gem #56

Open
jgrocho opened this issue Jul 19, 2012 · 1 comment · May be fixed by #65
Open

Multiple enum_attr's and annotate gem #56

jgrocho opened this issue Jul 19, 2012 · 1 comment · May be fixed by #65

Comments

@jgrocho
Copy link

jgrocho commented Jul 19, 2012

Given a model that looks like

class user < ActiveRecord::Base
    enum_attr :status %w{suspended pending approved}
    enum_attr :role %w{regular moderator admin}
end

When attempting to run annotate on that model,
Then I get the following error

Unable to annotate user.rb: #<MetaProgramming::AliasMethodChainError: method_missing_without_enumerated_attribute already exists.  Circular references not permitted.>

Nothing annotated.

I seem to have narrowed it down to the fact that enum_attr is being used twice in the model. Removing (or commenting out) one or both allows the model to be annotated as expected, even when both enums are defined in the migration. My guess is that method_missing_without_enumerated_attribute is being defined each time enum_attr is used, but I don't know enough about the internals of enumerated_attribute to determine this.

@rchekaluk
Copy link

More in-depth stack trace:

$ bundle exec annotate --position before
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/meta_programming-0.2.2/lib/meta_programming/object.rb:43:in `block in safe_alias_method_chain': method_missing_without_enumerated_attribute already exists.  Circular references not permitted. (MetaProgramming::AliasMethodChainError)
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/meta_programming-0.2.2/lib/meta_programming/object.rb:39:in `class_eval'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/meta_programming-0.2.2/lib/meta_programming/object.rb:39:in `safe_alias_method_chain'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/meta_programming-0.2.2/lib/meta_programming/object.rb:66:in `define_chained_method'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/enumerated_attribute-0.2.16/lib/enumerated_attribute/integrations/active_record.rb:103:in `singleton class'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/enumerated_attribute-0.2.16/lib/enumerated_attribute/integrations/active_record.rb:90:in `block in define_enumerated_attribute_new_method'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/enumerated_attribute-0.2.16/lib/enumerated_attribute/integrations/active_record.rb:89:in `class_eval'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/enumerated_attribute-0.2.16/lib/enumerated_attribute/integrations/active_record.rb:89:in `define_enumerated_attribute_new_method'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/enumerated_attribute-0.2.16/lib/enumerated_attribute/attribute.rb:45:in `create_enumerated_attribute'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/enumerated_attribute-0.2.16/lib/enumerated_attribute.rb:13:in `enumerated_attribute'
    from /redacted/app/models/redacted.rb:77:in `<class:Redacted>'
    from /redacted/app/models/redacted.rb:61:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:469:in `load'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:469:in `block in load_file'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:639:in `new_constants_in'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:468:in `load_file'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:353:in `require_or_load'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:502:in `load_missing_constant'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:192:in `block in const_missing'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:190:in `each'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:190:in `const_missing'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:514:in `load_missing_constant'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:192:in `block in const_missing'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:190:in `each'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:190:in `const_missing'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/inflector/methods.rb:230:in `block in constantize'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/inflector/methods.rb:229:in `each'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/inflector/methods.rb:229:in `constantize'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/inflector/methods.rb:260:in `safe_constantize'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/core_ext/string/inflections.rb:66:in `safe_constantize'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/actionpack-3.2.16/lib/action_controller/metal/params_wrapper.rb:152:in `_default_wrap_model'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/actionpack-3.2.16/lib/action_controller/metal/params_wrapper.rb:169:in `_set_wrapper_defaults'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/actionpack-3.2.16/lib/action_controller/metal/params_wrapper.rb:133:in `inherited'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/actionpack-3.2.16/lib/abstract_controller/railties/routes_helpers.rb:7:in `block (2 levels) in with'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/actionpack-3.2.16/lib/action_controller/railties/paths.rb:7:in `block (2 levels) in with'
    from /redacted/app/controllers/redacted_controller.rb:5:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:469:in `load'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:469:in `block in load_file'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:639:in `new_constants_in'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:468:in `load_file'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:353:in `require_or_load'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:313:in `depend_on'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:225:in `require_dependency'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.16/lib/rails/engine.rb:444:in `block (2 levels) in eager_load!'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.16/lib/rails/engine.rb:443:in `each'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.16/lib/rails/engine.rb:443:in `block in eager_load!'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.16/lib/rails/engine.rb:441:in `each'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.16/lib/rails/engine.rb:441:in `eager_load!'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.16/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/annotate-2.6.0/lib/annotate.rb:109:in `eager_load'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/annotate-2.6.0/bin/annotate:146:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/bin/annotate:23:in `load'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/bin/annotate:23:in `<main>'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `eval'
    from /usr/local/rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `<main>'

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

Successfully merging a pull request may close this issue.

2 participants