lite-query 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.fasterer.yml +19 -0
- data/.gitignore +11 -0
- data/.rspec +4 -0
- data/.rubocop.yml +32 -0
- data/.travis.yml +24 -0
- data/CHANGELOG.md +11 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +131 -0
- data/LICENSE.txt +21 -0
- data/README.md +101 -0
- data/Rakefile +8 -0
- data/_config.yml +1 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/generators/lite/query/install_generator.rb +17 -0
- data/lib/generators/lite/query/templates/install.rb +4 -0
- data/lib/generators/rails/USAGE +8 -0
- data/lib/generators/rails/query_generator.rb +28 -0
- data/lib/generators/rails/templates/query.rb.tt +4 -0
- data/lib/generators/rspec/query_generator.rb +28 -0
- data/lib/generators/rspec/templates/query_spec.rb.tt +5 -0
- data/lib/generators/test_unit/query_generator.rb +29 -0
- data/lib/generators/test_unit/templates/query_test.rb.tt +9 -0
- data/lib/lite/query/base.rb +38 -0
- data/lib/lite/query/exceptions.rb +7 -0
- data/lib/lite/query/version.rb +9 -0
- data/lib/lite/query.rb +11 -0
- data/lite-query.gemspec +51 -0
- metadata +226 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e787fda8231f0dbe267c758fb1da312e415ae83a80f77d6a9a7083bc144b8cb0
|
4
|
+
data.tar.gz: e9abc471342a9c5c903a42060a6907cdd093691c0d84c2f2acf0529c283ee31b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 65fb72db1ec538595da11494e6b98a7b89c7328104de1c3ab166ef9134ce062c9172f26e6831096ed6b800190cd6f854c7807bdf48bf60a3aa9ef74ac38ba8f7
|
7
|
+
data.tar.gz: acdfac248ce160b37b6526edc1554d8f69b81066407e319faaa47d0e45bce7b066c19ef94bede71054bdbf1bda65863299fc8ba5eb949198e271dd3fd423c561
|
data/.fasterer.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
speedups:
|
2
|
+
block_vs_symbol_to_proc: true
|
3
|
+
each_with_index_vs_while: false
|
4
|
+
fetch_with_argument_vs_block: true
|
5
|
+
for_loop_vs_each: true
|
6
|
+
getter_vs_attr_reader: true
|
7
|
+
gsub_vs_tr: true
|
8
|
+
hash_merge_bang_vs_hash_brackets: true
|
9
|
+
keys_each_vs_each_key: true
|
10
|
+
map_flatten_vs_flat_map: true
|
11
|
+
module_eval: true
|
12
|
+
proc_call_vs_yield: true
|
13
|
+
rescue_vs_respond_to: true
|
14
|
+
reverse_each_vs_reverse_each: true
|
15
|
+
select_first_vs_detect: true
|
16
|
+
select_last_vs_reverse_detect: true
|
17
|
+
setter_vs_attr_writer: true
|
18
|
+
shuffle_first_vs_sample: true
|
19
|
+
sort_vs_sort_by: true
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rspec
|
4
|
+
AllCops:
|
5
|
+
TargetRubyVersion: 2.6
|
6
|
+
DisplayCopNames: true
|
7
|
+
DisplayStyleGuide: true
|
8
|
+
LineLength:
|
9
|
+
Max: 100
|
10
|
+
Layout/EmptyLinesAroundBlockBody:
|
11
|
+
Exclude:
|
12
|
+
- 'spec/**/**/*'
|
13
|
+
Layout/EmptyLinesAroundClassBody:
|
14
|
+
EnforcedStyle: empty_lines_except_namespace
|
15
|
+
Layout/EmptyLinesAroundModuleBody:
|
16
|
+
EnforcedStyle: empty_lines_except_namespace
|
17
|
+
Metrics/BlockLength:
|
18
|
+
Exclude:
|
19
|
+
- 'spec/**/**/*'
|
20
|
+
- '*.gemspec'
|
21
|
+
Naming/MemoizedInstanceVariableName:
|
22
|
+
Enabled: false
|
23
|
+
RSpec/ExampleLength:
|
24
|
+
Enabled: false
|
25
|
+
RSpec/FilePath:
|
26
|
+
Enabled: false
|
27
|
+
RSpec/MultipleExpectations:
|
28
|
+
Enabled: false
|
29
|
+
Style/Documentation:
|
30
|
+
Enabled: false
|
31
|
+
Style/ExpandPathArguments:
|
32
|
+
Enabled: false
|
data/.travis.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
cache: bundler
|
4
|
+
rvm:
|
5
|
+
- 2.5
|
6
|
+
- 2.6
|
7
|
+
- ruby-head
|
8
|
+
matrix:
|
9
|
+
fast_finish: true
|
10
|
+
allow_failures:
|
11
|
+
- rvm: ruby-head
|
12
|
+
before_install:
|
13
|
+
- gem update --system
|
14
|
+
- gem install bundler
|
15
|
+
install:
|
16
|
+
- bundle install --jobs=3 --retry=3
|
17
|
+
script:
|
18
|
+
- bundle exec rspec
|
19
|
+
- bundle exec rubocop
|
20
|
+
- bundle exec fasterer
|
21
|
+
notifications:
|
22
|
+
email: false
|
23
|
+
slack:
|
24
|
+
secure: Hcdz1aigAkFPa37QSLo73MxwpUbUL5nE3aCVT6AhTTMijFg4Cl8u4qiZyER1sSXQzT2CTnG8ybZbSe7ehXmWtfgEqsFZCRc8qz6XkCQENayatGpQj+sokwEoGn2HWyPs5xXBxqW3RHx95Pf1qCJehOvS2Xwz0PwxsxUz5ZhRyR2lMbImcCsocDJXnOwDFvni6sOu5C+5S+WsZQMRs/XHlAeg1SE++ej8BuwQU3fTGO306ZR/jfszB0hBzlNrgUwRBejEd5P12AdE/VZ8ZjLP7xEH/Pj/dZsYx39sncmedQ6C+MG76ziT0SrZL7sfK+r6n9yCx/9StgpYpkQ6VWQ2iCxfaKj9U4VoCcA8ysPGZx4k4l6Ri7/h1isGFXhUrGYjA1HBIfaIdUtrXHSjKrqaCNwU2HIoWFPud8njFwQy8I2NeqqUw0GWO33la0QwNtTlO4z30vMCJijSa0nFFVkU6aWDUfPscrzFOakyzD41aEkykdv0Lky9HQjbSmf5D6KjvzNTQr8Erxv+dyzbcPYH86dSN2OrVbB3TgvvN2xjFaqySbpMMRuw6DWq/xtgOuQ27gRziGUULt183VeoRFre2yFUBCLIYVXsL26NF5Ml5nxDWodJ1Wq+foiYZmbVHsq/k+H+W6PcHDUG5v368YqEk6QqaG1LUNcNkUKwABF4n+c=
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
|
9
|
+
## [1.0.0] - 2019-09-02
|
10
|
+
### Added
|
11
|
+
- Initial project version
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at j.gomez@drexed.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
lite-query (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
actionpack (6.0.0)
|
10
|
+
actionview (= 6.0.0)
|
11
|
+
activesupport (= 6.0.0)
|
12
|
+
rack (~> 2.0)
|
13
|
+
rack-test (>= 0.6.3)
|
14
|
+
rails-dom-testing (~> 2.0)
|
15
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
16
|
+
actionview (6.0.0)
|
17
|
+
activesupport (= 6.0.0)
|
18
|
+
builder (~> 3.1)
|
19
|
+
erubi (~> 1.4)
|
20
|
+
rails-dom-testing (~> 2.0)
|
21
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
22
|
+
activemodel (6.0.0)
|
23
|
+
activesupport (= 6.0.0)
|
24
|
+
activerecord (6.0.0)
|
25
|
+
activemodel (= 6.0.0)
|
26
|
+
activesupport (= 6.0.0)
|
27
|
+
activesupport (6.0.0)
|
28
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
29
|
+
i18n (>= 0.7, < 2)
|
30
|
+
minitest (~> 5.1)
|
31
|
+
tzinfo (~> 1.1)
|
32
|
+
zeitwerk (~> 2.1, >= 2.1.8)
|
33
|
+
ast (2.4.0)
|
34
|
+
builder (3.2.3)
|
35
|
+
colorize (0.8.1)
|
36
|
+
concurrent-ruby (1.1.5)
|
37
|
+
crass (1.0.4)
|
38
|
+
database_cleaner (1.7.0)
|
39
|
+
diff-lcs (1.3)
|
40
|
+
erubi (1.8.0)
|
41
|
+
fasterer (0.6.0)
|
42
|
+
colorize (~> 0.7)
|
43
|
+
ruby_parser (>= 3.13.0)
|
44
|
+
generator_spec (0.9.4)
|
45
|
+
activesupport (>= 3.0.0)
|
46
|
+
railties (>= 3.0.0)
|
47
|
+
i18n (1.6.0)
|
48
|
+
concurrent-ruby (~> 1.0)
|
49
|
+
jaro_winkler (1.5.3)
|
50
|
+
loofah (2.2.3)
|
51
|
+
crass (~> 1.0.2)
|
52
|
+
nokogiri (>= 1.5.9)
|
53
|
+
method_source (0.9.2)
|
54
|
+
mini_portile2 (2.4.0)
|
55
|
+
minitest (5.11.3)
|
56
|
+
nokogiri (1.10.4)
|
57
|
+
mini_portile2 (~> 2.4.0)
|
58
|
+
parallel (1.17.0)
|
59
|
+
parser (2.6.4.0)
|
60
|
+
ast (~> 2.4.0)
|
61
|
+
rack (2.0.7)
|
62
|
+
rack-test (1.1.0)
|
63
|
+
rack (>= 1.0, < 3)
|
64
|
+
rails-dom-testing (2.0.3)
|
65
|
+
activesupport (>= 4.2.0)
|
66
|
+
nokogiri (>= 1.6)
|
67
|
+
rails-html-sanitizer (1.2.0)
|
68
|
+
loofah (~> 2.2, >= 2.2.2)
|
69
|
+
railties (6.0.0)
|
70
|
+
actionpack (= 6.0.0)
|
71
|
+
activesupport (= 6.0.0)
|
72
|
+
method_source
|
73
|
+
rake (>= 0.8.7)
|
74
|
+
thor (>= 0.20.3, < 2.0)
|
75
|
+
rainbow (3.0.0)
|
76
|
+
rake (12.3.3)
|
77
|
+
rspec (3.8.0)
|
78
|
+
rspec-core (~> 3.8.0)
|
79
|
+
rspec-expectations (~> 3.8.0)
|
80
|
+
rspec-mocks (~> 3.8.0)
|
81
|
+
rspec-core (3.8.2)
|
82
|
+
rspec-support (~> 3.8.0)
|
83
|
+
rspec-expectations (3.8.4)
|
84
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
85
|
+
rspec-support (~> 3.8.0)
|
86
|
+
rspec-mocks (3.8.1)
|
87
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
88
|
+
rspec-support (~> 3.8.0)
|
89
|
+
rspec-support (3.8.2)
|
90
|
+
rubocop (0.74.0)
|
91
|
+
jaro_winkler (~> 1.5.1)
|
92
|
+
parallel (~> 1.10)
|
93
|
+
parser (>= 2.6)
|
94
|
+
rainbow (>= 2.2.2, < 4.0)
|
95
|
+
ruby-progressbar (~> 1.7)
|
96
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
97
|
+
rubocop-performance (1.4.1)
|
98
|
+
rubocop (>= 0.71.0)
|
99
|
+
rubocop-rspec (1.35.0)
|
100
|
+
rubocop (>= 0.60.0)
|
101
|
+
ruby-progressbar (1.10.1)
|
102
|
+
ruby_parser (3.13.1)
|
103
|
+
sexp_processor (~> 4.9)
|
104
|
+
sexp_processor (4.12.1)
|
105
|
+
sqlite3 (1.4.1)
|
106
|
+
thor (0.20.3)
|
107
|
+
thread_safe (0.3.6)
|
108
|
+
tzinfo (1.2.5)
|
109
|
+
thread_safe (~> 0.1)
|
110
|
+
unicode-display_width (1.6.0)
|
111
|
+
zeitwerk (2.1.9)
|
112
|
+
|
113
|
+
PLATFORMS
|
114
|
+
ruby
|
115
|
+
|
116
|
+
DEPENDENCIES
|
117
|
+
activerecord
|
118
|
+
bundler
|
119
|
+
database_cleaner
|
120
|
+
fasterer
|
121
|
+
generator_spec
|
122
|
+
lite-query!
|
123
|
+
rake
|
124
|
+
rspec
|
125
|
+
rubocop
|
126
|
+
rubocop-performance
|
127
|
+
rubocop-rspec
|
128
|
+
sqlite3
|
129
|
+
|
130
|
+
BUNDLED WITH
|
131
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Juan Gomez
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# Lite::Query
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/lite-query.svg)](http://badge.fury.io/rb/lite-query)
|
4
|
+
[![Build Status](https://travis-ci.org/drexed/lite-query.svg?branch=master)](https://travis-ci.org/drexed/lite-query)
|
5
|
+
|
6
|
+
Lite::Query is a library for using the query pattern to separate complex query
|
7
|
+
logic from classes such as controllers and models.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'lite-query'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install lite-query
|
24
|
+
|
25
|
+
## Table of Contents
|
26
|
+
|
27
|
+
* [Setup](#setup)
|
28
|
+
* [Usage](#usage)
|
29
|
+
|
30
|
+
## Setup
|
31
|
+
|
32
|
+
`rails g lite:query:install` will generate the following file:
|
33
|
+
`../app/queries/application_query.rb`
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
class ApplicationQuery < Lite::Query::Base
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
Use `rails g query NAME` will generate the following file: `../app/queries/[name]_query.rb`
|
41
|
+
|
42
|
+
*(This will also add available test framework files if detected)*
|
43
|
+
|
44
|
+
You will then need to fill this class with the required `execute` method
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
class AgeQuery < ApplicationQuery
|
48
|
+
|
49
|
+
# NOTE: this method is required
|
50
|
+
def execute
|
51
|
+
return relation unless args[:age]
|
52
|
+
|
53
|
+
relation.where('age > ?', args[:age])
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def default_relation
|
59
|
+
User.all
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
## Usage
|
66
|
+
|
67
|
+
There are multiple ways to access the query call:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
relation = User.limit(1)
|
71
|
+
|
72
|
+
query = AgeQuery.new(relation)
|
73
|
+
query.call
|
74
|
+
|
75
|
+
# - or -
|
76
|
+
|
77
|
+
query = AgeQuery.new(age: 10)
|
78
|
+
query.exectue
|
79
|
+
|
80
|
+
# - or -
|
81
|
+
|
82
|
+
AgeQuery.call(relation, age: 20)
|
83
|
+
```
|
84
|
+
|
85
|
+
## Development
|
86
|
+
|
87
|
+
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.
|
88
|
+
|
89
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
90
|
+
|
91
|
+
## Contributing
|
92
|
+
|
93
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/lite-query. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
94
|
+
|
95
|
+
## License
|
96
|
+
|
97
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
98
|
+
|
99
|
+
## Code of Conduct
|
100
|
+
|
101
|
+
Everyone interacting in the Lite::Query project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/lite-query/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/_config.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
theme: jekyll-theme-leap-day
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'lite/query'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
|
5
|
+
module Lite
|
6
|
+
module Query
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
8
|
+
|
9
|
+
source_root File.expand_path('../templates', __FILE__)
|
10
|
+
|
11
|
+
def copy_application_query_file
|
12
|
+
copy_file('install.rb', 'app/queries/application_query.rb')
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
|
5
|
+
module Rails
|
6
|
+
class QueryGenerator < Rails::Generators::NamedBase
|
7
|
+
|
8
|
+
source_root File.expand_path('../templates', __FILE__)
|
9
|
+
check_class_collision suffix: 'Query'
|
10
|
+
hook_for :test_framework
|
11
|
+
|
12
|
+
def create_query
|
13
|
+
path = File.join('app', 'queries', class_path, "#{file_name}_query.rb")
|
14
|
+
template('query.rb.tt', path)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def file_name
|
20
|
+
@_file_name ||= remove_possible_suffix(super)
|
21
|
+
end
|
22
|
+
|
23
|
+
def remove_possible_suffix(name)
|
24
|
+
name.sub(/_?query$/i, '')
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
|
5
|
+
module RSpec
|
6
|
+
module Generators
|
7
|
+
class QueryGenerator < Rails::Generators::NamedBase
|
8
|
+
|
9
|
+
source_root File.expand_path('../templates', __FILE__)
|
10
|
+
|
11
|
+
def create_test_file
|
12
|
+
path = File.join('spec', 'queries', class_path, "#{file_name}_query_spec.rb")
|
13
|
+
template('query_spec.rb.tt', path)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def file_name
|
19
|
+
@_file_name ||= remove_possible_suffix(super)
|
20
|
+
end
|
21
|
+
|
22
|
+
def remove_possible_suffix(name)
|
23
|
+
name.sub(/_?query$/i, '')
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
|
5
|
+
module TestUnit
|
6
|
+
module Generators
|
7
|
+
class QueryGenerator < Rails::Generators::NamedBase
|
8
|
+
|
9
|
+
source_root File.expand_path('../templates', __FILE__)
|
10
|
+
check_class_collision suffix: 'QueryTest'
|
11
|
+
|
12
|
+
def create_test_file
|
13
|
+
path = File.join('test', 'queries', class_path, "#{file_name}_query_test.rb")
|
14
|
+
template('query_test.rb.tt', path)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def file_name
|
20
|
+
@_file_name ||= remove_possible_suffix(super)
|
21
|
+
end
|
22
|
+
|
23
|
+
def remove_possible_suffix(name)
|
24
|
+
name.sub(/_?query$/i, '')
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lite
|
4
|
+
module Query
|
5
|
+
class Base
|
6
|
+
|
7
|
+
attr_accessor :relation
|
8
|
+
attr_reader :args
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def call(relation = nil, **args)
|
13
|
+
klass = new(relation, args)
|
14
|
+
klass.call
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(relation = nil, **args)
|
20
|
+
@relation = relation || default_relation
|
21
|
+
@args = args
|
22
|
+
end
|
23
|
+
|
24
|
+
def call
|
25
|
+
raise Lite::Query::NotImplementedError unless defined?(execute)
|
26
|
+
|
27
|
+
execute
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def default_relation
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/lite/query.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
%w[version exceptions base].each do |name|
|
4
|
+
require "lite/query/#{name}"
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'generators/lite/query/install_generator'
|
8
|
+
|
9
|
+
%w[rails rspec test_unit].each do |name|
|
10
|
+
require "generators/#{name}/query_generator"
|
11
|
+
end
|
data/lite-query.gemspec
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'lite/query/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'lite-query'
|
9
|
+
spec.version = Lite::Query::VERSION
|
10
|
+
spec.authors = ['Juan Gomez']
|
11
|
+
spec.email = %w[j.gomez@drexed.com]
|
12
|
+
|
13
|
+
spec.summary = 'Ruby Query based framework (aka query objects)'
|
14
|
+
spec.homepage = 'http://drexed.github.io/lite-query'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata.merge(
|
21
|
+
'allowed_push_host' => 'https://rubygems.org',
|
22
|
+
'changelog_uri' => 'https://github.com/drexed/lite-query/blob/master/CHANGELOG.md',
|
23
|
+
'homepage_uri' => spec.homepage,
|
24
|
+
'source_code_uri' => 'https://github.com/drexed/lite-query'
|
25
|
+
)
|
26
|
+
else
|
27
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
28
|
+
'public gem pushes.'
|
29
|
+
end
|
30
|
+
|
31
|
+
# Specify which files should be added to the gem when it is released.
|
32
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
33
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
34
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
35
|
+
end
|
36
|
+
spec.bindir = 'exe'
|
37
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
|
+
spec.require_paths = %w[lib]
|
39
|
+
|
40
|
+
spec.add_development_dependency 'activerecord'
|
41
|
+
spec.add_development_dependency 'bundler'
|
42
|
+
spec.add_development_dependency 'database_cleaner'
|
43
|
+
spec.add_development_dependency 'fasterer'
|
44
|
+
spec.add_development_dependency 'generator_spec'
|
45
|
+
spec.add_development_dependency 'rake'
|
46
|
+
spec.add_development_dependency 'rspec'
|
47
|
+
spec.add_development_dependency 'rubocop'
|
48
|
+
spec.add_development_dependency 'rubocop-performance'
|
49
|
+
spec.add_development_dependency 'rubocop-rspec'
|
50
|
+
spec.add_development_dependency 'sqlite3'
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,226 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lite-query
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Juan Gomez
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-09-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: database_cleaner
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fasterer
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: generator_spec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop-performance
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop-rspec
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: sqlite3
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
description:
|
168
|
+
email:
|
169
|
+
- j.gomez@drexed.com
|
170
|
+
executables: []
|
171
|
+
extensions: []
|
172
|
+
extra_rdoc_files: []
|
173
|
+
files:
|
174
|
+
- ".fasterer.yml"
|
175
|
+
- ".gitignore"
|
176
|
+
- ".rspec"
|
177
|
+
- ".rubocop.yml"
|
178
|
+
- ".travis.yml"
|
179
|
+
- CHANGELOG.md
|
180
|
+
- CODE_OF_CONDUCT.md
|
181
|
+
- Gemfile
|
182
|
+
- Gemfile.lock
|
183
|
+
- LICENSE.txt
|
184
|
+
- README.md
|
185
|
+
- Rakefile
|
186
|
+
- _config.yml
|
187
|
+
- bin/console
|
188
|
+
- bin/setup
|
189
|
+
- lib/generators/lite/query/install_generator.rb
|
190
|
+
- lib/generators/lite/query/templates/install.rb
|
191
|
+
- lib/generators/rails/USAGE
|
192
|
+
- lib/generators/rails/query_generator.rb
|
193
|
+
- lib/generators/rails/templates/query.rb.tt
|
194
|
+
- lib/generators/rspec/query_generator.rb
|
195
|
+
- lib/generators/rspec/templates/query_spec.rb.tt
|
196
|
+
- lib/generators/test_unit/query_generator.rb
|
197
|
+
- lib/generators/test_unit/templates/query_test.rb.tt
|
198
|
+
- lib/lite/query.rb
|
199
|
+
- lib/lite/query/base.rb
|
200
|
+
- lib/lite/query/exceptions.rb
|
201
|
+
- lib/lite/query/version.rb
|
202
|
+
- lite-query.gemspec
|
203
|
+
homepage: http://drexed.github.io/lite-query
|
204
|
+
licenses:
|
205
|
+
- MIT
|
206
|
+
metadata: {}
|
207
|
+
post_install_message:
|
208
|
+
rdoc_options: []
|
209
|
+
require_paths:
|
210
|
+
- lib
|
211
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ">="
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
217
|
+
requirements:
|
218
|
+
- - ">="
|
219
|
+
- !ruby/object:Gem::Version
|
220
|
+
version: '0'
|
221
|
+
requirements: []
|
222
|
+
rubygems_version: 3.0.4
|
223
|
+
signing_key:
|
224
|
+
specification_version: 4
|
225
|
+
summary: Ruby Query based framework (aka query objects)
|
226
|
+
test_files: []
|