trailblazer-finder 0.3.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +1 -4
- data/CHANGES.md +3 -0
- data/LICENSE.txt +1 -1
- data/README.md +0 -7
- data/lib/trailblazer/finder.rb +9 -18
- data/lib/trailblazer/finder/activity/find.rb +26 -28
- data/lib/trailblazer/finder/activity/prepare.rb +17 -14
- data/lib/trailblazer/finder/activity/prepare_adapters.rb +52 -0
- data/lib/trailblazer/finder/activity/prepare_entity.rb +25 -0
- data/lib/trailblazer/finder/activity/prepare_filters.rb +29 -0
- data/lib/trailblazer/finder/activity/prepare_paging.rb +42 -0
- data/lib/trailblazer/finder/activity/prepare_params.rb +27 -0
- data/lib/trailblazer/finder/activity/prepare_properties.rb +44 -0
- data/lib/trailblazer/finder/activity/prepare_sorting.rb +52 -0
- data/lib/trailblazer/finder/activity/process.rb +12 -8
- data/lib/trailblazer/finder/activity/process_adapters.rb +40 -0
- data/lib/trailblazer/finder/activity/process_filters.rb +21 -0
- data/lib/trailblazer/finder/activity/process_paging.rb +19 -0
- data/lib/trailblazer/finder/activity/process_predicates.rb +23 -0
- data/lib/trailblazer/finder/activity/process_sorting.rb +19 -0
- data/lib/trailblazer/finder/version.rb +1 -1
- data/lib/trailblazer/operation/finder.rb +42 -49
- data/spec/spec_helper.rb +4 -0
- data/trailblazer-finder.gemspec +6 -7
- metadata +32 -57
- data/.rubocop-https---raw-githubusercontent-com-trailblazer-meta-master-rubocop-yml +0 -101
- data/lib/trailblazer/finder/activity/prepare/adapters.rb +0 -66
- data/lib/trailblazer/finder/activity/prepare/entity.rb +0 -32
- data/lib/trailblazer/finder/activity/prepare/filters.rb +0 -36
- data/lib/trailblazer/finder/activity/prepare/paging.rb +0 -49
- data/lib/trailblazer/finder/activity/prepare/params.rb +0 -33
- data/lib/trailblazer/finder/activity/prepare/properties.rb +0 -47
- data/lib/trailblazer/finder/activity/prepare/sorting.rb +0 -57
- data/lib/trailblazer/finder/activity/process/adapters.rb +0 -48
- data/lib/trailblazer/finder/activity/process/filters.rb +0 -28
- data/lib/trailblazer/finder/activity/process/paging.rb +0 -26
- data/lib/trailblazer/finder/activity/process/predicates.rb +0 -30
- data/lib/trailblazer/finder/activity/process/sorting.rb +0 -26
@@ -1,101 +0,0 @@
|
|
1
|
-
AllCops:
|
2
|
-
DisplayCopNames: true
|
3
|
-
Layout/CaseIndentation:
|
4
|
-
IndentOneStep: true
|
5
|
-
Layout/FirstArrayElementLineBreak:
|
6
|
-
Enabled: true
|
7
|
-
Layout/FirstHashElementLineBreak:
|
8
|
-
Enabled: true
|
9
|
-
Layout/FirstMethodArgumentLineBreak:
|
10
|
-
Enabled: true
|
11
|
-
Layout/FirstMethodParameterLineBreak:
|
12
|
-
Enabled: true
|
13
|
-
Layout/MultilineAssignmentLayout:
|
14
|
-
Enabled: true
|
15
|
-
EnforcedStyle: same_line
|
16
|
-
Layout/SpaceInsideHashLiteralBraces:
|
17
|
-
EnforcedStyle: no_space
|
18
|
-
Metrics/LineLength:
|
19
|
-
Max: 130
|
20
|
-
Metrics/ParameterLists:
|
21
|
-
Max: 5
|
22
|
-
Naming/VariableNumber:
|
23
|
-
EnforcedStyle: snake_case
|
24
|
-
Style/AndOr:
|
25
|
-
EnforcedStyle: conditionals
|
26
|
-
Style/AutoResourceCleanup:
|
27
|
-
Enabled: true
|
28
|
-
Style/CollectionMethods:
|
29
|
-
Enabled: true
|
30
|
-
Style/Documentation:
|
31
|
-
Enabled: false
|
32
|
-
Style/EmptyLiteral:
|
33
|
-
Enabled: false
|
34
|
-
Style/EmptyMethod:
|
35
|
-
EnforcedStyle: expanded
|
36
|
-
Style/FormatStringToken:
|
37
|
-
EnforcedStyle: template
|
38
|
-
Style/ImplicitRuntimeError:
|
39
|
-
Enabled: true
|
40
|
-
Style/MethodCalledOnDoEndBlock:
|
41
|
-
Enabled: true
|
42
|
-
Style/MethodDefParentheses:
|
43
|
-
EnforcedStyle: require_parentheses
|
44
|
-
Style/MissingElse:
|
45
|
-
Enabled: true
|
46
|
-
EnforcedStyle: case
|
47
|
-
Style/NumericLiterals:
|
48
|
-
Enabled: false
|
49
|
-
Style/OptionHash:
|
50
|
-
Enabled: true
|
51
|
-
Style/PercentLiteralDelimiters:
|
52
|
-
PreferredDelimiters:
|
53
|
-
"%w": "[]"
|
54
|
-
"%W": "[]"
|
55
|
-
"%i": "[]"
|
56
|
-
"%I": "[]"
|
57
|
-
"%r": "()"
|
58
|
-
Style/ReturnNil:
|
59
|
-
Enabled: true
|
60
|
-
Style/SafeNavigation:
|
61
|
-
Enabled: false
|
62
|
-
Style/Send:
|
63
|
-
Enabled: true
|
64
|
-
Style/SignalException:
|
65
|
-
EnforcedStyle: semantic
|
66
|
-
Style/StringLiterals:
|
67
|
-
EnforcedStyle: double_quotes
|
68
|
-
Style/StringLiteralsInInterpolation:
|
69
|
-
EnforcedStyle: double_quotes
|
70
|
-
Style/StringMethods:
|
71
|
-
Enabled: true
|
72
|
-
Style/SymbolArray:
|
73
|
-
Enabled: true
|
74
|
-
# this allows in rspec to have expect { } with multiple lines
|
75
|
-
Style/BlockDelimiters:
|
76
|
-
EnforcedStyle: braces_for_chaining
|
77
|
-
Layout/EndOfLine:
|
78
|
-
Enabled: false
|
79
|
-
# don't need these checks in test folders
|
80
|
-
Metrics/ModuleLength:
|
81
|
-
Exclude:
|
82
|
-
- "spec/**/*"
|
83
|
-
- "test/**/*"
|
84
|
-
Metrics/BlockLength:
|
85
|
-
Exclude:
|
86
|
-
- "spec/**/*"
|
87
|
-
- "test/**/*"
|
88
|
-
- "*.gemspec" # definitely not in the gemspec
|
89
|
-
Metrics/MethodLength:
|
90
|
-
Max: 20
|
91
|
-
Lint/UnreachableCode:
|
92
|
-
Description: 'Unreachable code.'
|
93
|
-
Enabled: false
|
94
|
-
Lint/Void:
|
95
|
-
Enabled: false
|
96
|
-
Layout/HashAlignment:
|
97
|
-
EnforcedLastArgumentHashStyle: ignore_implicit
|
98
|
-
Metrics/AbcSize:
|
99
|
-
Max: 25
|
100
|
-
Style/LambdaCall:
|
101
|
-
Enabled: false
|
@@ -1,66 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Trailblazer
|
4
|
-
class Finder
|
5
|
-
module Activity
|
6
|
-
module Prepare
|
7
|
-
# Adapters Activity
|
8
|
-
module Adapters
|
9
|
-
extend Trailblazer::Activity::Railway()
|
10
|
-
|
11
|
-
module_function
|
12
|
-
|
13
|
-
def check_for_adapters(ctx, **)
|
14
|
-
adapters = ctx[:config][:adapters]
|
15
|
-
return true if adapters.empty?
|
16
|
-
|
17
|
-
adapters.each do |adapter|
|
18
|
-
return true if Finder::Adapters.constants.include?(adapter.to_sym)
|
19
|
-
end
|
20
|
-
false
|
21
|
-
end
|
22
|
-
|
23
|
-
def validate_adapters(ctx, **)
|
24
|
-
adapters = ctx[:config][:adapters]
|
25
|
-
return true if adapters.empty?
|
26
|
-
|
27
|
-
adapters.each do |adapter|
|
28
|
-
if ORM_ADAPTERS.include?(adapter)
|
29
|
-
return false if (adapters & (ORM_ADAPTERS - [adapter])).any?
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def invalid_adapters_error(ctx, **)
|
35
|
-
(ctx[:errors] ||= []) << {adapters: "One or more of the specified adapters are invalid"}
|
36
|
-
end
|
37
|
-
|
38
|
-
def multiple_orm_error(ctx, **)
|
39
|
-
(ctx[:errors] ||= []) << {adapters: "More then one ORM adapter specified"}
|
40
|
-
end
|
41
|
-
|
42
|
-
def set_adapters(ctx, **)
|
43
|
-
adapters = ctx[:config][:adapters]
|
44
|
-
ctx[:adapters] = (ORM_ADAPTERS & adapters).any? ? adapters : ["Basic"] + adapters
|
45
|
-
end
|
46
|
-
|
47
|
-
step method(:check_for_adapters),
|
48
|
-
Output(:success) => Track(:valid),
|
49
|
-
Output(:failure) => Track(:invalid_adapters)
|
50
|
-
step method(:validate_adapters), magnetic_to: [:valid],
|
51
|
-
Output(:success) => Track(:valid),
|
52
|
-
Output(:failure) => Track(:multiple_orm)
|
53
|
-
fail method(:invalid_adapters_error), magnetic_to: [:invalid_adapters],
|
54
|
-
Output(:success) => Track(:failure),
|
55
|
-
Output(:failure) => Track(:failure)
|
56
|
-
fail method(:multiple_orm_error), magnetic_to: [:multiple_orm],
|
57
|
-
Output(:success) => Track(:failure),
|
58
|
-
Output(:failure) => Track(:failure)
|
59
|
-
step method(:set_adapters), magnetic_to: [:valid],
|
60
|
-
Output(:success) => Track(:success),
|
61
|
-
Output(:failure) => Track(:failure)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Trailblazer
|
4
|
-
class Finder
|
5
|
-
module Activity
|
6
|
-
module Prepare
|
7
|
-
# Prepare Entity Activity
|
8
|
-
module Entity
|
9
|
-
extend Trailblazer::Activity::Railway()
|
10
|
-
|
11
|
-
module_function
|
12
|
-
|
13
|
-
def validate_entity(ctx, **)
|
14
|
-
ctx[:options][:entity] || ctx[:config][:entity]
|
15
|
-
end
|
16
|
-
|
17
|
-
def invalid_entity_error(ctx, **)
|
18
|
-
(ctx[:errors] ||= []) << {entity: "Invalid entity specified"}
|
19
|
-
end
|
20
|
-
|
21
|
-
def set_entity(ctx, **)
|
22
|
-
ctx[:entity] = ctx[:options][:entity] || instance_eval(&ctx[:config][:entity])
|
23
|
-
end
|
24
|
-
|
25
|
-
step method(:validate_entity), id: :validate_entity
|
26
|
-
fail method(:invalid_entity_error), id: :invalid_entity_error
|
27
|
-
step method(:set_entity), id: :set_entity
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Trailblazer
|
4
|
-
class Finder
|
5
|
-
module Activity
|
6
|
-
module Prepare
|
7
|
-
# Filters Activity
|
8
|
-
module Filters
|
9
|
-
extend Trailblazer::Activity::Railway()
|
10
|
-
|
11
|
-
module_function
|
12
|
-
|
13
|
-
def validate_filters(ctx, **)
|
14
|
-
filters = ctx[:config][:filters]
|
15
|
-
filters.each do |key, _value|
|
16
|
-
return false if !filters[key][:with].nil? && !filters[key][:with].is_a?(Symbol)
|
17
|
-
end
|
18
|
-
true
|
19
|
-
end
|
20
|
-
|
21
|
-
def invalid_filters_error(ctx, **)
|
22
|
-
(ctx[:errors] ||= []) << {filters: "One or more filters are missing a with method definition"}
|
23
|
-
end
|
24
|
-
|
25
|
-
def set_filters(ctx, **)
|
26
|
-
ctx[:filters] = ctx[:config][:filters]
|
27
|
-
end
|
28
|
-
|
29
|
-
step method(:validate_filters), id: :validate_filters
|
30
|
-
fail method(:invalid_filters_error), id: :invalid_filters_error
|
31
|
-
step method(:set_filters), id: :set_filters
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Trailblazer
|
4
|
-
class Finder
|
5
|
-
module Activity
|
6
|
-
module Prepare
|
7
|
-
# Paging Activity
|
8
|
-
module Paging
|
9
|
-
extend Trailblazer::Activity::Railway()
|
10
|
-
|
11
|
-
module_function
|
12
|
-
|
13
|
-
def check_paging(ctx, **)
|
14
|
-
paging = ctx[:config][:paging] || nil
|
15
|
-
return false if ctx[:config][:paging].empty? || paging.nil?
|
16
|
-
|
17
|
-
true
|
18
|
-
end
|
19
|
-
|
20
|
-
def set_paging(ctx, **)
|
21
|
-
ctx[:paging] = ctx[:config][:paging] || {}
|
22
|
-
ctx[:paging][:current_page] = ctx[:params][:page] || 1
|
23
|
-
return true unless ctx[:params][:per_page]
|
24
|
-
|
25
|
-
ctx[:paging][:per_page] = ctx[:params][:per_page].to_i || ctx[:paging][:per_page]
|
26
|
-
ctx[:paging][:per_page] = ctx[:paging][:max_per_page] if ctx[:paging][:per_page] > ctx[:paging][:max_per_page]
|
27
|
-
ctx[:paging][:per_page] = ctx[:paging][:min_per_page] if ctx[:paging][:per_page] < ctx[:paging][:min_per_page]
|
28
|
-
true
|
29
|
-
end
|
30
|
-
|
31
|
-
def clear_paging(ctx, **)
|
32
|
-
ctx[:params].delete(:page) unless ctx[:params][:page].nil?
|
33
|
-
true
|
34
|
-
end
|
35
|
-
|
36
|
-
step method(:check_paging), id: :check_paging,
|
37
|
-
Output(:success) => Track(:paging),
|
38
|
-
Output(:failure) => Track(:end_paging)
|
39
|
-
step method(:set_paging), id: :set_paging, magnetic_to: [:paging],
|
40
|
-
Output(:success) => Track(:end_paging),
|
41
|
-
Output(:failure) => Track(:failure)
|
42
|
-
step method(:clear_paging), id: :clear_paging, magnetic_to: [:end_paging],
|
43
|
-
Output(:success) => Track(:success),
|
44
|
-
Output(:failure) => Track(:failure)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Trailblazer
|
4
|
-
class Finder
|
5
|
-
module Activity
|
6
|
-
module Prepare
|
7
|
-
# Params Activity
|
8
|
-
module Params
|
9
|
-
extend Trailblazer::Activity::Railway()
|
10
|
-
|
11
|
-
module_function
|
12
|
-
|
13
|
-
def validate_params(_ctx, **)
|
14
|
-
# Should probably validate some things here at some point
|
15
|
-
true
|
16
|
-
end
|
17
|
-
|
18
|
-
def invalid_params_error(ctx, **)
|
19
|
-
# (ctx[:errors] ||= []) << {params: "One or more parameters are invalid"}
|
20
|
-
end
|
21
|
-
|
22
|
-
def set_params(ctx, **)
|
23
|
-
ctx[:params] = ctx[:options][:params] || {}
|
24
|
-
end
|
25
|
-
|
26
|
-
step method(:validate_params), id: :validate_params
|
27
|
-
fail method(:invalid_params_error), id: :invalid_params_error
|
28
|
-
step method(:set_params), id: :set_params
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Trailblazer
|
4
|
-
class Finder
|
5
|
-
module Activity
|
6
|
-
module Prepare
|
7
|
-
# Prepare Properties Activity
|
8
|
-
module Properties
|
9
|
-
extend Trailblazer::Activity::Railway()
|
10
|
-
|
11
|
-
module_function
|
12
|
-
|
13
|
-
def check_property_types(ctx, **)
|
14
|
-
properties = ctx[:config][:properties] || {}
|
15
|
-
return true if properties.empty?
|
16
|
-
|
17
|
-
properties.each do |key, _value|
|
18
|
-
return !properties[key][:type].nil?
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def validate_property_types(ctx, **)
|
23
|
-
properties = ctx[:config][:properties] || {}
|
24
|
-
return true if properties.empty?
|
25
|
-
|
26
|
-
properties.each do |key, _value|
|
27
|
-
return properties[key][:type].class.ancestors.include?(Dry::Types::Definition)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def invalid_properties_error(ctx, **)
|
32
|
-
(ctx[:errors] ||= []) << {properties: "One or more properties are missing a valid type"}
|
33
|
-
end
|
34
|
-
|
35
|
-
def set_properties(ctx, **)
|
36
|
-
ctx[:properties] = ctx[:config][:properties]
|
37
|
-
end
|
38
|
-
|
39
|
-
step method(:check_property_types), id: :check_property_types
|
40
|
-
step method(:validate_property_types), id: :validate_property_types
|
41
|
-
fail method(:invalid_properties_error), id: :invalid_properties_error
|
42
|
-
step method(:set_properties), id: :set_properties
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Trailblazer
|
4
|
-
class Finder
|
5
|
-
module Activity
|
6
|
-
module Prepare
|
7
|
-
# Paging Activity
|
8
|
-
module Sorting
|
9
|
-
extend Trailblazer::Activity::Railway()
|
10
|
-
|
11
|
-
module_function
|
12
|
-
|
13
|
-
def check_sorting(ctx, **)
|
14
|
-
sorting = ctx[:config][:sorting] || nil
|
15
|
-
return true unless ctx[:config][:sorting].empty? || sorting.nil?
|
16
|
-
end
|
17
|
-
|
18
|
-
def set_sorting(ctx, **)
|
19
|
-
return true if ctx[:params][:sort].nil?
|
20
|
-
|
21
|
-
sorting = ctx[:params][:sort]
|
22
|
-
config = ctx[:config][:sorting]
|
23
|
-
ctx[:sorting] = ctx[:sorting] || {}
|
24
|
-
sorting.split(",").each do |sorter|
|
25
|
-
spt = sorter.split
|
26
|
-
ctx[:sorting][spt[0]] = fetch_sort_direction(config[spt[0].to_sym], spt[1]) if config.include?(spt[0].to_sym)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def fetch_sort_direction(config_direction, params_direction = nil)
|
31
|
-
return config_direction == :asc ? :asc : :desc if params_direction.nil?
|
32
|
-
|
33
|
-
case params_direction
|
34
|
-
when ":asc", :asc, "asc" then :asc
|
35
|
-
else :desc
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def clear_sorting(ctx, **)
|
40
|
-
ctx[:params].delete(:sort) unless ctx[:params][:sort].nil?
|
41
|
-
true
|
42
|
-
end
|
43
|
-
|
44
|
-
step method(:check_sorting), id: :check_sorting,
|
45
|
-
Output(:success) => Track(:paging),
|
46
|
-
Output(:failure) => Track(:end_sorting)
|
47
|
-
step method(:set_sorting), id: :set_sorting, magnetic_to: [:paging],
|
48
|
-
Output(:success) => Track(:end_sorting),
|
49
|
-
Output(:failure) => Track(:failure)
|
50
|
-
step method(:clear_sorting), id: :clear_sorting, magnetic_to: [:end_sorting],
|
51
|
-
Output(:success) => Track(:success),
|
52
|
-
Output(:failure) => Track(:failure)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Trailblazer
|
4
|
-
class Finder
|
5
|
-
module Activity
|
6
|
-
module Process
|
7
|
-
# Process Adapters Activity
|
8
|
-
module Adapters
|
9
|
-
extend Trailblazer::Activity::Railway()
|
10
|
-
|
11
|
-
module_function
|
12
|
-
|
13
|
-
def set_orm_adapters(ctx, **)
|
14
|
-
ctx[:adapters].each do |adapter|
|
15
|
-
next unless (ORM_ADAPTERS + ["Basic"]).include?(adapter)
|
16
|
-
|
17
|
-
ctx[:orm] = {}
|
18
|
-
ctx[:orm][:adapter] = adapter
|
19
|
-
ctx[:orm][:predicates] = "Trailblazer::Finder::Adapters::#{adapter}::Predicates"
|
20
|
-
ctx[:orm][:paging] = "Trailblazer::Finder::Adapters::#{adapter}::Paging"
|
21
|
-
ctx[:orm][:sorting] = "Trailblazer::Finder::Adapters::#{adapter}::Sorting"
|
22
|
-
return true
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def set_paging_adapters(ctx, **)
|
27
|
-
ctx[:adapters].each do |adapter|
|
28
|
-
next unless PAGING_ADAPTERS.include?(adapter)
|
29
|
-
return false if ctx[:adapters].include?("Basic")
|
30
|
-
|
31
|
-
ctx[:orm][:paging] = "Trailblazer::Finder::Adapters::#{adapter}::Paging"
|
32
|
-
return true
|
33
|
-
end
|
34
|
-
true
|
35
|
-
end
|
36
|
-
|
37
|
-
def invalid_paging_adapter_error(ctx, **)
|
38
|
-
(ctx[:errors] ||= []) << {adapters: "Can't use paging adapters like Kaminari without using an ORM like ActiveRecord or Sequel"}
|
39
|
-
end
|
40
|
-
|
41
|
-
step method(:set_orm_adapters)
|
42
|
-
step method(:set_paging_adapters)
|
43
|
-
fail method(:invalid_paging_adapter_error)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|