interage-query 0.1.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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +4 -0
- data/.rubocop.yml +22 -0
- data/.travis.yml +7 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +80 -0
- data/README.md +40 -0
- data/Rakefile +8 -0
- data/bin/brakeman +29 -0
- data/bin/bundle +105 -0
- data/bin/ci +12 -0
- data/bin/console +14 -0
- data/bin/rspec +29 -0
- data/bin/rubocop +29 -0
- data/bin/setup +8 -0
- data/interage-query.gemspec +41 -0
- data/lib/generators/interage/query/create/USAGE +8 -0
- data/lib/generators/interage/query/create/create_generator.rb +34 -0
- data/lib/generators/interage/query/create/templates/sample_query.rb +7 -0
- data/lib/generators/interage/query/install/USAGE +8 -0
- data/lib/generators/interage/query/install/install_generator.rb +21 -0
- data/lib/generators/interage/query/install/templates/application_query.rb +4 -0
- data/lib/interage/application_query.rb +60 -0
- data/lib/interage/query/version.rb +7 -0
- data/lib/interage/query.rb +13 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 635408157836d195392fe9af6fc25cef12dbc9af290bf9b7e7dca2e31daba904
|
4
|
+
data.tar.gz: 58afcab84392f1a16f296859312195887f479a93cc5ad35d0d827001f3fd8f42
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 37ebb5f4e8cbab5b11a55aea7642b5aff47cd44bd2d00cf57cf5d19e84adb81679c5402443733c2f6acdecae15c8d8b02bdf3f99b1a68e1282c4729782579904
|
7
|
+
data.tar.gz: 61e710399d859b2a5e30400138d9e2899cd7dbf1508e9c7c013a66298a747c79e3dcf46287ac1671bb19fbbf48d41d6881b8f3471f64d6b75f1ab009980e9026
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rspec
|
3
|
+
- rubocop-performance
|
4
|
+
|
5
|
+
Documentation:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Style/EmptyMethod:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Style/SymbolArray:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Style/WordArray:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
AllCops:
|
18
|
+
TargetRubyVersion: 2.6
|
19
|
+
Exclude:
|
20
|
+
- bin/**/*
|
21
|
+
- vendor/**/*
|
22
|
+
- lib/generators/interage/query/*/templates/**/*.rb
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
gemspec
|
6
|
+
|
7
|
+
group :development, :test do
|
8
|
+
# https://github.com/rubocop-hq/rubocop#quickstart
|
9
|
+
gem 'rubocop', '~> 0.67.2'
|
10
|
+
# https://github.com/backus/rubocop-rspec
|
11
|
+
gem 'rubocop-rspec', '~> 1.32'
|
12
|
+
# https://github.com/rubocop-hq/rubocop-performance/#usage
|
13
|
+
gem 'rubocop-performance', '~> 1.1'
|
14
|
+
# https://github.com/rspec/rspec#install
|
15
|
+
gem 'rspec', '~> 3.8'
|
16
|
+
# https://github.com/pry/pry#installation
|
17
|
+
gem 'pry', '~> 0.12.2'
|
18
|
+
# https://github.com/presidentbeef/brakeman
|
19
|
+
gem 'brakeman', '~> 4.3', '>= 4.3.1', require: false
|
20
|
+
# https://github.com/rails/rails/tree/master/activesupport#download-and-installation
|
21
|
+
gem 'activesupport', '~> 5.2', '>= 5.2.3'
|
22
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
interage-query (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (5.2.3)
|
10
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
|
+
i18n (>= 0.7, < 2)
|
12
|
+
minitest (~> 5.1)
|
13
|
+
tzinfo (~> 1.1)
|
14
|
+
ast (2.4.0)
|
15
|
+
brakeman (4.5.0)
|
16
|
+
coderay (1.1.2)
|
17
|
+
concurrent-ruby (1.1.5)
|
18
|
+
diff-lcs (1.3)
|
19
|
+
i18n (1.6.0)
|
20
|
+
concurrent-ruby (~> 1.0)
|
21
|
+
jaro_winkler (1.5.2)
|
22
|
+
method_source (0.9.2)
|
23
|
+
minitest (5.11.3)
|
24
|
+
parallel (1.17.0)
|
25
|
+
parser (2.6.2.1)
|
26
|
+
ast (~> 2.4.0)
|
27
|
+
pry (0.12.2)
|
28
|
+
coderay (~> 1.1.0)
|
29
|
+
method_source (~> 0.9.0)
|
30
|
+
psych (3.1.0)
|
31
|
+
rainbow (3.0.0)
|
32
|
+
rake (10.5.0)
|
33
|
+
rspec (3.8.0)
|
34
|
+
rspec-core (~> 3.8.0)
|
35
|
+
rspec-expectations (~> 3.8.0)
|
36
|
+
rspec-mocks (~> 3.8.0)
|
37
|
+
rspec-core (3.8.0)
|
38
|
+
rspec-support (~> 3.8.0)
|
39
|
+
rspec-expectations (3.8.2)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.8.0)
|
42
|
+
rspec-mocks (3.8.0)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.8.0)
|
45
|
+
rspec-support (3.8.0)
|
46
|
+
rubocop (0.67.2)
|
47
|
+
jaro_winkler (~> 1.5.1)
|
48
|
+
parallel (~> 1.10)
|
49
|
+
parser (>= 2.5, != 2.5.1.1)
|
50
|
+
psych (>= 3.1.0)
|
51
|
+
rainbow (>= 2.2.2, < 4.0)
|
52
|
+
ruby-progressbar (~> 1.7)
|
53
|
+
unicode-display_width (>= 1.4.0, < 1.6)
|
54
|
+
rubocop-performance (1.1.0)
|
55
|
+
rubocop (>= 0.67.0)
|
56
|
+
rubocop-rspec (1.32.0)
|
57
|
+
rubocop (>= 0.60.0)
|
58
|
+
ruby-progressbar (1.10.0)
|
59
|
+
thread_safe (0.3.6)
|
60
|
+
tzinfo (1.2.5)
|
61
|
+
thread_safe (~> 0.1)
|
62
|
+
unicode-display_width (1.5.0)
|
63
|
+
|
64
|
+
PLATFORMS
|
65
|
+
ruby
|
66
|
+
|
67
|
+
DEPENDENCIES
|
68
|
+
activesupport (~> 5.2, >= 5.2.3)
|
69
|
+
brakeman (~> 4.3, >= 4.3.1)
|
70
|
+
bundler (~> 2.0)
|
71
|
+
interage-query!
|
72
|
+
pry (~> 0.12.2)
|
73
|
+
rake (~> 10.0)
|
74
|
+
rspec (~> 3.8)
|
75
|
+
rubocop (~> 0.67.2)
|
76
|
+
rubocop-performance (~> 1.1)
|
77
|
+
rubocop-rspec (~> 1.32)
|
78
|
+
|
79
|
+
BUNDLED WITH
|
80
|
+
2.0.1
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Interage::Query
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'interage-query', '~> 0.1'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
```bash
|
14
|
+
bundle install
|
15
|
+
```
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
```bash
|
20
|
+
gem install interage-query
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
You can use a Rails generator to create `ApplicationQuery`:
|
26
|
+
|
27
|
+
```bash
|
28
|
+
rails g interage:query:install
|
29
|
+
```
|
30
|
+
|
31
|
+
And you can use a Rails generator to create query classes:
|
32
|
+
|
33
|
+
|
34
|
+
```bash
|
35
|
+
rails g interage:query:create UsersByEmail User
|
36
|
+
```
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Bug reports and merge requests are welcome on GitLab at https://gitlab.com/[USERNAME]/interage-query.
|
data/Rakefile
ADDED
data/bin/brakeman
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'brakeman' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("brakeman", "brakeman")
|
data/bin/bundle
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'bundle' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "rubygems"
|
12
|
+
|
13
|
+
m = Module.new do
|
14
|
+
module_function
|
15
|
+
|
16
|
+
def invoked_as_script?
|
17
|
+
File.expand_path($0) == File.expand_path(__FILE__)
|
18
|
+
end
|
19
|
+
|
20
|
+
def env_var_version
|
21
|
+
ENV["BUNDLER_VERSION"]
|
22
|
+
end
|
23
|
+
|
24
|
+
def cli_arg_version
|
25
|
+
return unless invoked_as_script? # don't want to hijack other binstubs
|
26
|
+
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
|
27
|
+
bundler_version = nil
|
28
|
+
update_index = nil
|
29
|
+
ARGV.each_with_index do |a, i|
|
30
|
+
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
|
31
|
+
bundler_version = a
|
32
|
+
end
|
33
|
+
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
|
34
|
+
bundler_version = $1 || ">= 0.a"
|
35
|
+
update_index = i
|
36
|
+
end
|
37
|
+
bundler_version
|
38
|
+
end
|
39
|
+
|
40
|
+
def gemfile
|
41
|
+
gemfile = ENV["BUNDLE_GEMFILE"]
|
42
|
+
return gemfile if gemfile && !gemfile.empty?
|
43
|
+
|
44
|
+
File.expand_path("../../Gemfile", __FILE__)
|
45
|
+
end
|
46
|
+
|
47
|
+
def lockfile
|
48
|
+
lockfile =
|
49
|
+
case File.basename(gemfile)
|
50
|
+
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
|
51
|
+
else "#{gemfile}.lock"
|
52
|
+
end
|
53
|
+
File.expand_path(lockfile)
|
54
|
+
end
|
55
|
+
|
56
|
+
def lockfile_version
|
57
|
+
return unless File.file?(lockfile)
|
58
|
+
lockfile_contents = File.read(lockfile)
|
59
|
+
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
|
60
|
+
Regexp.last_match(1)
|
61
|
+
end
|
62
|
+
|
63
|
+
def bundler_version
|
64
|
+
@bundler_version ||= begin
|
65
|
+
env_var_version || cli_arg_version ||
|
66
|
+
lockfile_version || "#{Gem::Requirement.default}.a"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def load_bundler!
|
71
|
+
ENV["BUNDLE_GEMFILE"] ||= gemfile
|
72
|
+
|
73
|
+
# must dup string for RG < 1.8 compatibility
|
74
|
+
activate_bundler(bundler_version.dup)
|
75
|
+
end
|
76
|
+
|
77
|
+
def activate_bundler(bundler_version)
|
78
|
+
if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
|
79
|
+
bundler_version = "< 2"
|
80
|
+
end
|
81
|
+
gem_error = activation_error_handling do
|
82
|
+
gem "bundler", bundler_version
|
83
|
+
end
|
84
|
+
return if gem_error.nil?
|
85
|
+
require_error = activation_error_handling do
|
86
|
+
require "bundler/version"
|
87
|
+
end
|
88
|
+
return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
|
89
|
+
warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
|
90
|
+
exit 42
|
91
|
+
end
|
92
|
+
|
93
|
+
def activation_error_handling
|
94
|
+
yield
|
95
|
+
nil
|
96
|
+
rescue StandardError, LoadError => e
|
97
|
+
e
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
m.load_bundler!
|
102
|
+
|
103
|
+
if m.invoked_as_script?
|
104
|
+
load Gem.bin_path("bundler", "bundle")
|
105
|
+
end
|
data/bin/ci
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "interage/query"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/rspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/rubocop
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rubocop' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rubocop", "rubocop")
|
data/bin/setup
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'interage/query/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'interage-query'
|
9
|
+
spec.version = Interage::Query::VERSION
|
10
|
+
spec.authors = ['Walmir Neto']
|
11
|
+
spec.email = ['owalmirneto@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Application Query for Interage'
|
14
|
+
spec.description = 'Classes to encapsulate queries'
|
15
|
+
spec.homepage = 'https://gitlab.com/interage/patterns/query'
|
16
|
+
spec.licenses = ['MIT']
|
17
|
+
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
20
|
+
|
21
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
22
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
23
|
+
spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGES"
|
24
|
+
else
|
25
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
26
|
+
'public gem pushes.'
|
27
|
+
end
|
28
|
+
|
29
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
30
|
+
`git ls-files -z`.split("\x0").reject do |file|
|
31
|
+
file.match(%r{^(test|spec|features)/}) || file.split('.').last == 'gem'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
spec.bindir = 'exe'
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
+
spec.require_paths = ['lib']
|
37
|
+
|
38
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
39
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
40
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
41
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Interage
|
4
|
+
module Query
|
5
|
+
module Generators
|
6
|
+
class CreateGenerator < Rails::Generators::NamedBase
|
7
|
+
source_root File.expand_path('templates', __dir__)
|
8
|
+
|
9
|
+
desc 'Generates a query.'
|
10
|
+
|
11
|
+
def initialize(args, *_options)
|
12
|
+
super
|
13
|
+
|
14
|
+
@query_name = args[0].camelize
|
15
|
+
@model_name = args[1].camelize
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_query
|
19
|
+
create_file Rails.root.join("app/queries/#{file_name}_query.rb"),
|
20
|
+
sample_file.gsub('{{QUERY_NAME}}', query_name)
|
21
|
+
.gsub('{{MODEL_NAME}}', model_name)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :query_name, :model_name
|
27
|
+
|
28
|
+
def sample_file
|
29
|
+
File.read(File.expand_path('templates/sample_query.rb', __dir__))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Interage
|
4
|
+
module Query
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
7
|
+
|
8
|
+
desc 'Generates a application query.'
|
9
|
+
|
10
|
+
def create_application_query
|
11
|
+
copy_file 'application_query.rb', application_query_path
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def application_query_path
|
17
|
+
Rails.root.join('app/queries/application_query.rb')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Interage
|
4
|
+
class ApplicationQuery
|
5
|
+
PER_PAGE = 50
|
6
|
+
|
7
|
+
delegate :first, :find_by, :last, :count, :any?, to: :relation
|
8
|
+
|
9
|
+
def all
|
10
|
+
includes.relation
|
11
|
+
end
|
12
|
+
|
13
|
+
def build(attributes = {})
|
14
|
+
all.new(attributes)
|
15
|
+
end
|
16
|
+
|
17
|
+
def find(id)
|
18
|
+
relation.find_by(id: id)
|
19
|
+
end
|
20
|
+
|
21
|
+
def paginate(page = 1)
|
22
|
+
all.page(page).per(PER_PAGE)
|
23
|
+
end
|
24
|
+
|
25
|
+
def by_id(id)
|
26
|
+
@relation = relation.where(id: id) if id.present?
|
27
|
+
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def search_ilike_for(colums, term)
|
32
|
+
return self unless term
|
33
|
+
|
34
|
+
params = { t: "%#{term.to_s.downcase}%" }
|
35
|
+
colums = colums.map { |colum| "unaccent(#{colum}) ILIKE unaccent(:t)" }
|
36
|
+
@relation = relation.where(colums.join(' OR '), params)
|
37
|
+
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def between_dates(column, start_date, finish_date = nil)
|
42
|
+
start_date = Time.current if start_date.blank?
|
43
|
+
finish_date = start_date if finish_date.blank?
|
44
|
+
range_date =
|
45
|
+
start_date.to_date.beginning_of_day..finish_date.to_date.end_of_day
|
46
|
+
|
47
|
+
@relation = relation.where(column => range_date)
|
48
|
+
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def includes
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
56
|
+
protected
|
57
|
+
|
58
|
+
attr_accessor :relation
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'interage/query/version'
|
4
|
+
require 'active_support/core_ext/module'
|
5
|
+
|
6
|
+
module Interage
|
7
|
+
module Query
|
8
|
+
class Error < StandardError
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
autoload :ApplicationQuery, 'interage/application_query'
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: interage-query
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Walmir Neto
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Classes to encapsulate queries
|
56
|
+
email:
|
57
|
+
- owalmirneto@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".rubocop.yml"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/brakeman
|
71
|
+
- bin/bundle
|
72
|
+
- bin/ci
|
73
|
+
- bin/console
|
74
|
+
- bin/rspec
|
75
|
+
- bin/rubocop
|
76
|
+
- bin/setup
|
77
|
+
- interage-query.gemspec
|
78
|
+
- lib/generators/interage/query/create/USAGE
|
79
|
+
- lib/generators/interage/query/create/create_generator.rb
|
80
|
+
- lib/generators/interage/query/create/templates/sample_query.rb
|
81
|
+
- lib/generators/interage/query/install/USAGE
|
82
|
+
- lib/generators/interage/query/install/install_generator.rb
|
83
|
+
- lib/generators/interage/query/install/templates/application_query.rb
|
84
|
+
- lib/interage/application_query.rb
|
85
|
+
- lib/interage/query.rb
|
86
|
+
- lib/interage/query/version.rb
|
87
|
+
homepage: https://gitlab.com/interage/patterns/query
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata:
|
91
|
+
allowed_push_host: https://rubygems.org
|
92
|
+
homepage_uri: https://gitlab.com/interage/patterns/query
|
93
|
+
source_code_uri: https://gitlab.com/interage/patterns/query
|
94
|
+
changelog_uri: https://gitlab.com/interage/patterns/query/blob/master/CHANGES
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubygems_version: 3.0.1
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Application Query for Interage
|
114
|
+
test_files: []
|