Skip to content

Commit

Permalink
Avoid check_flag_column method if no ActiveRecord class
Browse files Browse the repository at this point in the history
  • Loading branch information
jfcaiceo committed Aug 7, 2015
1 parent 0153c63 commit 5d74b5a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/flag_shih_tzu.rb
Expand Up @@ -34,7 +34,7 @@ def has_flags(*args)
opts[:column] = opts[:column].to_s
end
colmn = opts[:column]
if opts[:check_for_column] && !check_flag_column(colmn)
if opts[:check_for_column] && ( is_active_record_class? && !check_flag_column(colmn) )
warn "FlagShihTzu says: Flag column #{colmn} appears to be missing!\nTo turn off this warning set check_for_column: false in has_flags definition here: #{caller.first}"
return
end
Expand Down Expand Up @@ -91,7 +91,7 @@ def #{flag_name}_changed?
EVAL

if self.class.ancestors.include?(ActiveRecord::Base)
if self.ancestors.include?(ActiveRecord::Base)
class_eval <<-EVAL, __FILE__, __LINE__ + 1
def self.#{flag_name}_condition(options = {})
sql_condition_for_flag(:#{flag_name}, '#{colmn}', true, options[:table_alias] || self.table_name)
Expand Down Expand Up @@ -350,6 +350,10 @@ def named_scope_method
# Can't use respond_to because both AR 2 and 3 respond to both +scope+ and +named_scope+.
ActiveRecord::VERSION::MAJOR == 2 ? :named_scope : :scope
end

def is_active_record_class?
return self.ancestors.include?(ActiveRecord::Base)
end
end

# Performs the bitwise operation so the flag will return +true+.
Expand Down

0 comments on commit 5d74b5a

Please sign in to comment.