literal
literal copied to clipboard
POC: Refactor Literal::Enum finders
Allow multiple criterias and more complex values. Example:
class Example < Literal::Enum(String)
prop :score, Integer
index :score, Integer, unique: false
A = new("a", score: 5)
B = new("b", score: 4)
C = new("c", score: 3)
D = new("d", score: 2)
E = new("e", score: 1)
end
Example.where(score: 2..4) # => [Example::B, Example::C, Example::D]
Example.where(score: :odd?.to_proc) # => [Example::A, Example::C, Example::E]
I agree that multi-key filtering is probably not needed, but I do think that:
find_by(...)should be as simple aswhere(...).firstwhere(k: v)should allow non-literal values for filtering
If this is something that can be considered - I will revamp this PR and tests.