Created
June 1, 2015 01:55
-
-
Save johnpmitsch/c47d1c045b9929f16c61 to your computer and use it in GitHub Desktop.
find by version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_by_version(_key, operator, value) | |
major, minor = value.split('.') | |
case | |
when value.to_f < 1 | |
query = {} | |
when /[<>]/ =~ operator | |
minor ||= 0 | |
query = "major #{operator} :major OR (major = :major AND minor #{operator} :minor)" | |
when minor.nil? | |
query = "major #{operator} (?)" | |
else | |
query = "major #{operator} (?) and minor #{operator} (?)" | |
end | |
puts query | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment