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

Already on GitHub? Sign in to your account

Additional checks #82

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+2 −2
Split
@@ -82,7 +82,7 @@ def get_schema_info(klass, header, options = {})
attrs = []
attrs << "default(#{quote(col.default)})" unless col.default.nil?
attrs << "not null" unless col.null
- attrs << "primary key" if col.name.to_sym == klass.primary_key.to_sym
+ attrs << "primary key" if klass.primary_key && col.name.to_sym == klass.primary_key.to_sym
@arturtr

arturtr Jun 18, 2012

I solve this problem this way:

attrs << "primary key" if col.name.to_sym == klass.primary_key.try(:to_sym)
@alexch

alexch Jul 13, 2012

Collaborator

"try" seems like a fun method. Where is it defined?

@alexch

alexch Jul 14, 2012

Collaborator

Don't know if we can use ActiveSupport methods since some people use
Annotate without Rails.

https://github.com/rails/rails/blob/6ef9fda1a39f45e2d18aba4881f60a19589a2c77/activesupport/lib/active_support/core_ext/object/try.rb#L32

On Fri, Jul 13, 2012 at 4:33 PM, arturtr
reply@reply.github.com
wrote:

@@ -82,7 +82,7 @@ def get_schema_info(klass, header, options = {})
attrs = []
attrs << "default(#{quote(col.default)})" unless col.default.nil?
attrs << "not null" unless col.null

  •    attrs << "primary key" if col.name.to_sym == klass.primary_key.to_sym
    
  •    attrs << "primary key" if klass.primary_key && col.name.to_sym == klass.primary_key.to_sym
    

http://api.rubyonrails.org/classes/Object.html#method-i-try


Reply to this email directly or view it on GitHub:
https://github.com/ctran/annotate_models/pull/82/files#r1163133

Alex Chaffee - alex@stinky.com
http://alexchaffee.com
http://twitter.com/alexch

col_type = (col.type || col.sql_type).to_s
if col_type == "decimal"
@@ -318,7 +318,7 @@ def get_model_class(file)
# Retrieve loaded model class by path to the file where it's supposed to be defined.
def get_loaded_model(model_path)
ObjectSpace.each_object.
- select { |c| c.is_a?(Class) && c.ancestors.include?(ActiveRecord::Base) }.
+ select { |c| Class === c && c.ancestors.respond_to?(:include?) && c.ancestors.include?(ActiveRecord::Base) }.
detect { |c| ActiveSupport::Inflector.underscore(c) == model_path }
end