insights-api-common 5.0.1 → 5.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b34faa7ec7e3811b6988b38141876b844872b64f153715b667049cd6eeabf02
4
- data.tar.gz: ffd22592c2cc7c8972fea54d6e7e26a483caebeaaeab263c879c3c8b03f1c4cc
3
+ metadata.gz: 2aa2430e936c484f6b54cbcc8587462ab0ace760f6a2ab7a295e02258953a932
4
+ data.tar.gz: a41b5a30792c05b38b48df621f60ced0aa098b49fc6c1dbf3282d36bfbb5830c
5
5
  SHA512:
6
- metadata.gz: 7f12c007eb09dd2f2764cf7fd43199fc8603e967fd623570fc2002276453fb44be0ee03cf6b5ce8de4b7a227106695acf9ac0902aa3761f755df11e45836c6b9
7
- data.tar.gz: 7d62e8db35cbe0b4adbbd63ecde081dab1bd1eeb1262fabbb84b9967366e35b3b01667a7aa27cb4a2953a4dc708693dd7b1754588682afe7e4d002ebc25901b2
6
+ metadata.gz: 48d2cff3476fa94a453cdb247c2a452a6197729f531361ac093e76c03530777f22a097487b1a0f4bcc6e733cad32f7425764d976ddc2a72d2edb1efe84e15eb8
7
+ data.tar.gz: da7a2598ce95a1769f028a26461436a5962aa2455605dbf4ac7fd23a5c86d7ca0aaaa2eb68e20e423286a5d2e8cc812892cf94fc26b6200acac2d1cd94e636c3
data/README.md CHANGED
@@ -30,6 +30,7 @@ Or install it yourself as:
30
30
  | Supported Comparators | Comparator |
31
31
  | --------------------- | ---------- |
32
32
  | Integer | eq |
33
+ | | not_eq |
33
34
  | | gt |
34
35
  | | gte |
35
36
  | | lt |
@@ -37,12 +38,14 @@ Or install it yourself as:
37
38
  | | nil |
38
39
  | | not_nil |
39
40
  | String | eq |
41
+ | | not_eq |
40
42
  | | contains |
41
43
  | | starts_with |
42
44
  | | ends_with |
43
45
  | | nil |
44
46
  | | not_nil |
45
47
  | String (case insensitive) | eq_i |
48
+ | | not_eq_i |
46
49
  | | contains_i |
47
50
  | | starts_with_i |
48
51
  | | ends_with_i |
@@ -53,6 +56,7 @@ After implementing filtering in your application, this is the way to filter via
53
56
  | --------------- | --------------------- | ----------------- |
54
57
  | "?filter[name]=reviews" | { :filter => { :name => "reviews" } } | filter: { name: "reviews" } |
55
58
  | "?filter[name][eq]=reviews" | { :filter => { :name => { :eq => "reviews" } } } | filter: { name: { eq: "reviews" } } |
59
+ | "?filter[name][not_eq]=reviews" | { :filter => { :name => { :not_eq => "reviews" } } } | filter: { name: { not_eq: "reviews" } } |
56
60
  | "?filter[name][starts_with]=a" | { :filter => { :name => { :starts_with => "a" } } } | filter: { name: { starts_with: "a" } } |
57
61
  | "?filter[name][ends_with]=manager" | { :filter => { :name => { :ends_with => "manager" } } } | filter: { name: { ends_with: "manager" } } |
58
62
  | "?filter[name][contains]=openshift" | { :filter => { :name => { :contains => "openshift" } } } | filter: { name: { contains: "openshift" } } |
@@ -2,8 +2,8 @@ module Insights
2
2
  module API
3
3
  module Common
4
4
  class Filter
5
- INTEGER_COMPARISON_KEYWORDS = ["eq", "gt", "gte", "lt", "lte", "nil", "not_nil"].freeze
6
- STRING_COMPARISON_KEYWORDS = ["contains", "contains_i", "eq", "eq_i", "starts_with", "starts_with_i", "ends_with", "ends_with_i", "nil", "not_nil"].freeze
5
+ INTEGER_COMPARISON_KEYWORDS = ["eq", "not_eq", "gt", "gte", "lt", "lte", "nil", "not_nil"].freeze
6
+ STRING_COMPARISON_KEYWORDS = ["contains", "contains_i", "eq", "not_eq", "eq_i", "not_eq_i", "starts_with", "starts_with_i", "ends_with", "ends_with_i", "nil", "not_nil"].freeze
7
7
  ALL_COMPARISON_KEYWORDS = (INTEGER_COMPARISON_KEYWORDS + STRING_COMPARISON_KEYWORDS).uniq.freeze
8
8
 
9
9
  attr_reader :apply, :arel_table, :api_doc_definition, :extra_filterable_attributes, :model
@@ -242,6 +242,16 @@ module Insights
242
242
  self.query = query.where(model_arel_attribute(key).eq_any(Array(value)))
243
243
  end
244
244
 
245
+ def comparator_not_eq(key, value)
246
+ self.query = query.where.not(model_arel_attribute(key).eq_any(Array(value)))
247
+ end
248
+
249
+ def comparator_not_eq_i(key, value)
250
+ values = Array(value).map { |v| query.sanitize_sql_like(v.downcase) }
251
+
252
+ self.query = query.where.not(model_arel_table(key).grouping(arel_lower(key).matches_any(values)))
253
+ end
254
+
245
255
  def comparator_eq_i(key, value)
246
256
  values = Array(value).map { |v| query.sanitize_sql_like(v.downcase) }
247
257
 
@@ -20,8 +20,32 @@ module Insights
20
20
  openapi_path.split("/")[1..-1]
21
21
  end
22
22
 
23
+ def self.template_file_by(type, root_dir = __dir__)
24
+ Pathname.new(root_dir).join(File.expand_path("templates", root_dir), "#{type}.erb")
25
+ end
26
+
27
+ def self.root_dir
28
+ Rails.root
29
+ end
30
+
31
+ def self.app_name
32
+ Rails.application.class.parent.name.underscore
33
+ end
34
+
35
+ def self.pluggable_template_file_by(type)
36
+ templates_relative_path = "lib/#{app_name}/api/graphql/templates"
37
+ template_path = File.expand_path(templates_relative_path, root_dir)
38
+ Pathname.new(root_dir).join(template_path, "#{type}.erb")
39
+ end
40
+
41
+ def self.template_path_by(type)
42
+ template_path_pluggable = pluggable_template_file_by(type)
43
+ template_path_default = template_file_by(type)
44
+ template_path_pluggable.exist? ? template_path_pluggable : template_path_default
45
+ end
46
+
23
47
  def self.template(type)
24
- File.read(Pathname.new(__dir__).join(File.expand_path("templates", __dir__), "#{type}.erb").to_s)
48
+ File.read(template_path_by(type))
25
49
  end
26
50
 
27
51
  def self.graphql_type(property_name, property_format, property_type)
@@ -17,7 +17,7 @@ module Insights
17
17
 
18
18
  private_class_method def self.ensure_exporter_server
19
19
  require 'socket'
20
- TCPSocket.open("localhost", metrics_port) {}
20
+ TCPSocket.open("127.0.0.1", metrics_port) {}
21
21
  rescue Errno::ECONNREFUSED
22
22
  require 'prometheus_exporter/server'
23
23
  server = PrometheusExporter::Server::WebServer.new(port: metrics_port)
@@ -1,7 +1,7 @@
1
1
  module Insights
2
2
  module API
3
3
  module Common
4
- VERSION = "5.0.1".freeze
4
+ VERSION = "5.0.2".freeze
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insights-api-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.1
4
+ version: 5.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Insights Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-26 00:00:00.000000000 Z
11
+ date: 2021-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: acts_as_tenant