Skip to content

Commit 321c4d4

Browse files
committed
Add README
1 parent b356124 commit 321c4d4

File tree

1 file changed

+94
-19
lines changed

1 file changed

+94
-19
lines changed

README.md

+94-19
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,114 @@
11
# Gyros
22

3-
TODO: Delete this and the text below, and describe your gem
4-
5-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gyros`. To experiment with that code, run `bin/console` for an interactive prompt.
3+
Gyros is a Ruby library designed to simplify data handling, specifically focusing on streamlining data filtering processes. This library provides an intuitive way to manage and query data efficiently.
64

75
## Installation
86

9-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
7+
Add this line to your application's Gemfile:
108

11-
Install the gem and add to the application's Gemfile by executing:
9+
```ruby
10+
gem 'gyros'
11+
```
1212

13-
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
13+
And then execute:
1414

15-
If bundler is not being used to manage dependencies, install the gem by executing:
15+
```bash
16+
bundle install
17+
```
1618

17-
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
19+
Or install it yourself as:
1820

19-
## Usage
21+
```bash
22+
gem install gyros
23+
```
2024

21-
TODO: Write usage instructions here
2225

23-
## Development
26+
## Features
2427

25-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28+
- **Scope Management:** Gyros allows for the comprehensive management of scopes, enabling you to define and apply different data scopes based on your requirements.
2629

27-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30+
- **Dynamic Filtering:** The library provides the ability to create dynamic filters that can adjust based on the parameters passed, facilitating a more flexible data querying experience.
2831

29-
## Contributing
32+
- **Sorting Capabilities:** With Gyros, you have the control to define sorting logic, ensuring that your data is presented in the order you need.
3033

31-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gyros. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/gyros/blob/master/CODE_OF_CONDUCT.md).
34+
- **Use of Modifiers:** Enhance your queries with modifiers, allowing for additional customization and refinement of the returned data sets.
3235

33-
## License
36+
- **Code Organization with Collections:** Gyros supports the organization of your code through the use of different collections, enabling a cleaner and more modular approach to data handling.
3437

35-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
38+
## Usage
39+
40+
Define base class:
41+
42+
```ruby
43+
class BaseRepository < Gyros::Base
44+
def list(params = {})
45+
apply_with_scope(:list, params)
46+
end
47+
48+
def show!(id, params = {})
49+
apply_with_scope(:show, params).find(id)
50+
end
51+
end
52+
```
53+
54+
Desribe your repository:
55+
56+
```ruby
57+
class UserRepository < BaseRepository
58+
model { User.all }
59+
60+
collection :default do
61+
# Define default conditions for all queries in collection
62+
default_scope do
63+
where(deleted_at: nil)
64+
end
65+
66+
modifier :visible do |user|
67+
if user.admin?
68+
self
69+
else
70+
user.where.not(role: 'admin')
71+
end
72+
end
73+
74+
scope_for(:show) do
75+
# Apply something for the show query
76+
end
77+
78+
scope_for(:list) do
79+
# Apply something for the list query
80+
end
81+
82+
# Define sortable fields
83+
%i[id name email created_at updated_at].each do |key|
84+
order_by(key) do |_column, dir|
85+
order(key => dir)
86+
end
87+
end
88+
89+
# Define filters
90+
filter :email do |email|
91+
where('email ILIKE ?', "%#{email}%")
92+
end
93+
94+
filter :created_from do |from|
95+
where('created_at >= ?', from)
96+
end
97+
98+
filter :created_to do |to|
99+
where('created_at <= ?', to)
100+
end
101+
end
102+
end
103+
```
104+
105+
Use it:
106+
107+
```ruby
108+
repository = UserRepository.new(:default).visible(current_user)
109+
repository.list(email: '@example.com', created_from: 1.year.ago, created_to: Time.now, sort: 'created_at', dir: :desc)
110+
```
36111

37-
## Code of Conduct
112+
## License
38113

39-
Everyone interacting in the Gyros project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/gyros/blob/master/CODE_OF_CONDUCT.md).
114+
The gem is available as open source under the terms of the MIT License.

0 commit comments

Comments
 (0)