Skip to content
This repository has been archived by the owner on Jun 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #67 from smudge/indexable_with_scopes
Browse files Browse the repository at this point in the history
Use '>' operator instead of '<>' to make 'with' scopes indexable.
  • Loading branch information
spemmons committed Oct 23, 2015
2 parents 26c66ee + 3e3be4e commit 7777077
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/bitmask_attributes/definition.rb
Expand Up @@ -152,7 +152,7 @@ def create_scopes_on(model)
else
sets = values.map do |value|
mask = ::#{model}.bitmask_for_#{attribute}(value)
"#{model.table_name}.#{attribute} & \#{mask} <> 0"
"#{model.table_name}.#{attribute} & \#{mask} > 0"
end
where(sets.join(' AND '))
end
Expand Down Expand Up @@ -182,14 +182,14 @@ def create_scopes_on(model)
if values.blank?
where('#{model.table_name}.#{attribute} > 0')
else
where("#{model.table_name}.#{attribute} & ? <> 0", ::#{model}.bitmask_for_#{attribute}(*values))
where("#{model.table_name}.#{attribute} & ? > 0", ::#{model}.bitmask_for_#{attribute}(*values))
end
}
)
values.each do |value|
model.class_eval %(
scope :#{attribute}_for_#{value},
proc { where('#{model.table_name}.#{attribute} & ? <> 0', ::#{model}.bitmask_for_#{attribute}(:#{value})) }
proc { where('#{model.table_name}.#{attribute} & ? > 0', ::#{model}.bitmask_for_#{attribute}(:#{value})) }
)
end
end
Expand Down

0 comments on commit 7777077

Please sign in to comment.