scopiform 0.1.4 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/scopiform/association_scopes.rb +26 -20
- data/lib/scopiform/common_scopes.rb +6 -6
- data/lib/scopiform/core.rb +35 -9
- data/lib/scopiform/filters.rb +14 -12
- data/lib/scopiform/helpers.rb +9 -1
- data/lib/scopiform/reflection_plugin.rb +3 -3
- data/lib/scopiform/scope_context.rb +81 -0
- data/lib/scopiform/scope_definition.rb +12 -1
- data/lib/scopiform/string_number_date_scopes.rb +6 -7
- data/lib/scopiform/string_number_scopes.rb +56 -20
- data/lib/scopiform/version.rb +1 -1
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60fdf69684da8b4a16efc5b52b69bcae18d30824b844fb57fdc3219780ed2894
|
4
|
+
data.tar.gz: fbc86f9e966127b7c64546adc46b805e1c78caaa6d8aa9c49acceaeea7120639
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6165fbab6073d4ec637aed25cfb58d2f13ef7ecd590724b17374f47e9718850c62740655768f11f1e1b7f14a119a30eba863897c6189b620844e03b0c54fa0ee
|
7
|
+
data.tar.gz: 5730438bea472073e31a9f37d45ce3de8e066615e9dea0b0fa99af5bb955d5b3192cd068898c6367515d959d84354a202c90d405f5a08f488f8f07f342439aa7
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'active_support/concern'
|
4
|
+
require 'scopiform/scope_context'
|
4
5
|
|
5
6
|
module Scopiform
|
6
7
|
module AssociationScopes
|
@@ -11,12 +12,25 @@ module Scopiform
|
|
11
12
|
end
|
12
13
|
|
13
14
|
module ClassMethods
|
14
|
-
def
|
15
|
-
|
15
|
+
def scopiform_association_scope(association, method, value, ctx:)
|
16
|
+
is_root = ctx.nil?
|
17
|
+
ctx = ScopeContext.from(ctx)
|
18
|
+
ctx.set(arel_table) if is_root || ctx.arel_table.blank?
|
19
|
+
|
20
|
+
ctx.association = association
|
21
|
+
ctx.build_joins
|
22
|
+
|
23
|
+
applied = ctx.association.klass.send(method, value, ctx: ScopeContext.from(ctx).set(ctx.association_arel_table))
|
24
|
+
|
25
|
+
if is_root
|
26
|
+
ctx.scopes.reduce(joins(ctx.joins).merge(applied)) { |chain, scope| chain.merge(scope) }
|
27
|
+
else
|
28
|
+
ctx.scopes.reduce(all.merge(applied)) { |chain, scope| chain.merge(scope) }
|
29
|
+
end
|
16
30
|
end
|
17
31
|
|
18
|
-
def
|
19
|
-
|
32
|
+
def reflection_added(_name, reflection)
|
33
|
+
setup_association_auto_scopes(reflection)
|
20
34
|
end
|
21
35
|
|
22
36
|
private
|
@@ -30,30 +44,22 @@ module Scopiform
|
|
30
44
|
def setup_association_auto_scopes(association)
|
31
45
|
auto_scope_add(
|
32
46
|
association.name,
|
33
|
-
|
34
|
-
|
35
|
-
joins = {} if is_root
|
36
|
-
|
37
|
-
joins[association.name] ||= {}
|
38
|
-
applied = association.klass.apply_filters(value, joins: joins[association.name])
|
39
|
-
|
40
|
-
if is_root
|
41
|
-
scopiform_joins(joins).merge(applied)
|
42
|
-
else
|
43
|
-
all.merge(applied)
|
44
|
-
end
|
47
|
+
proc { |value, ctx: nil|
|
48
|
+
scopiform_association_scope(association, :apply_filters, value, ctx: ctx)
|
45
49
|
},
|
46
50
|
suffix: '_is',
|
47
51
|
argument_type: :hash
|
48
52
|
)
|
49
53
|
|
50
|
-
#
|
54
|
+
# Sorting
|
51
55
|
auto_scope_add(
|
52
56
|
association.name,
|
53
|
-
|
54
|
-
|
57
|
+
proc { |value, ctx: nil|
|
58
|
+
scopiform_association_scope(association, :apply_sorts, value, ctx: ctx)
|
59
|
+
},
|
60
|
+
prefix: 'sort_by_',
|
55
61
|
argument_type: :hash,
|
56
|
-
type: :
|
62
|
+
type: :sort
|
57
63
|
)
|
58
64
|
end
|
59
65
|
end
|
@@ -21,24 +21,24 @@ module Scopiform
|
|
21
21
|
|
22
22
|
auto_scope_add(
|
23
23
|
name,
|
24
|
-
|
24
|
+
proc { |value, ctx: nil, **| where(scopiform_arel(ctx)[name_sym].eq(value)) },
|
25
25
|
suffix: '_is',
|
26
26
|
argument_type: type
|
27
27
|
)
|
28
28
|
auto_scope_add(
|
29
29
|
name,
|
30
|
-
|
30
|
+
proc { |value, ctx: nil, **| where.not(scopiform_arel(ctx)[name_sym].eq(value)) },
|
31
31
|
suffix: '_not',
|
32
32
|
argument_type: type
|
33
33
|
)
|
34
34
|
|
35
|
-
#
|
35
|
+
# Sorting
|
36
36
|
auto_scope_add(
|
37
37
|
name,
|
38
|
-
|
39
|
-
prefix: '
|
38
|
+
proc { |value = :asc, ctx: nil, **| order(scopiform_arel(ctx)[name_sym].send(value.to_s.downcase)) },
|
39
|
+
prefix: 'sort_by_',
|
40
40
|
argument_type: :string,
|
41
|
-
type: :
|
41
|
+
type: :sort
|
42
42
|
)
|
43
43
|
end
|
44
44
|
end
|
data/lib/scopiform/core.rb
CHANGED
@@ -8,6 +8,8 @@ module Scopiform
|
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
10
10
|
module ClassMethods
|
11
|
+
attr_accessor :scopiform_ctx
|
12
|
+
|
11
13
|
def auto_scopes
|
12
14
|
@auto_scopes || []
|
13
15
|
end
|
@@ -18,16 +20,14 @@ module Scopiform
|
|
18
20
|
end
|
19
21
|
|
20
22
|
def auto_scope?(name)
|
21
|
-
auto_scopes.find { |scope| scope.name == name }
|
23
|
+
auto_scopes.find { |scope| scope.name == name }.present?
|
22
24
|
end
|
23
25
|
|
24
26
|
def auto_scope_add(attribute, block, prefix: nil, suffix: nil, **options)
|
25
|
-
scope_name = "#{prefix}#{attribute}#{suffix}".underscore
|
26
|
-
scope_name_sym = scope_name.to_sym
|
27
|
-
scope scope_name_sym, block
|
28
|
-
|
29
27
|
scope_definition = auto_scope_add_definition(attribute, prefix: prefix, suffix: suffix, **options)
|
30
28
|
|
29
|
+
scope scope_definition.name, block
|
30
|
+
|
31
31
|
aliases_for(attribute).each do |alias_name|
|
32
32
|
auto_scope_for_alias(alias_name, scope_definition)
|
33
33
|
end
|
@@ -41,8 +41,31 @@ module Scopiform
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
def enum(definitions)
|
45
|
+
super(definitions)
|
46
|
+
|
47
|
+
definitions.each_key { |name| update_scope_to_enum(name) }
|
48
|
+
end
|
49
|
+
|
44
50
|
private
|
45
51
|
|
52
|
+
def update_scope_to_enum(name)
|
53
|
+
scopes = auto_scopes_by_attribute(name)
|
54
|
+
|
55
|
+
scopes.each do |scope|
|
56
|
+
if scope.options[:type].blank?
|
57
|
+
argument_type = scope.options[:argument_type]
|
58
|
+
scope.options[:argument_type] = argument_type.is_a?(Array) ? [:string] : :string if argument_type
|
59
|
+
scope.options[:type] = :enum
|
60
|
+
end
|
61
|
+
|
62
|
+
if scope.options[:remove_for_enum]
|
63
|
+
singleton_class.send(:remove_method, scope.name)
|
64
|
+
@auto_scopes.delete(scope)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
46
69
|
def auto_scope_add_definition(attribute, **options)
|
47
70
|
definition = ScopeDefinition.new(attribute, **options)
|
48
71
|
@auto_scopes ||= []
|
@@ -52,10 +75,13 @@ module Scopiform
|
|
52
75
|
end
|
53
76
|
|
54
77
|
def auto_scope_for_alias(alias_name, scope_definition)
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
78
|
+
alias_scope_definition = scope_definition.dup
|
79
|
+
alias_scope_definition.attribute = alias_name.to_sym
|
80
|
+
|
81
|
+
@auto_scopes ||= []
|
82
|
+
@auto_scopes << alias_scope_definition
|
83
|
+
|
84
|
+
singleton_class.send(:alias_method, alias_scope_definition.name, scope_definition.name)
|
59
85
|
end
|
60
86
|
end
|
61
87
|
end
|
data/lib/scopiform/filters.rb
CHANGED
@@ -1,39 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'active_support/concern'
|
4
|
+
require 'scopiform/scope_context'
|
4
5
|
|
5
6
|
module Scopiform
|
6
7
|
module Filters
|
7
8
|
extend ActiveSupport::Concern
|
8
9
|
|
9
10
|
module ClassMethods
|
10
|
-
def apply_filters(filters_hash, injecting: all,
|
11
|
-
filters_hash.keys.inject(injecting) { |out, filter_name| resolve_filter(out, filter_name, filters_hash[filter_name],
|
11
|
+
def apply_filters(filters_hash, injecting: all, ctx: nil)
|
12
|
+
filters_hash.keys.inject(injecting) { |out, filter_name| resolve_filter(out, filter_name, filters_hash[filter_name], ctx: ctx) }
|
12
13
|
end
|
13
14
|
|
14
|
-
def
|
15
|
-
|
15
|
+
def apply_sorts(sorts_hash, injecting = all, ctx: nil)
|
16
|
+
sorts_hash.keys.inject(injecting) { |out, sort_name| resolve_sort(out, sort_name, sorts_hash[sort_name], ctx: ctx) }
|
16
17
|
end
|
17
18
|
|
18
19
|
private
|
19
20
|
|
20
|
-
def resolve_filter(out, filter_name, filter_argument,
|
21
|
+
def resolve_filter(out, filter_name, filter_argument, ctx:)
|
21
22
|
if filter_name.to_s.casecmp('OR').zero?
|
22
|
-
|
23
|
+
ctx ||= ScopeContext.new
|
24
|
+
ctx.joins = []
|
23
25
|
|
24
26
|
return (
|
25
27
|
filter_argument
|
26
|
-
.map { |or_filters_hash| apply_filters(or_filters_hash, injecting: out,
|
27
|
-
.map { |a| a.
|
28
|
+
.map { |or_filters_hash| apply_filters(or_filters_hash, injecting: out, ctx: ctx) }
|
29
|
+
.map { |a| a.joins(ctx.joins) }
|
28
30
|
.inject { |chain, applied| chain.or(applied) }
|
29
31
|
)
|
30
32
|
end
|
31
|
-
out.send(filter_name, filter_argument,
|
33
|
+
out.send(filter_name, filter_argument, ctx: ctx)
|
32
34
|
end
|
33
35
|
|
34
|
-
def
|
35
|
-
method_name = "
|
36
|
-
out.send(method_name,
|
36
|
+
def resolve_sort(out, sort_name, sort_argument, ctx:)
|
37
|
+
method_name = "sort_by_#{sort_name}"
|
38
|
+
out.send(method_name, sort_argument, ctx: ctx)
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
data/lib/scopiform/helpers.rb
CHANGED
@@ -43,7 +43,7 @@ module Scopiform
|
|
43
43
|
def association(name)
|
44
44
|
name = resolve_alias(name)
|
45
45
|
association = reflect_on_association(name)
|
46
|
-
|
46
|
+
|
47
47
|
association.klass if association.present?
|
48
48
|
association
|
49
49
|
rescue NameError
|
@@ -51,6 +51,14 @@ module Scopiform
|
|
51
51
|
nil
|
52
52
|
end
|
53
53
|
|
54
|
+
def enum_attribute?(name)
|
55
|
+
defined_enums.include? name.to_s
|
56
|
+
end
|
57
|
+
|
58
|
+
def scopiform_arel(ctx)
|
59
|
+
ctx&.arel_table || arel_table
|
60
|
+
end
|
61
|
+
|
54
62
|
protected
|
55
63
|
|
56
64
|
def safe_columns
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Scopiform
|
2
2
|
module ReflectionPlugin
|
3
|
-
def add_reflection(
|
4
|
-
super(
|
3
|
+
def add_reflection(record, name, reflection)
|
4
|
+
super(record, name, reflection)
|
5
5
|
|
6
|
-
|
6
|
+
record.reflection_added(name, reflection) if record.respond_to? :reflection_added
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Scopiform
|
2
|
+
class ScopeContext
|
3
|
+
attr_accessor :association, :arel_table, :association_arel_table, :joins, :ancestors, :scopes
|
4
|
+
|
5
|
+
def self.from(ctx)
|
6
|
+
created = new
|
7
|
+
|
8
|
+
if ctx
|
9
|
+
created.set(ctx.arel_table)
|
10
|
+
created.association = ctx.association
|
11
|
+
created.association_arel_table = ctx.association_arel_table
|
12
|
+
created.joins = ctx.joins
|
13
|
+
created.ancestors = [*ctx.ancestors]
|
14
|
+
end
|
15
|
+
|
16
|
+
created
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@joins = []
|
21
|
+
@ancestors = []
|
22
|
+
@scopes = []
|
23
|
+
end
|
24
|
+
|
25
|
+
def set(arel_table)
|
26
|
+
@arel_table = arel_table
|
27
|
+
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def build_joins
|
32
|
+
loop do
|
33
|
+
if association.through_reflection
|
34
|
+
source_reflection_name = association.source_reflection_name
|
35
|
+
self.association = association.through_reflection
|
36
|
+
end
|
37
|
+
|
38
|
+
ancestors << association.name.to_s.pluralize
|
39
|
+
self.association_arel_table = association.klass.arel_table.alias(alias_name)
|
40
|
+
|
41
|
+
joins << create_join
|
42
|
+
|
43
|
+
if association.scope.present? && association.scope.arity.zero?
|
44
|
+
association.klass.scopiform_ctx = ScopeContext.from(self).set(association_arel_table)
|
45
|
+
scopes << association.klass.instance_exec(&association.scope)
|
46
|
+
association.klass.scopiform_ctx = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
break if source_reflection_name.blank?
|
50
|
+
|
51
|
+
self.association = association.klass.reflect_on_association(source_reflection_name)
|
52
|
+
self.arel_table = association_arel_table
|
53
|
+
end
|
54
|
+
|
55
|
+
joins
|
56
|
+
end
|
57
|
+
|
58
|
+
def alias_name
|
59
|
+
ancestors.join('_').downcase
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def conditions
|
65
|
+
# Rails 4 join_keys has arity of 1, expecting a klass as an argument
|
66
|
+
keys = association.method(:join_keys).arity == 1 ? association.join_keys(association.klass) : association.join_keys
|
67
|
+
[*keys.foreign_key]
|
68
|
+
.zip([*keys.key])
|
69
|
+
.map { |foreign, primary| arel_table[foreign].eq(association_arel_table[primary]) }
|
70
|
+
.reduce { |acc, cond| acc.and(cond) }
|
71
|
+
end
|
72
|
+
|
73
|
+
def create_join
|
74
|
+
arel_table.create_join(
|
75
|
+
association_arel_table,
|
76
|
+
association_arel_table.create_on(conditions),
|
77
|
+
Arel::Nodes::OuterJoin
|
78
|
+
)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -10,7 +10,18 @@ module Scopiform
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def name
|
13
|
-
|
13
|
+
name_for(attribute)
|
14
|
+
end
|
15
|
+
|
16
|
+
def name_for(attribute_name)
|
17
|
+
"#{prefix}#{attribute_name}#{suffix}".underscore.to_sym
|
18
|
+
end
|
19
|
+
|
20
|
+
def dup
|
21
|
+
duplicate = super
|
22
|
+
duplicate.options = options.dup
|
23
|
+
|
24
|
+
duplicate
|
14
25
|
end
|
15
26
|
end
|
16
27
|
end
|
@@ -20,46 +20,45 @@ module Scopiform
|
|
20
20
|
name = column.name
|
21
21
|
name_sym = name.to_sym
|
22
22
|
type = column.type
|
23
|
-
arel_column = arel_table[name]
|
24
23
|
|
25
24
|
auto_scope_add(
|
26
25
|
name,
|
27
|
-
|
26
|
+
proc { |*value, ctx: nil, **| where(scopiform_arel(ctx)[name_sym].in(value.flatten)) },
|
28
27
|
suffix: '_in',
|
29
28
|
argument_type: [type]
|
30
29
|
)
|
31
30
|
|
32
31
|
auto_scope_add(
|
33
32
|
name,
|
34
|
-
|
33
|
+
proc { |*value, ctx: nil, **| where.not(scopiform_arel(ctx)[name_sym].in(value.flatten)) },
|
35
34
|
suffix: '_not_in',
|
36
35
|
argument_type: [type]
|
37
36
|
)
|
38
37
|
|
39
38
|
auto_scope_add(
|
40
39
|
name,
|
41
|
-
|
40
|
+
proc { |value, ctx: nil, **| where(scopiform_arel(ctx)[name_sym].lt(value)) },
|
42
41
|
suffix: '_lt',
|
43
42
|
argument_type: type
|
44
43
|
)
|
45
44
|
|
46
45
|
auto_scope_add(
|
47
46
|
name,
|
48
|
-
|
47
|
+
proc { |value, ctx: nil, **| where(scopiform_arel(ctx)[name_sym].lteq(value)) },
|
49
48
|
suffix: '_lte',
|
50
49
|
argument_type: type
|
51
50
|
)
|
52
51
|
|
53
52
|
auto_scope_add(
|
54
53
|
name,
|
55
|
-
|
54
|
+
proc { |value, ctx: nil, **| where(scopiform_arel(ctx)[name_sym].gt(value)) },
|
56
55
|
suffix: '_gt',
|
57
56
|
argument_type: type
|
58
57
|
)
|
59
58
|
|
60
59
|
auto_scope_add(
|
61
60
|
name,
|
62
|
-
|
61
|
+
proc { |value, ctx: nil, **| where(scopiform_arel(ctx)[name_sym].gteq(value)) },
|
63
62
|
suffix: '_gte',
|
64
63
|
argument_type: type
|
65
64
|
)
|
@@ -13,65 +13,101 @@ module Scopiform
|
|
13
13
|
module ClassMethods
|
14
14
|
private
|
15
15
|
|
16
|
+
def cast_to_text(arel_column)
|
17
|
+
cast_to = connection.adapter_name.downcase.starts_with?('mysql') ? 'CHAR' : 'TEXT'
|
18
|
+
Arel::Nodes::NamedFunction.new(
|
19
|
+
'CAST',
|
20
|
+
[arel_column.as(cast_to)]
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
16
24
|
def setup_string_and_number_auto_scopes
|
17
25
|
string_numbers = Helpers::STRING_TYPES + Helpers::NUMBER_TYPES
|
18
|
-
string_number_columns = safe_columns.select
|
26
|
+
string_number_columns = safe_columns.select do |column|
|
27
|
+
string_numbers.include?(column.type) && !enum_attribute?(column.name)
|
28
|
+
end
|
19
29
|
string_number_columns.each do |column|
|
20
30
|
name = column.name
|
21
31
|
type = column.type
|
22
|
-
|
32
|
+
cast = false
|
23
33
|
|
24
34
|
# Numeric values don't work properly with `.matches`. Using workaround
|
25
35
|
# https://coderwall.com/p/qtgvdq/using-arel_table-for-ilike-yes-even-with-integers
|
26
|
-
if Helpers::NUMBER_TYPES.include?
|
27
|
-
|
28
|
-
'CAST',
|
29
|
-
[arel_column.as('TEXT')]
|
30
|
-
)
|
31
|
-
|
36
|
+
if Helpers::NUMBER_TYPES.include? type
|
37
|
+
cast = true
|
32
38
|
type = :string
|
33
39
|
end
|
34
40
|
|
35
41
|
auto_scope_add(
|
36
42
|
name,
|
37
|
-
|
43
|
+
proc { |value, ctx: nil, **|
|
44
|
+
arel_column = scopiform_arel(ctx)[name]
|
45
|
+
arel_column = cast_to_text(arel_column) if cast
|
46
|
+
where(arel_column.matches("%#{ActiveRecord::Base.sanitize_sql_like(value.to_s)}%"))
|
47
|
+
},
|
38
48
|
suffix: '_contains',
|
39
|
-
|
49
|
+
argument_type: type,
|
50
|
+
remove_for_enum: true
|
40
51
|
)
|
41
52
|
|
42
53
|
auto_scope_add(
|
43
54
|
name,
|
44
|
-
|
55
|
+
proc { |value, ctx: nil, **|
|
56
|
+
arel_column = scopiform_arel(ctx)[name]
|
57
|
+
arel_column = cast_to_text(arel_column) if cast
|
58
|
+
where.not(arel_column.matches("%#{ActiveRecord::Base.sanitize_sql_like(value.to_s)}%"))
|
59
|
+
},
|
45
60
|
suffix: '_not_contains',
|
46
|
-
|
61
|
+
argument_type: type,
|
62
|
+
remove_for_enum: true
|
47
63
|
)
|
48
64
|
|
49
65
|
auto_scope_add(
|
50
66
|
name,
|
51
|
-
|
67
|
+
proc { |value, ctx: nil, **|
|
68
|
+
arel_column = scopiform_arel(ctx)[name]
|
69
|
+
arel_column = cast_to_text(arel_column) if cast
|
70
|
+
where(arel_column.matches("#{ActiveRecord::Base.sanitize_sql_like(value.to_s)}%"))
|
71
|
+
},
|
52
72
|
suffix: '_starts_with',
|
53
|
-
|
73
|
+
argument_type: type,
|
74
|
+
remove_for_enum: true
|
54
75
|
)
|
55
76
|
|
56
77
|
auto_scope_add(
|
57
78
|
name,
|
58
|
-
|
79
|
+
proc { |value, ctx: nil, **|
|
80
|
+
arel_column = scopiform_arel(ctx)[name]
|
81
|
+
arel_column = cast_to_text(arel_column) if cast
|
82
|
+
where.not(arel_column.matches("#{ActiveRecord::Base.sanitize_sql_like(value.to_s)}%"))
|
83
|
+
},
|
59
84
|
suffix: '_not_starts_with',
|
60
|
-
|
85
|
+
argument_type: type,
|
86
|
+
remove_for_enum: true
|
61
87
|
)
|
62
88
|
|
63
89
|
auto_scope_add(
|
64
90
|
name,
|
65
|
-
|
91
|
+
proc { |value, ctx: nil, **|
|
92
|
+
arel_column = scopiform_arel(ctx)[name]
|
93
|
+
arel_column = cast_to_text(arel_column) if cast
|
94
|
+
where(arel_column.matches("%#{ActiveRecord::Base.sanitize_sql_like(value.to_s)}"))
|
95
|
+
},
|
66
96
|
suffix: '_ends_with',
|
67
|
-
|
97
|
+
argument_type: type,
|
98
|
+
remove_for_enum: true
|
68
99
|
)
|
69
100
|
|
70
101
|
auto_scope_add(
|
71
102
|
name,
|
72
|
-
|
103
|
+
proc { |value, ctx: nil, **|
|
104
|
+
arel_column = scopiform_arel(ctx)[name]
|
105
|
+
arel_column = cast_to_text(arel_column) if cast
|
106
|
+
where.not(arel_column.matches("%#{ActiveRecord::Base.sanitize_sql_like(value.to_s)}"))
|
107
|
+
},
|
73
108
|
suffix: '_not_ends_with',
|
74
|
-
|
109
|
+
argument_type: type,
|
110
|
+
remove_for_enum: true
|
75
111
|
)
|
76
112
|
end
|
77
113
|
end
|
data/lib/scopiform/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scopiform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jayce.pulsipher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: warning
|
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: composite_primary_keys
|
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'
|
55
83
|
description:
|
56
84
|
email:
|
57
85
|
- jayce.pulsipher@3-form.com
|
@@ -69,6 +97,7 @@ files:
|
|
69
97
|
- lib/scopiform/filters.rb
|
70
98
|
- lib/scopiform/helpers.rb
|
71
99
|
- lib/scopiform/reflection_plugin.rb
|
100
|
+
- lib/scopiform/scope_context.rb
|
72
101
|
- lib/scopiform/scope_definition.rb
|
73
102
|
- lib/scopiform/string_number_date_scopes.rb
|
74
103
|
- lib/scopiform/string_number_scopes.rb
|