Skip to content

Conversation

@ixti
Copy link
Contributor

@ixti ixti commented Sep 25, 2025

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.

Allow multiple criterias and more complex values. Example:

``` ruby
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]
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant