yaqb 0.1.1 → 0.2.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 +4 -4
- data/lib/yaqb/{query_builder.rb → base.rb} +12 -3
- data/lib/yaqb/hooks.rb +2 -15
- data/lib/yaqb/presenter.rb +20 -0
- data/lib/yaqb/query_builders/filter.rb +5 -4
- data/lib/yaqb/query_builders/query_orchestrator.rb +3 -3
- data/lib/yaqb/version.rb +1 -1
- data/lib/yaqb.rb +3 -1
- data/yaqb.gemspec +0 -1
- metadata +4 -18
- data/lib/yaqb/railtie.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a04bf5ad9bfc9480751951e4ff8d5130c63720fada33e09012d9204ac5a3082e
|
4
|
+
data.tar.gz: 3cbe75005b7df8d27bb0569db90dfc05377c59266bd137959a97281a0c944a7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b1095d0e8d279e3d6d3ff7526ad3b92621676edfc43642e141b9275ef9aae43ec65b4f350da5e0c5b5c06fc9f51b362091f80366e92375dbeb838e4066271d6
|
7
|
+
data.tar.gz: 7cc7b2b5c26915c326da053903d129c55daca8575df356c836ca3703224d57c3995a3f4b6f7a73948e214d3524e115e0b8e7fb6c4d6204e81bfd03ae8320a412
|
@@ -3,11 +3,20 @@
|
|
3
3
|
require 'yaqb/query_builders/query_orchestrator'
|
4
4
|
|
5
5
|
module Yaqb
|
6
|
-
module
|
6
|
+
module Base
|
7
|
+
def self.included(base)
|
8
|
+
base.extend ClassMethods
|
9
|
+
base.class_eval do
|
10
|
+
rescue_from Yaqb::Errors::QueryBuilderError, with: :builder_error
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods; end
|
15
|
+
|
7
16
|
private
|
8
17
|
|
9
|
-
def orchestrate(scope,
|
10
|
-
QueryBuilders::QueryOrchestrator.new(scope, params, request, response,
|
18
|
+
def orchestrate(scope, presenter)
|
19
|
+
QueryBuilders::QueryOrchestrator.new(scope, params, request, response, presenter).call
|
11
20
|
end
|
12
21
|
|
13
22
|
def builder_error(error)
|
data/lib/yaqb/hooks.rb
CHANGED
@@ -3,22 +3,9 @@
|
|
3
3
|
begin; require 'kaminari'; rescue LoadError; end
|
4
4
|
|
5
5
|
unless defined?(Kaminari)
|
6
|
-
Kernel.warn <<~HEREDOC
|
6
|
+
Kernel.warn <<~HEREDOC
|
7
7
|
Warning: Yaqb relies on Kaminari. Please
|
8
8
|
install dependency by adding the following to your Gemfile:
|
9
|
-
gem 'kaminari'
|
9
|
+
gem 'kaminari'\n
|
10
10
|
HEREDOC
|
11
11
|
end
|
12
|
-
|
13
|
-
|
14
|
-
if defined?(ActionController::Base)
|
15
|
-
require 'yaqb/query_builder'
|
16
|
-
ActionController::Base.send(:include, Yaqb::QueryBuilder)
|
17
|
-
ActionController::Base.rescue_from Yaqb::Errors::QueryBuilderError, with: :builder_error
|
18
|
-
end
|
19
|
-
|
20
|
-
if defined?(ActionController::API)
|
21
|
-
require 'yaqb/query_builder'
|
22
|
-
ActionController::API.send(:include, Yaqb::QueryBuilder)
|
23
|
-
ActionController::API.rescue_from Yaqb::Errors::QueryBuilderError, with: :builder_error
|
24
|
-
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yaqb
|
4
|
+
class Presenter
|
5
|
+
@sort_attributes = []
|
6
|
+
@filter_attributes = []
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_accessor :sort_attributes, :filter_attributes
|
10
|
+
|
11
|
+
def sort_by(*args)
|
12
|
+
@sort_attributes = args.map(&:to_s)
|
13
|
+
end
|
14
|
+
|
15
|
+
def filter_by(*args)
|
16
|
+
@filter_attributes = args.map(&:to_s)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -5,10 +5,10 @@ module Yaqb
|
|
5
5
|
class Filter
|
6
6
|
PREDICATES = %w[eq cont notcont start end gt lt].freeze
|
7
7
|
|
8
|
-
def initialize(scope, params,
|
8
|
+
def initialize(scope, params, presenter)
|
9
9
|
@scope = scope
|
10
10
|
@filters = params['q'] || {}
|
11
|
-
@
|
11
|
+
@presenter = presenter
|
12
12
|
end
|
13
13
|
|
14
14
|
def filter
|
@@ -68,7 +68,8 @@ module Yaqb
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def validate_filters
|
71
|
-
attributes = @
|
71
|
+
attributes = @presenter.filter_attributes
|
72
|
+
|
72
73
|
@filters.each do |key, data|
|
73
74
|
error!(key, data) unless attributes.include?(data[:column])
|
74
75
|
error!(key, data) unless PREDICATES.include?(data[:predicate])
|
@@ -76,7 +77,7 @@ module Yaqb
|
|
76
77
|
end
|
77
78
|
|
78
79
|
def error!(key, data)
|
79
|
-
columns = @
|
80
|
+
columns = @presenter.filter_attributes.join(', ')
|
80
81
|
pred = PREDICATES.join(', ')
|
81
82
|
|
82
83
|
raise Errors::QueryBuilderError.new("q[#{key}]=#{data[:value]}"),
|
@@ -7,12 +7,12 @@ require 'yaqb/query_builders/filter'
|
|
7
7
|
module Yaqb
|
8
8
|
module QueryBuilders
|
9
9
|
class QueryOrchestrator
|
10
|
-
def initialize(scope, params, request, response,
|
10
|
+
def initialize(scope, params, request, response, presenter)
|
11
11
|
@scope = scope
|
12
12
|
@params = params
|
13
13
|
@request = request
|
14
14
|
@response = response
|
15
|
-
@
|
15
|
+
@presenter = presenter
|
16
16
|
end
|
17
17
|
|
18
18
|
def call
|
@@ -37,7 +37,7 @@ module Yaqb
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def filter
|
40
|
-
Filter.new(@scope, @params.to_unsafe_hash, @
|
40
|
+
Filter.new(@scope, @params.to_unsafe_hash, @presenter).filter
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
data/lib/yaqb/version.rb
CHANGED
data/lib/yaqb.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'yaqb/version'
|
4
|
+
require 'yaqb/hooks'
|
4
5
|
require 'yaqb/configuration'
|
6
|
+
require 'yaqb/presenter'
|
7
|
+
require 'yaqb/base'
|
5
8
|
require 'yaqb/errors/query_builder_error'
|
6
|
-
require 'yaqb/railtie'
|
7
9
|
|
8
10
|
module Yaqb
|
9
11
|
class << self
|
data/yaqb.gemspec
CHANGED
@@ -31,7 +31,6 @@ Gem::Specification.new do |spec|
|
|
31
31
|
|
32
32
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
33
33
|
spec.add_development_dependency 'pry'
|
34
|
-
spec.add_development_dependency 'railties', '>= 4.2.0'
|
35
34
|
spec.add_development_dependency 'rake', '~> 12.3.0'
|
36
35
|
spec.add_development_dependency 'rspec', '~> 3.8.0'
|
37
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaqb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ronald Chacon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: railties
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 4.2.0
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 4.2.0
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rake
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,15 +85,15 @@ files:
|
|
99
85
|
- bin/console
|
100
86
|
- bin/setup
|
101
87
|
- lib/yaqb.rb
|
88
|
+
- lib/yaqb/base.rb
|
102
89
|
- lib/yaqb/configuration.rb
|
103
90
|
- lib/yaqb/errors/query_builder_error.rb
|
104
91
|
- lib/yaqb/hooks.rb
|
105
|
-
- lib/yaqb/
|
92
|
+
- lib/yaqb/presenter.rb
|
106
93
|
- lib/yaqb/query_builders/filter.rb
|
107
94
|
- lib/yaqb/query_builders/paginate.rb
|
108
95
|
- lib/yaqb/query_builders/query_orchestrator.rb
|
109
96
|
- lib/yaqb/query_builders/sort.rb
|
110
|
-
- lib/yaqb/railtie.rb
|
111
97
|
- lib/yaqb/version.rb
|
112
98
|
- yaqb.gemspec
|
113
99
|
homepage: https://github.com/ronaldchacon/yaqb
|