literal icon indicating copy to clipboard operation
literal copied to clipboard

POC: Refactor Literal::Enum finders

Open ixti opened this issue 2 months ago • 0 comments

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:

  1. find_by(...) should be as simple as where(...).first
  2. where(k: v) should allow non-literal values for filtering

If this is something that can be considered - I will revamp this PR and tests.

ixti avatar Sep 25 '25 21:09 ixti