hquery 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7bb53d5ee3e79e1de862b0d74ecd772407093472ecda2affed913488583d6700
4
+ data.tar.gz: 6810348afbde8e4a3ba8659b9cb8d9615704e21de183ff73e4cf8276249aebb9
5
+ SHA512:
6
+ metadata.gz: ff9d72ae2a9b43791f1e6f7a4dd5d77e51ad5f2f6d26f4cc99af00f526196e8aa06a3cdd46fd706c036e69a0d10de084e9b1d6739fd7f94a24433860b95dc143
7
+ data.tar.gz: cc26ce9baac650712d18ea4cf4d94a3def8b14593b31956f50b45d38276ad435e76973e43323b5ec903335b78f09d0eaa4aedd5ab4eab7fec1f214a75bf41af8
data/CHANGELOG.md ADDED
@@ -0,0 +1,133 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ---
9
+
10
+ ## [1.0.1] - 2025-11-01
11
+
12
+ ### 🐛 Fixed
13
+ * Fixed a bug where using `.or_where` as the very first clause in a query chain would fail.
14
+ * Ensured `.count` and `.size` correctly respect any applied `.limit()` and `.offset()` chains.
15
+
16
+ ## [1.0.0] - 2025-10-28
17
+
18
+ This is the first stable 1.0 release! It introduces auto-loading and finalizes the presenter and relationship APIs.
19
+
20
+ ### ✨ Added
21
+ * **`Hq.load_from(directory_path)`:** A new, convenient way to auto-load all data definitions from a specified directory (e.g., `data/`).
22
+ * **`Hq.reload_from(directory_path)`:** A helper for development to reload all definitions, perfect for use with tools like `listen`.
23
+
24
+ ### 💥 Changed
25
+ * Query results (`Hq::InstanceWrapper` objects) are now fully **immutable** and **frozen** to prevent accidental mutation and improve thread-safety.
26
+ * Improved type-coercion in `.order` to more robustly handle sorting columns with mixed data types (e.g., `Integer` and `String`).
27
+
28
+ ### ⛔ Removed
29
+ * Removed the deprecated `item { ... }` block inside `Hq.define`. Please use the new `Hq.present(:model_name) { ... }` API introduced in `0.9.0`.
30
+
31
+ ## [0.9.0] - 2025-10-05
32
+
33
+ ### ✨ Added
34
+ * **New Presenter API:** Introduced `Hq.present(:model_name) { ... }` as the new, cleaner way to define presenter methods. This uses standard `def` syntax and keeps presentation logic separate from data definition.
35
+ * Instance wrappers now dynamically define accessor methods for all hash keys (e.g., `post.title`), which can be used within presenter methods. Presenter methods take precedence over key accessors.
36
+ * Added `Hq.reload` helper for hot-reloading data in development environments.
37
+
38
+ ### ⚠️ Deprecated
39
+ * The `item { ... }` block within `Hq.define` is now deprecated in favor of `Hq.present`. It will be removed in version 1.0.
40
+
41
+ ## [0.8.0] - 2025-09-15
42
+
43
+ ### ✨ Added
44
+ * **Pagination:** Added `.limit()` and `.offset()` for basic pagination.
45
+ * **Advanced Pagination:** Introduced the `.paginate(per_page: N)` method. This returns an enumerable `Hq::Page` object with helpers like `.current_page`, `.total_pages`, `.total_items`, `.next_page`, `.prev_page`, `is_first_page?`, and `is_last_page?`.
46
+
47
+ ## [0.7.0] - 2025-08-25
48
+
49
+ ### ✨ Added
50
+ * **Many-to-Many Relationships:** Added support for `has_many :through` relationships.
51
+
52
+ ### 🐛 Fixed
53
+ * `belongs_to` relationships now correctly return `nil` if the foreign key is missing or `nil`, rather than raising an error.
54
+ * `has_many` relationships now correctly work with custom `primary_key` definitions on the target model.
55
+
56
+ ## [0.6.0] - 2025-07-30
57
+
58
+ ### ✨ Added
59
+ * **Relationships:** Initial support for data relationships!
60
+ * `belongs_to`
61
+ * `has_many`
62
+ * `has_one`
63
+ * Relationships support overrides for `class_name`, `foreign_key`, `primary_key`, and `owner_key`.
64
+ * Related objects are returned as `Hq::InstanceWrapper` (`belongs_to`, `has_one`) or a new chainable `Hq::Query` (`has_many`).
65
+
66
+ ## [0.5.0] - 2025-07-10
67
+
68
+ ### ✨ Added
69
+ * **`OR` Logic:** Added `.or_where` for building `OR` queries.
70
+ * **Grouped Conditions:** Added block support to `where` and `or_where` for creating nested logical groups (e.g., `where { |q| q.where(a: 1).or_where(b: 2) }`).
71
+ * **New Operators:** Added new hash condition operators:
72
+ * `:not` (e.g., `where(published: { not: true })`)
73
+ * `:in` and `:not_in` (e.g., `where(id: { in: [1, 3, 5] })`)
74
+ * `:exists` (for non-nil values)
75
+ * `:empty` (for `nil`, `""`, or `[]`)
76
+
77
+ ## [0.4.0] - 2025-06-15
78
+
79
+ ### ✨ Added
80
+ * **Advanced `where` Operators:** `where` now supports more than just simple equality.
81
+ * `:greater_than` / `:gt`
82
+ * `:less_than` / `:lt`
83
+ * `:greater_than_or_equal` / `:gte`
84
+ * `:less_than_or_equal` / `:lte`
85
+ * `:contains` (for strings and arrays)
86
+ * `:starts_with` and `:ends_with` (for strings)
87
+ * **Ranges:** `where` now accepts a Ruby `Range` (e.g., `where(views: 100..500)`).
88
+ * **Ordering:** `.order` now accepts a second argument, `desc: true`, for descending sorts.
89
+ * **Helpers:** Added `.find_by(...)` as a shortcut for `.where(...).first`.
90
+
91
+ ### 🐛 Fixed
92
+ * `.order` now gracefully handles mixed-type comparisons (e.g., `String` and `Date`) without crashing.
93
+
94
+ ## [0.3.0] - 2025-05-20
95
+
96
+ ### ✨ Added
97
+ * **Scopes:** Added support for reusable query scopes via `scope({...})` inside the `Hq.define` block.
98
+ * Scopes can accept arguments (e.g., `scope recent: ->(n=5) { order(:created_at, desc: true).limit(n) }`).
99
+ * Scopes are chainable with `where`, `order`, and other scopes.
100
+
101
+ ## [0.2.1] - 2025-05-01
102
+
103
+ ### 🐛 Fixed
104
+ * `load` glob pattern now sorts files alphabetically before loading to ensure a predictable and consistent data order.
105
+ * `Hq.configure` now correctly resolves paths relative to the application root.
106
+
107
+ ## [0.2.0] - 2025-04-25
108
+
109
+ ### ✨ Added
110
+ * **File-Based Data:** Added `load 'path/to/*.rb'` loader. Data can now be loaded from individual Ruby files that return a hash.
111
+ * Added `Hq.configure(data_path: '...')` to set a base directory for data files.
112
+ * Added `Hq.defined_models` to inspect which models have been registered.
113
+
114
+ ### 💥 Changed
115
+ * `Hq.define` is now lazy. Data from files is not loaded into memory until the first query is performed on that model.
116
+
117
+ ## [0.1.1] - 2025-04-12
118
+
119
+ ### 🐛 Fixed
120
+ * Fixed a `NoMethodError` when using `.order` on a key where some records had a `nil` value. Nils are now always sorted last by default.
121
+ * `hq(:model).first` on an empty dataset now correctly returns `nil` instead of raising an error.
122
+
123
+ ## [0.1.0] - 2025-04-10
124
+
125
+ ### ✨ Added
126
+ * **Initial Release!**
127
+ * `Hq.define(:model_name)` block.
128
+ * `from_array([...])` data source.
129
+ * Global `hq()` helper for easy querying.
130
+ * Basic `.where(key: value)` for exact matching.
131
+ * `.order(:key)` for ascending sort.
132
+ * Query execution methods: `.to_a`, `.first`, `.last`, `.each`.
133
+ * Results are wrapped in `Hq::InstanceWrapper` for hash-like access (`record[:key]`).
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 activestylus
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.