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

cannot annotate 'acronym classes' #22

Closed
nbt opened this issue Apr 19, 2011 · 10 comments
Closed

cannot annotate 'acronym classes' #22

nbt opened this issue Apr 19, 2011 · 10 comments
Assignees
Labels

Comments

@nbt
Copy link

nbt commented Apr 19, 2011

Trying to annotate a class with a string of capital letters such as IRSDocuments in a file named "irs_documents.rb" will fail with the message:

Unable to annotate irs_documents.rb: #<NameError: uninitialized constant IrsDocuments>
  • If there is no mechanism to handle this, it should be added
  • If there is a mechanism to handle this, please excuse me, and it should be better documented.
@ctran
Copy link
Owner

ctran commented Jun 27, 2011

What is your Rails application environment (http://localhost:3000/rails/info/properties)?

@nbt
Copy link
Author

nbt commented Jun 27, 2011

Ruby version 1.9.2 (x86_64-darwin10.6.0)
RubyGems version 1.3.7
Rack version 1.2
Rails version 3.0.5
Active Record version 3.0.5
Action Pack version 3.0.5
Active Resource version 3.0.5
Action Mailer version 3.0.5
Active Support version 3.0.5
Middleware
ActionDispatch::Static
Rack::Lock
ActiveSupport::Cache::Strategy::LocalCache
Rack::Runtime
Rails::Rack::Logger
ActionDispatch::ShowExceptions
ActionDispatch::RemoteIp
Rack::Sendfile
ActionDispatch::Callbacks
ActiveRecord::ConnectionAdapters::ConnectionManagement
ActiveRecord::QueryCache
ActionDispatch::Cookies
ActionDispatch::Session::CookieStore
ActionDispatch::Flash
ActionDispatch::ParamsParser
Rack::MethodOverride
ActionDispatch::Head
ActionDispatch::BestStandardsSupport
Warden::Manager
Application root /Users/r/Developer/bluedot
Environment development
Database adapter postgresql
Database schema version 20110621161403

@alexeymuranov
Copy link

I have probably a related issue. I have models Admin::User and Admin::KnownIP in files models/admin/user.rb and models/admin/known_ip.rb. I also use set_table_name :admin_known_ips in Admin::KnownIP class. The User model gets annotated fine, but not KnownIP, and i get the following message:

$ bundle exec annotate
Unable to annotate admin/known_ip.rb: #<TypeError: nil is not a symbol>
...

@nbt
Copy link
Author

nbt commented Jan 2, 2012

bump?

@KL-7
Copy link
Contributor

KL-7 commented Jan 28, 2012

In my own project I just hacked into the source of the gem to annotate models in CRM module, but I'm seriously thinking about surrendering and renaming it to Crm.

There was a pull request to Rails that added support for acronyms to ActiveSupport::Infrector. I doubt that's possible to use it directly as that will make annotate_models dependent on very high version of active_support, but may be smth similar can be added to the gem itself. Alternatively Infrector can be monkey-patched to work with earlier versions of active_support.

May be I could help with implementation, but I'm not sure what'd be the best interface for that. Should it be just an CLI option that will accept list of acronyms that will be later used to perform replacement in generated class names? Should it be list of words themselves (like xml, crm, etc.) or full class names?

Btw, may be there is a different way to retrieve name of the class defined in some file other than camelizing file name. It'd be nice to find one.

@ctran, care to share your thoughts on that?

@alexeymuranov
Copy link

My understanding was that there is no need to retrieve the name of the class from the name of the file, it is the other way around: if a file with a class definition was not explicitly required, then its name is inferred from the name of the class.

@KL-7
Copy link
Contributor

KL-7 commented Jan 28, 2012

@alexeymuranov, have a look at AnnotateModels.get_model_class method. It's used to retrieve classes from file names passed to annotate command.

@alexeymuranov
Copy link

Ok, i see, this is not nice. It would seem more reasonable to me to create some "sandbox" module, inside of it require active_record (with module_eval), then require the files, then see what ActiveRecord::Base classes have been defined and ask them their table names.

@ctran
Copy link
Owner

ctran commented Jan 29, 2012

This has never been an issue for me so I procrastinated a bit :-).
Let me take a closer look at it this weekend since it seems enough people run into this problem.

@ghost ghost assigned ctran Jan 29, 2012
@alexeymuranov
Copy link

If i may express my thought, there seem to be two approaches possible:

  • either annotate_models gem annotates models, in this case probably some kind of ruby environment sandbox is needed so safely execute model files in it to learn model attributes,
  • or models annotate themselves with the help of annotate_models gem, then models would be responsible themselves to run nicely.

@ctran ctran closed this as completed Nov 30, 2013
ctran pushed a commit that referenced this issue Dec 21, 2013
ctran pushed a commit that referenced this issue Dec 21, 2013
ctran pushed a commit that referenced this issue Feb 26, 2014
* release/2.6.2:
  v2.6.2
  Add known changes for 2.6.2.
  Retain existing position unless :force is passed
  Temporarily ignore integration tests
  Revert "Replacing old block with new one."
  Change email address
  Add .travis.yml
  switch deprecated "mock" for "double" in annotate specs
  use general file resolution for test files as well
  Replacing old block with new one.
  Fixed gemspec files attribute
  migrate.rake should live in lib/tasks
  Always load models, since they may not be autoloaded by Rails
  Handle the "--exclude" option correctly, #152 and #160
  FIX #157
  Pump version to 2.6.1 which fixes #22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants