params_ready 0.0.2 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/params_ready/builder.rb +21 -0
- data/lib/params_ready/extensions/delegation.rb +1 -0
- data/lib/params_ready/extensions/freezer.rb +2 -0
- data/lib/params_ready/extensions/undefined.rb +8 -0
- data/lib/params_ready/format.rb +4 -2
- data/lib/params_ready/helpers/arel_builder.rb +96 -35
- data/lib/params_ready/helpers/callable.rb +14 -0
- data/lib/params_ready/helpers/interface_definer.rb +48 -0
- data/lib/params_ready/helpers/memo.rb +0 -1
- data/lib/params_ready/helpers/options.rb +77 -9
- data/lib/params_ready/helpers/parameter_storage_class_methods.rb +27 -0
- data/lib/params_ready/helpers/parameter_user_class_methods.rb +18 -14
- data/lib/params_ready/helpers/rule.rb +30 -11
- data/lib/params_ready/helpers/usage_rule.rb +21 -3
- data/lib/params_ready/marshaller/array_marshallers.rb +4 -3
- data/lib/params_ready/marshaller/{hash_set_marshallers.rb → enum_set_marshallers.rb} +5 -5
- data/lib/params_ready/marshaller/polymorph_marshallers.rb +2 -2
- data/lib/params_ready/marshaller/{hash_marshallers.rb → struct_marshallers.rb} +5 -5
- data/lib/params_ready/marshaller/tuple_marshallers.rb +2 -2
- data/lib/params_ready/ordering/column.rb +1 -1
- data/lib/params_ready/output_parameters.rb +13 -2
- data/lib/params_ready/pagination/keyset_pagination.rb +5 -5
- data/lib/params_ready/parameter/{abstract_hash_parameter.rb → abstract_struct_parameter.rb} +6 -6
- data/lib/params_ready/parameter/array_parameter.rb +2 -2
- data/lib/params_ready/parameter/definition.rb +48 -40
- data/lib/params_ready/parameter/{hash_set_parameter.rb → enum_set_parameter.rb} +11 -10
- data/lib/params_ready/parameter/parameter.rb +48 -29
- data/lib/params_ready/parameter/state.rb +4 -4
- data/lib/params_ready/parameter/{hash_parameter.rb → struct_parameter.rb} +11 -10
- data/lib/params_ready/parameter/tuple_parameter.rb +1 -1
- data/lib/params_ready/parameter/value_parameter.rb +14 -10
- data/lib/params_ready/parameter_user.rb +7 -15
- data/lib/params_ready/query/array_grouping.rb +4 -4
- data/lib/params_ready/query/exists_predicate.rb +3 -3
- data/lib/params_ready/query/grouping.rb +8 -2
- data/lib/params_ready/query/join_clause.rb +91 -28
- data/lib/params_ready/query/predicate.rb +3 -3
- data/lib/params_ready/query/relation.rb +29 -14
- data/lib/params_ready/query/structured_grouping.rb +4 -4
- data/lib/params_ready/query/variable_operator_predicate.rb +12 -12
- data/lib/params_ready/value/coder.rb +36 -8
- data/lib/params_ready/version.rb +7 -0
- data/lib/params_ready.rb +3 -11
- metadata +56 -10
@@ -1,22 +1,23 @@
|
|
1
1
|
require_relative 'parameter'
|
2
2
|
require_relative '../builder'
|
3
|
-
require_relative '
|
3
|
+
require_relative 'abstract_struct_parameter'
|
4
4
|
require_relative '../marshaller/parameter_module'
|
5
5
|
|
6
6
|
|
7
7
|
module ParamsReady
|
8
8
|
module Parameter
|
9
|
-
class
|
9
|
+
class StructParameter < AbstractStructParameter
|
10
10
|
include Marshaller::ParameterModule
|
11
11
|
end
|
12
12
|
|
13
|
-
class
|
14
|
-
include
|
13
|
+
class StructParameterBuilder < Builder
|
14
|
+
include AbstractStructParameterBuilder::StructLike
|
15
15
|
include Marshaller::BuilderModule
|
16
|
-
register :
|
16
|
+
register :struct
|
17
|
+
register_deprecated :hash, use: :struct
|
17
18
|
|
18
19
|
def self.instance(name, altn: nil)
|
19
|
-
new
|
20
|
+
new StructParameterDefinition.new(name, altn: altn)
|
20
21
|
end
|
21
22
|
|
22
23
|
def map(hash)
|
@@ -24,11 +25,11 @@ module ParamsReady
|
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
|
-
class
|
28
|
-
include Marshaller::DefinitionModule[Marshaller::
|
28
|
+
class StructParameterDefinition < AbstractStructParameterDefinition
|
29
|
+
include Marshaller::DefinitionModule[Marshaller::StructMarshallers.collection]
|
29
30
|
|
30
|
-
name_for_formatter :
|
31
|
-
parameter_class
|
31
|
+
name_for_formatter :struct
|
32
|
+
parameter_class StructParameter
|
32
33
|
freeze_variables :key_map
|
33
34
|
|
34
35
|
def ensure_canonical(hash)
|
@@ -70,28 +70,32 @@ module ParamsReady
|
|
70
70
|
builder_class.register name
|
71
71
|
end
|
72
72
|
|
73
|
-
def self.instance(name, coder_or_name = nil, altn: nil)
|
73
|
+
def self.instance(name, coder_or_name = nil, altn: nil, **opts)
|
74
74
|
coder = if coder_or_name.is_a? Symbol
|
75
|
-
self.coder(coder_or_name)
|
76
|
-
|
77
|
-
Value::GenericCoder.new(name)
|
75
|
+
coder_class = self.coder(coder_or_name)
|
76
|
+
coder_class.instance(**opts)
|
78
77
|
else
|
79
|
-
|
78
|
+
raise ParamsReadyError, 'Expected option hash to be empty' unless opts.empty?
|
79
|
+
if coder_or_name.nil?
|
80
|
+
Value::GenericCoder.new(name)
|
81
|
+
else
|
82
|
+
coder_or_name
|
83
|
+
end
|
80
84
|
end
|
81
85
|
new ValueParameterDefinition.new(name, coder, altn: altn)
|
82
86
|
end
|
83
87
|
|
84
|
-
def self.[](
|
88
|
+
def self.[](coder_name)
|
85
89
|
builder = Class.new(self)
|
86
|
-
capitalized =
|
90
|
+
capitalized = coder_name.to_s.split('_').map(&:capitalize).join
|
87
91
|
qualified = "#{self.name}::#{capitalized}Builder".freeze
|
88
92
|
|
89
93
|
builder.define_singleton_method :name do
|
90
94
|
qualified
|
91
95
|
end
|
92
96
|
|
93
|
-
builder.define_singleton_method :instance do |name, altn: nil|
|
94
|
-
superclass.instance(name,
|
97
|
+
builder.define_singleton_method :instance do |name, altn: nil, **opts|
|
98
|
+
superclass.instance(name, coder_name, altn: altn, **opts)
|
95
99
|
end
|
96
100
|
|
97
101
|
builder
|
@@ -161,7 +165,7 @@ module ParamsReady
|
|
161
165
|
def ensure_canonical(value)
|
162
166
|
coerced = coder.try_coerce value, Format.instance(:backend)
|
163
167
|
if coder.strict_default? && value != coerced
|
164
|
-
raise ParamsReadyError, "input '#{value}'
|
168
|
+
raise ParamsReadyError, "input '#{value}'/#{value.class.name} (expected '#{coerced}'/#{coerced.class.name})"
|
165
169
|
end
|
166
170
|
validate coerced
|
167
171
|
coerced
|
@@ -15,29 +15,21 @@ module ParamsReady
|
|
15
15
|
protected
|
16
16
|
|
17
17
|
def parameter_definition(key)
|
18
|
-
|
18
|
+
self.class.parameter_definition key
|
19
19
|
end
|
20
20
|
|
21
21
|
def relation_definition(key)
|
22
|
-
|
22
|
+
self.class.relation_definition key
|
23
23
|
end
|
24
24
|
|
25
|
-
def populate_state_for(
|
26
|
-
definition = create_state_for
|
25
|
+
def populate_state_for(key, params, context = Format.instance(:frontend), validator = nil)
|
26
|
+
definition = create_state_for key
|
27
27
|
result, state = definition.from_input(params || {}, context: context, validator: validator || Result.new(:params_ready))
|
28
28
|
[result, state]
|
29
29
|
end
|
30
30
|
|
31
|
-
def create_state_for(
|
32
|
-
|
33
|
-
options = self.class.params_ready_storage
|
34
|
-
options.parameter_rules do |rule|
|
35
|
-
builder.add rule.parameter_definition if rule.valid_for(method)
|
36
|
-
end
|
37
|
-
options.relation_rules do |rule|
|
38
|
-
builder.relation rule.parameter_definition if rule.valid_for(method)
|
39
|
-
end
|
40
|
-
builder.build
|
31
|
+
def create_state_for(key)
|
32
|
+
self.class.params_ready_option.create_state_for(key)
|
41
33
|
end
|
42
34
|
end
|
43
|
-
end
|
35
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require_relative '../parameter/
|
1
|
+
require_relative '../parameter/struct_parameter'
|
2
2
|
require_relative '../parameter/array_parameter'
|
3
3
|
require_relative 'grouping'
|
4
4
|
require_relative 'predicate'
|
5
5
|
|
6
6
|
module ParamsReady
|
7
7
|
module Query
|
8
|
-
class ArrayGrouping < Parameter::
|
8
|
+
class ArrayGrouping < Parameter::StructParameter
|
9
9
|
include Parameter::GroupingLike
|
10
10
|
|
11
11
|
def predicates
|
@@ -29,7 +29,7 @@ module ParamsReady
|
|
29
29
|
end
|
30
30
|
|
31
31
|
class ArrayGroupingBuilder < Builder
|
32
|
-
include Parameter::
|
32
|
+
include Parameter::AbstractStructParameterBuilder::StructLike
|
33
33
|
PredicateRegistry.register_predicate :array_grouping_predicate, self
|
34
34
|
|
35
35
|
def prototype(type_name, name = :proto, *arr, **opts, &block)
|
@@ -48,7 +48,7 @@ module ParamsReady
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
class ArrayGroupingDefinition < Parameter::
|
51
|
+
class ArrayGroupingDefinition < Parameter::StructParameterDefinition
|
52
52
|
def initialize(*args, **opts)
|
53
53
|
super
|
54
54
|
end
|
@@ -58,7 +58,7 @@ module ParamsReady
|
|
58
58
|
PredicateRegistry.register_predicate :exists_predicate, self
|
59
59
|
|
60
60
|
include GroupingLike
|
61
|
-
include Parameter::
|
61
|
+
include Parameter::AbstractStructParameterBuilder::StructLike
|
62
62
|
include HavingArelTable
|
63
63
|
|
64
64
|
def self.instance(name, altn: nil, coll: nil)
|
@@ -66,8 +66,8 @@ module ParamsReady
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def related(on: nil, eq: nil, &block)
|
69
|
-
join_statement = JoinStatement.new(on: on, eq: eq, &block)
|
70
|
-
@definition.set_related(join_statement)
|
69
|
+
join_statement = JoinStatement::Builder.new(on: on, eq: eq, &block)
|
70
|
+
@definition.set_related(join_statement.build)
|
71
71
|
end
|
72
72
|
|
73
73
|
def outer_table(arel_table)
|
@@ -48,6 +48,10 @@ module ParamsReady
|
|
48
48
|
definition = Builder.define_grouping_operator(:operator, altn: :op, &block)
|
49
49
|
add definition
|
50
50
|
end
|
51
|
+
|
52
|
+
def to_query?(&block)
|
53
|
+
helper :to_query?, &block
|
54
|
+
end
|
51
55
|
end
|
52
56
|
end
|
53
57
|
|
@@ -67,10 +71,12 @@ module ParamsReady
|
|
67
71
|
arel_table.grouping(subqueries)
|
68
72
|
end
|
69
73
|
|
70
|
-
def eligible_for_query?(
|
74
|
+
def eligible_for_query?(table, context)
|
71
75
|
return false unless context.permitted? self
|
76
|
+
return false unless is_definite?
|
77
|
+
return true unless respond_to?(:to_query?)
|
72
78
|
|
73
|
-
|
79
|
+
to_query?(table, context)
|
74
80
|
end
|
75
81
|
|
76
82
|
def to_query_if_eligible(arel_table, context:)
|
@@ -1,14 +1,45 @@
|
|
1
1
|
require_relative '../helpers/arel_builder'
|
2
|
+
require_relative '../error'
|
2
3
|
|
3
4
|
module ParamsReady
|
4
5
|
module Query
|
5
6
|
class Join
|
7
|
+
class Builder
|
8
|
+
def initialize(&block)
|
9
|
+
@block = block
|
10
|
+
@statement_builder = nil
|
11
|
+
@only_if = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def build
|
15
|
+
instance_eval(&@block)
|
16
|
+
@block = nil
|
17
|
+
raise ParamsReadyError, 'Join statement must be present' if @statement_builder.nil?
|
18
|
+
[@statement_builder.build, @only_if]
|
19
|
+
end
|
20
|
+
|
21
|
+
def on(expression, arel_table: nil)
|
22
|
+
@statement_builder ||= JoinStatement::Builder.new
|
23
|
+
@statement_builder.on(expression, arel_table: arel_table)
|
24
|
+
end
|
25
|
+
|
26
|
+
def only_if(&block)
|
27
|
+
@only_if = block
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
6
32
|
attr_reader :arel_table, :statement, :type
|
7
33
|
|
8
|
-
def initialize(table, type, &block)
|
9
|
-
@arel_table = table
|
34
|
+
def initialize(table, type, table_alias: nil, &block)
|
35
|
+
@arel_table = Helpers::ArelBuilder::Table.instance(table, table_alias: table_alias)
|
10
36
|
@type = arel_type(type)
|
11
|
-
@statement =
|
37
|
+
@statement, @only_if = Builder.new(&block).build
|
38
|
+
freeze
|
39
|
+
end
|
40
|
+
|
41
|
+
def arel_table(context, parameter)
|
42
|
+
@arel_table.to_arel(context, parameter)
|
12
43
|
end
|
13
44
|
|
14
45
|
def arel_type(type)
|
@@ -19,32 +50,51 @@ module ParamsReady
|
|
19
50
|
end
|
20
51
|
end
|
21
52
|
|
22
|
-
def to_arel(base_table, context, parameter)
|
23
|
-
|
24
|
-
|
53
|
+
def to_arel(joined_table, base_table, context, parameter)
|
54
|
+
return joined_table unless eligible?(context, parameter)
|
55
|
+
|
56
|
+
arel_table = arel_table(context, parameter)
|
57
|
+
join_statement = @statement.to_arel(base_table, arel_table, context, parameter)
|
58
|
+
joined_table.join(arel_table, @type).on(join_statement)
|
59
|
+
end
|
60
|
+
|
61
|
+
def eligible?(context, parameter)
|
62
|
+
return true if @only_if.nil?
|
63
|
+
|
64
|
+
@only_if.call(context, parameter)
|
25
65
|
end
|
26
66
|
end
|
27
67
|
|
28
68
|
class JoinStatement
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
69
|
+
class Builder
|
70
|
+
def initialize(on: nil, eq: nil, &block)
|
71
|
+
@condition_builders = []
|
72
|
+
if on.nil?
|
73
|
+
raise ParamsReadyError, 'Parameter :eq unexpected' unless eq.nil?
|
74
|
+
else
|
75
|
+
condition = on(on)
|
76
|
+
condition.eq(eq) unless eq.nil?
|
35
77
|
end
|
36
|
-
|
37
|
-
raise ParamsReadyError('Parameter :eq unexpected') unless eq.nil?
|
78
|
+
@block = block
|
38
79
|
end
|
39
80
|
|
40
|
-
|
41
|
-
|
81
|
+
def on(expression, arel_table: nil)
|
82
|
+
condition = JoinCondition::Builder.new(expression, arel_table: arel_table)
|
83
|
+
@condition_builders << condition
|
84
|
+
condition
|
85
|
+
end
|
86
|
+
|
87
|
+
def build
|
88
|
+
instance_eval(&@block) unless @block.nil?
|
89
|
+
JoinStatement.new(@condition_builders.map(&:build))
|
90
|
+
end
|
42
91
|
end
|
43
92
|
|
44
|
-
def
|
45
|
-
|
46
|
-
@conditions
|
47
|
-
|
93
|
+
def initialize(conditions)
|
94
|
+
@conditions = conditions.freeze
|
95
|
+
raise ParamsReadyError, "Join clause is empty" if @conditions.empty?
|
96
|
+
|
97
|
+
freeze
|
48
98
|
end
|
49
99
|
|
50
100
|
def to_arel(base_table, join_table, context, parameter)
|
@@ -58,16 +108,29 @@ module ParamsReady
|
|
58
108
|
end
|
59
109
|
|
60
110
|
class JoinCondition
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
111
|
+
class Builder
|
112
|
+
def initialize(expression, arel_table: nil)
|
113
|
+
@on = Helpers::ArelBuilder::Attribute.instance(expression, arel_table: arel_table)
|
114
|
+
@op = nil
|
115
|
+
@to = nil
|
116
|
+
end
|
117
|
+
|
118
|
+
def eq(expression, arel_table: nil)
|
119
|
+
raise ParamsReadyError, "Operator already set" unless @op.nil?
|
120
|
+
@op = :eq
|
121
|
+
@to = Helpers::ArelBuilder::Attribute.instance(expression, arel_table: arel_table)
|
122
|
+
end
|
123
|
+
|
124
|
+
def build
|
125
|
+
JoinCondition.new(@on, @op, @to)
|
126
|
+
end
|
65
127
|
end
|
66
128
|
|
67
|
-
def
|
68
|
-
|
69
|
-
@op =
|
70
|
-
@to =
|
129
|
+
def initialize(on, op, to)
|
130
|
+
@on = on
|
131
|
+
@op = op
|
132
|
+
@to = to
|
133
|
+
freeze
|
71
134
|
end
|
72
135
|
|
73
136
|
def to_arel(base_table, join_table, context, parameter)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative '../extensions/registry'
|
2
2
|
require_relative '../parameter/array_parameter'
|
3
|
-
require_relative '../parameter/
|
3
|
+
require_relative '../parameter/enum_set_parameter'
|
4
4
|
require_relative '../helpers/arel_builder'
|
5
5
|
|
6
6
|
module ParamsReady
|
@@ -45,7 +45,7 @@ module ParamsReady
|
|
45
45
|
registry :types, as: :type, getter: true
|
46
46
|
register_type :value, Parameter::ValueParameterBuilder
|
47
47
|
register_type :array, Parameter::ArrayParameterBuilder
|
48
|
-
register_type :
|
48
|
+
register_type :enum_set, Parameter::EnumSetParameterBuilder
|
49
49
|
end
|
50
50
|
|
51
51
|
class AbstractPredicateDefinition < Parameter::AbstractDefinition
|
@@ -70,7 +70,7 @@ module ParamsReady
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def build_select_expression(arel_table, context)
|
73
|
-
arel_builder = Helpers::ArelBuilder.instance(select_expression, arel_table: @arel_table)
|
73
|
+
arel_builder = Helpers::ArelBuilder::Attribute.instance(select_expression, arel_table: @arel_table)
|
74
74
|
arel = arel_builder.to_arel(arel_table, context, self)
|
75
75
|
|
76
76
|
arel
|
@@ -136,7 +136,7 @@ module ParamsReady
|
|
136
136
|
|
137
137
|
def perform_count(scope: nil, context: Restriction.blanket_permission)
|
138
138
|
scope ||= definition.model_class if definition.model_class_defined?
|
139
|
-
group =
|
139
|
+
group = to_query_if_eligible(scope.arel_table, context: context)
|
140
140
|
relation = scope.where(group)
|
141
141
|
relation = perform_joins(relation, context)
|
142
142
|
relation.count
|
@@ -144,7 +144,7 @@ module ParamsReady
|
|
144
144
|
|
145
145
|
def keysets(limit, direction, keyset, scope: nil, context: Restriction.blanket_permission, &block)
|
146
146
|
model_class = scope || definition.model_class
|
147
|
-
group =
|
147
|
+
group = to_query_if_eligible(model_class.arel_table, context: context)
|
148
148
|
relation = model_class.where(group)
|
149
149
|
relation = perform_joins(relation, context)
|
150
150
|
|
@@ -156,7 +156,7 @@ module ParamsReady
|
|
156
156
|
|
157
157
|
def build_relation(scope: nil, include: [], context: Restriction.blanket_permission, paginate: true)
|
158
158
|
model_class = scope || definition.model_class
|
159
|
-
group =
|
159
|
+
group = to_query_if_eligible(model_class.arel_table, context: context)
|
160
160
|
relation = model_class.where(group)
|
161
161
|
relation = relation.includes(*include) unless include.empty?
|
162
162
|
relation = perform_joins(relation, context)
|
@@ -165,9 +165,12 @@ module ParamsReady
|
|
165
165
|
end
|
166
166
|
|
167
167
|
def perform_joins(relation, context)
|
168
|
-
|
168
|
+
eligible_joins = definition.joins.select do |join|
|
169
|
+
join.eligible?(context, self)
|
170
|
+
end
|
171
|
+
return relation if eligible_joins.empty?
|
169
172
|
|
170
|
-
sql =
|
173
|
+
sql = join_tables(eligible_joins, relation.arel_table, context).join_sources.map(&:to_sql).join(' ')
|
171
174
|
relation.joins(sql)
|
172
175
|
end
|
173
176
|
|
@@ -176,7 +179,7 @@ module ParamsReady
|
|
176
179
|
|
177
180
|
arel_table = joined_tables(model_class.arel_table, context)
|
178
181
|
|
179
|
-
group =
|
182
|
+
group = to_query_if_eligible(model_class.arel_table, context: context)
|
180
183
|
|
181
184
|
query = if group.nil?
|
182
185
|
arel_table
|
@@ -200,7 +203,7 @@ module ParamsReady
|
|
200
203
|
def build_query(model_class, context)
|
201
204
|
arel_table = arel_table(model_class)
|
202
205
|
|
203
|
-
group =
|
206
|
+
group = to_query_if_eligible(arel_table, context: context)
|
204
207
|
joined = joined_tables(arel_table, context)
|
205
208
|
|
206
209
|
query = if group.nil?
|
@@ -212,6 +215,12 @@ module ParamsReady
|
|
212
215
|
[arel_table, query]
|
213
216
|
end
|
214
217
|
|
218
|
+
def to_query_if_eligible(arel_table, context:)
|
219
|
+
return if respond_to?(:to_query?) && !to_query?(arel_table, context)
|
220
|
+
|
221
|
+
predicate_group(arel_table, context: context)
|
222
|
+
end
|
223
|
+
|
215
224
|
def order_if_applicable(arel_table, context)
|
216
225
|
if child_is_definite?(:ordering) && (context.permitted?(ordering) || ordering.required?)
|
217
226
|
ordering = self.ordering.to_arel(arel_table, context: context)
|
@@ -248,16 +257,23 @@ module ParamsReady
|
|
248
257
|
query
|
249
258
|
end
|
250
259
|
|
251
|
-
def joined_tables(
|
252
|
-
definition.joins
|
253
|
-
|
260
|
+
def joined_tables(base_table, context)
|
261
|
+
join_tables(definition.joins, base_table, context)
|
262
|
+
end
|
263
|
+
|
264
|
+
def join_tables(joins, base_table, context)
|
265
|
+
joins.reduce(base_table) do |joined_table, join|
|
266
|
+
join = join.to_arel(joined_table, base_table, context, self)
|
267
|
+
next joined_table if join.nil?
|
268
|
+
|
269
|
+
join
|
254
270
|
end
|
255
271
|
end
|
256
272
|
end
|
257
273
|
|
258
274
|
class RelationParameterBuilder < Builder
|
259
275
|
include GroupingLike
|
260
|
-
include Parameter::
|
276
|
+
include Parameter::AbstractStructParameterBuilder::StructLike
|
261
277
|
include HavingModel
|
262
278
|
|
263
279
|
def self.instance(name, altn: nil)
|
@@ -288,9 +304,8 @@ module ParamsReady
|
|
288
304
|
add ordering
|
289
305
|
end
|
290
306
|
|
291
|
-
def join_table(arel_table, type, &block)
|
292
|
-
join = Join.new arel_table, type, &block
|
293
|
-
join.freeze
|
307
|
+
def join_table(arel_table, type, table_alias: nil, &block)
|
308
|
+
join = Join.new arel_table, type, table_alias: nil, &block
|
294
309
|
@definition.add_join(join)
|
295
310
|
end
|
296
311
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative '../parameter/
|
1
|
+
require_relative '../parameter/struct_parameter'
|
2
2
|
require_relative '../parameter/value_parameter'
|
3
3
|
require_relative 'fixed_operator_predicate'
|
4
4
|
require_relative 'nullness_predicate'
|
@@ -6,7 +6,7 @@ require_relative 'grouping'
|
|
6
6
|
|
7
7
|
module ParamsReady
|
8
8
|
module Query
|
9
|
-
class StructuredGrouping < Parameter::
|
9
|
+
class StructuredGrouping < Parameter::StructParameter
|
10
10
|
include Parameter::GroupingLike
|
11
11
|
def predicates
|
12
12
|
return [] if is_nil?
|
@@ -29,7 +29,7 @@ module ParamsReady
|
|
29
29
|
|
30
30
|
class StructuredGroupingBuilder < Builder
|
31
31
|
include GroupingLike
|
32
|
-
include Parameter::
|
32
|
+
include Parameter::AbstractStructParameterBuilder::StructLike
|
33
33
|
PredicateRegistry.register_predicate :structured_grouping_predicate, self
|
34
34
|
|
35
35
|
def self.instance(name, altn: nil)
|
@@ -37,7 +37,7 @@ module ParamsReady
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
class StructuredGroupingDefinition < Parameter::
|
40
|
+
class StructuredGroupingDefinition < Parameter::StructParameterDefinition
|
41
41
|
attr_reader :arel_table, :predicates
|
42
42
|
|
43
43
|
def initialize(*args, **opts)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require_relative 'predicate'
|
2
|
-
require_relative '../parameter/
|
2
|
+
require_relative '../parameter/struct_parameter'
|
3
3
|
require_relative '../parameter/value_parameter'
|
4
4
|
require_relative '../value/validator'
|
5
5
|
require_relative 'predicate_operator'
|
@@ -12,7 +12,7 @@ module ParamsReady
|
|
12
12
|
|
13
13
|
def initialize(definition)
|
14
14
|
super definition
|
15
|
-
@data = definition.
|
15
|
+
@data = definition.struct_parameter.create
|
16
16
|
end
|
17
17
|
|
18
18
|
def build_query(select_expression, context: nil)
|
@@ -33,8 +33,8 @@ module ParamsReady
|
|
33
33
|
|
34
34
|
def inspect_content
|
35
35
|
op, val = if is_definite?
|
36
|
-
|
37
|
-
|
36
|
+
@data[:operator].unwrap_or(nil)&.name || '?'
|
37
|
+
@data[:value].unwrap_or('?')
|
38
38
|
else
|
39
39
|
%w[? ?]
|
40
40
|
end
|
@@ -64,7 +64,7 @@ module ParamsReady
|
|
64
64
|
PredicateRegistry.register_predicate :variable_operator_predicate, self
|
65
65
|
include HavingType
|
66
66
|
include HavingAttribute
|
67
|
-
include DelegatingBuilder[:
|
67
|
+
include DelegatingBuilder[:struct_parameter_builder]
|
68
68
|
|
69
69
|
def self.instance(name, altn: nil, attr: nil)
|
70
70
|
new VariableOperatorPredicateDefinition.new name, altn: altn, attribute_name: attr
|
@@ -82,19 +82,19 @@ module ParamsReady
|
|
82
82
|
class VariableOperatorPredicateDefinition < AbstractPredicateDefinition
|
83
83
|
include HavingAttribute
|
84
84
|
|
85
|
-
attr_reader :
|
86
|
-
attr_reader :
|
85
|
+
attr_reader :struct_parameter_builder
|
86
|
+
attr_reader :struct_parameter
|
87
87
|
|
88
88
|
def initialize(*args, attribute_name: nil, **opts)
|
89
89
|
super *args, **opts
|
90
90
|
@attribute_name = attribute_name
|
91
|
-
@
|
91
|
+
@struct_parameter_builder = Builder.builder(:struct).instance(name, altn: altn)
|
92
92
|
@operator_parameter_builder = Builder.builder(:predicate_operator).instance(:operator, altn: :op)
|
93
93
|
end
|
94
94
|
|
95
95
|
def set_type(type)
|
96
96
|
@type = type
|
97
|
-
@
|
97
|
+
@struct_parameter_builder.add @type.finish
|
98
98
|
end
|
99
99
|
|
100
100
|
def set_operators(array, &block)
|
@@ -107,12 +107,12 @@ module ParamsReady
|
|
107
107
|
constrain :enum, operators
|
108
108
|
end
|
109
109
|
@operator_parameter_builder.include(&block) unless block.nil?
|
110
|
-
@
|
110
|
+
@struct_parameter_builder.add @operator_parameter_builder.build
|
111
111
|
end
|
112
112
|
|
113
113
|
def finish
|
114
|
-
@
|
115
|
-
@
|
114
|
+
@struct_parameter = @struct_parameter_builder.build
|
115
|
+
@struct_parameter_builder = nil
|
116
116
|
@operator_parameter_builder = nil
|
117
117
|
@type = nil
|
118
118
|
|