Skip to content

Instantly share code, notes, and snippets.

@johnpmitsch
Created May 29, 2015 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnpmitsch/a59ee6efacc8d752b2b2 to your computer and use it in GitHub Desktop.
Save johnpmitsch/a59ee6efacc8d752b2b2 to your computer and use it in GitHub Desktop.
Content View Version
def self.find_by_version(key, operator, value)
major, minor = value.to_s.split('.')
if minor.nil? or /[<>]/ =~ operator
query = where("major #{operator} ?", major)
else
query = where("major #{operator} ? and minor #{operator} ?", major, minor)
end
_, conditions = query.to_sql.split("WHERE")
{ :conditions => conditions }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment