lib/canard/user_model.rb in canard-0.3.4 vs lib/canard/user_model.rb in canard-0.3.5
- old
+ new
@@ -57,11 +57,11 @@
options = args.extract_options!.symbolize_keys
roles options[:roles] if options.has_key?(:roles) && has_roles_mask_attribute? || has_roles_mask_accessors?
- if respond_to?(:table_exists?) && table_exists?
+ if active_record_table?
valid_roles.each do |role|
define_scopes_for_role role
end
define_scope_method(:with_any_role) do |*roles|
@@ -74,18 +74,22 @@
end
end
private
+ def active_record_table?
+ respond_to?(:table_exists?) && table_exists?
+ end
+
def has_roles_mask_accessors?
instance_method_names = instance_methods.map { |method_name| method_name.to_s }
[roles_attribute_name.to_s, "#{roles_attribute_name}="].all? do |accessor|
instance_method_names.include?(accessor)
end
end
def has_roles_mask_attribute?
- respond_to?(:column_names) && column_names.include?(roles_attribute_name.to_s)
+ active_record_table? && column_names.include?(roles_attribute_name.to_s)
end
def define_scopes_for_role(role)
include_scope = role.to_s.pluralize
exclude_scope = "non_#{include_scope}"