trailblazer-finder 0.91.0 → 0.100.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trailblazer/finder/activities/prepare.rb +0 -8
- data/lib/trailblazer/finder/activities/prepare_adapter.rb +1 -1
- data/lib/trailblazer/finder/activities/prepare_entity.rb +4 -4
- data/lib/trailblazer/finder/activities/prepare_filters.rb +4 -4
- data/lib/trailblazer/finder/activities/prepare_paging.rb +5 -5
- data/lib/trailblazer/finder/activities/prepare_properties.rb +6 -6
- data/lib/trailblazer/finder/activities/prepare_sorting.rb +6 -6
- data/lib/trailblazer/finder/activities/process.rb +0 -6
- data/lib/trailblazer/finder/activities/process_adapters.rb +2 -5
- data/lib/trailblazer/finder/base.rb +1 -1
- data/lib/trailblazer/finder/dsl.rb +67 -31
- data/lib/trailblazer/finder/version.rb +1 -1
- data/lib/trailblazer/finder.rb +15 -32
- data/lib/trailblazer/operation/finder.rb +2 -2
- data/lib/trailblazer-finder.rb +1 -0
- metadata +30 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7b20b70b6ec1d9b476c977676905a019d5401e59ade88b7730dc9df838254c6
|
4
|
+
data.tar.gz: 137e82a841ab7bc0d92c8dd1c382b9b3ae7ea075bd1243a93002a2d4d6ebed63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c93fac22c96811f2a539ce7ed48e6b2adc1dc051d2844cea64d174f27f5f73b01012d0d3fa5659aa39e1ae997f60d641bab1498a85b32ad118aa2f64a075b710
|
7
|
+
data.tar.gz: b15bd4754b0cf76eaa96fb03422285a16b2cb126eb2d61eb9f399998f999394605699a54e37a07f219003d72a4c0de01b043ad11743284b4290625252cd086fe
|
@@ -1,13 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "prepare_adapter"
|
4
|
-
require_relative "prepare_entity"
|
5
|
-
require_relative "prepare_properties"
|
6
|
-
require_relative "prepare_filters"
|
7
|
-
require_relative "prepare_params"
|
8
|
-
require_relative "prepare_paging"
|
9
|
-
require_relative "prepare_sorting"
|
10
|
-
|
11
3
|
module Trailblazer
|
12
4
|
class Finder
|
13
5
|
module Activities
|
@@ -5,7 +5,7 @@ module Trailblazer
|
|
5
5
|
module Activities
|
6
6
|
class PrepareAdapter < Trailblazer::Activity::Railway
|
7
7
|
def set_adapter(ctx, **)
|
8
|
-
ctx[:adapter] = ctx
|
8
|
+
ctx[:adapter] = ctx[:config].adapter
|
9
9
|
end
|
10
10
|
|
11
11
|
def validate_adapter(_ctx, adapter:, **)
|
@@ -4,16 +4,16 @@ module Trailblazer
|
|
4
4
|
class Finder
|
5
5
|
module Activities
|
6
6
|
class PrepareEntity < Trailblazer::Activity::Railway
|
7
|
-
def validate_entity(ctx, **)
|
8
|
-
ctx.dig(:options, :entity) ||
|
7
|
+
def validate_entity(ctx, config:, **)
|
8
|
+
ctx.dig(:options, :entity) || config.entity
|
9
9
|
end
|
10
10
|
|
11
11
|
def invalid_entity_error(ctx, **)
|
12
12
|
(ctx[:errors] ||= []) << {entity: "Invalid entity specified"}
|
13
13
|
end
|
14
14
|
|
15
|
-
def set_entity(ctx, **)
|
16
|
-
ctx[:entity] = ctx.dig(:options, :entity)
|
15
|
+
def set_entity(ctx, config:, **)
|
16
|
+
ctx[:entity] = ctx.dig(:options, :entity) || instance_eval(&config.entity)
|
17
17
|
end
|
18
18
|
|
19
19
|
step :validate_entity
|
@@ -4,8 +4,8 @@ module Trailblazer
|
|
4
4
|
class Finder
|
5
5
|
module Activities
|
6
6
|
class PrepareFilters < Trailblazer::Activity::Railway
|
7
|
-
def validate_filters(
|
8
|
-
filters =
|
7
|
+
def validate_filters(_ctx, config:, **)
|
8
|
+
filters = config.filters
|
9
9
|
filters.each do |key, _value|
|
10
10
|
return false if !filters[key][:with].nil? && !filters[key][:with].is_a?(Symbol)
|
11
11
|
end
|
@@ -16,8 +16,8 @@ module Trailblazer
|
|
16
16
|
(ctx[:errors] ||= []) << {filters: "One or more filters are missing a with method definition"}
|
17
17
|
end
|
18
18
|
|
19
|
-
def set_filters(ctx, **)
|
20
|
-
ctx[:filters] =
|
19
|
+
def set_filters(ctx, config:, **)
|
20
|
+
ctx[:filters] = config.filters
|
21
21
|
end
|
22
22
|
|
23
23
|
step :validate_filters
|
@@ -4,15 +4,15 @@ module Trailblazer
|
|
4
4
|
class Finder
|
5
5
|
module Activities
|
6
6
|
class PreparePaging < Trailblazer::Activity::Railway
|
7
|
-
def check_paging(
|
8
|
-
paging =
|
9
|
-
return false if
|
7
|
+
def check_paging(_ctx, config:, **)
|
8
|
+
paging = config.paging
|
9
|
+
return false if config.paging.empty? || paging.nil?
|
10
10
|
|
11
11
|
true
|
12
12
|
end
|
13
13
|
|
14
|
-
def set_paging(ctx, **)
|
15
|
-
ctx[:paging] =
|
14
|
+
def set_paging(ctx, config:, **)
|
15
|
+
ctx[:paging] = config.paging
|
16
16
|
ctx[:paging][:current_page] = ctx.dig(:params, :page) || 1
|
17
17
|
return true unless ctx[:params][:per_page]
|
18
18
|
|
@@ -4,8 +4,8 @@ module Trailblazer
|
|
4
4
|
class Finder
|
5
5
|
module Activities
|
6
6
|
class PrepareProperties < Trailblazer::Activity::Railway
|
7
|
-
def check_property_types(
|
8
|
-
properties =
|
7
|
+
def check_property_types(_ctx, config:, **)
|
8
|
+
properties = config.properties
|
9
9
|
return true if properties.empty?
|
10
10
|
|
11
11
|
properties.each do |key, _value|
|
@@ -13,8 +13,8 @@ module Trailblazer
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def validate_property_types(
|
17
|
-
properties =
|
16
|
+
def validate_property_types(_ctx, config:, **)
|
17
|
+
properties = config.properties
|
18
18
|
return true if properties.empty?
|
19
19
|
|
20
20
|
properties.each do |key, _value|
|
@@ -26,8 +26,8 @@ module Trailblazer
|
|
26
26
|
(ctx[:errors] ||= []) << {properties: "One or more properties are missing a valid type"}
|
27
27
|
end
|
28
28
|
|
29
|
-
def set_properties(ctx, **)
|
30
|
-
ctx[:properties] =
|
29
|
+
def set_properties(ctx, config:, **)
|
30
|
+
ctx[:properties] = config.properties
|
31
31
|
end
|
32
32
|
|
33
33
|
step :check_property_types
|
@@ -4,20 +4,20 @@ module Trailblazer
|
|
4
4
|
class Finder
|
5
5
|
module Activities
|
6
6
|
class PrepareSorting < Trailblazer::Activity::Railway
|
7
|
-
def check_sorting(
|
8
|
-
sorting =
|
9
|
-
return true unless
|
7
|
+
def check_sorting(_ctx, config:, **)
|
8
|
+
sorting = config.sorting
|
9
|
+
return true unless sorting.empty? || sorting.nil?
|
10
10
|
end
|
11
11
|
|
12
|
-
def set_sorting(ctx, **)
|
12
|
+
def set_sorting(ctx, config:, **)
|
13
13
|
return true if ctx[:params][:sort].nil?
|
14
14
|
|
15
15
|
sorting = ctx[:params][:sort]
|
16
|
-
|
16
|
+
sorting_config = config.sorting
|
17
17
|
ctx[:sorting] = ctx[:sorting] || {}
|
18
18
|
sorting.split(",").each do |sorter|
|
19
19
|
spt = sorter.split
|
20
|
-
ctx[:sorting][spt[0]] = fetch_sort_direction(
|
20
|
+
ctx[:sorting][spt[0]] = fetch_sort_direction(sorting_config[spt[0].to_sym], spt[1]) if sorting_config.include?(spt[0].to_sym)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -1,11 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "process_adapters"
|
4
|
-
require_relative "process_predicates"
|
5
|
-
require_relative "process_paging"
|
6
|
-
require_relative "process_sorting"
|
7
|
-
require_relative "process_filters"
|
8
|
-
|
9
3
|
module Trailblazer
|
10
4
|
class Finder
|
11
5
|
module Activities
|
@@ -15,7 +15,7 @@ module Trailblazer
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def set_paginator(ctx, **)
|
18
|
-
paginator = ctx
|
18
|
+
paginator = ctx[:config].paginator
|
19
19
|
return true unless paginator
|
20
20
|
return false unless EXT_ORM_ADAPTERS.(ctx[:orm][:adapter])
|
21
21
|
return false unless PAGING_ADAPTERS.(paginator)
|
@@ -26,10 +26,7 @@ module Trailblazer
|
|
26
26
|
|
27
27
|
def invalid_paginator_error(ctx, **)
|
28
28
|
(ctx[:errors] ||= []) << {
|
29
|
-
paginator: "Can't use paginator #{ctx.
|
30
|
-
:config,
|
31
|
-
:paginator
|
32
|
-
)} without using an ORM like ActiveRecord or Sequel"
|
29
|
+
paginator: "Can't use paginator #{ctx[:config].paginator} without using an ORM like ActiveRecord or Sequel"
|
33
30
|
}
|
34
31
|
end
|
35
32
|
|
@@ -1,59 +1,95 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Trailblazer
|
4
2
|
class Finder
|
3
|
+
class Configuration
|
4
|
+
attr_accessor :entity, :paging, :properties, :sorting,
|
5
|
+
:filters, :adapter, :paginator
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@paging = {}
|
9
|
+
@properties = {}
|
10
|
+
@sorting = {}
|
11
|
+
@filters = {}
|
12
|
+
@paginator = nil
|
13
|
+
@adapter = "Basic"
|
14
|
+
end
|
15
|
+
|
16
|
+
def clone
|
17
|
+
new_config = Configuration.new
|
18
|
+
new_config.entity = entity
|
19
|
+
new_config.paging = paging.clone
|
20
|
+
new_config.properties = properties.clone
|
21
|
+
new_config.sorting = sorting.clone
|
22
|
+
new_config.filters = filters.clone
|
23
|
+
new_config.adapter = adapter
|
24
|
+
new_config.paginator = paginator
|
25
|
+
new_config
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
5
29
|
module Dsl
|
6
|
-
|
30
|
+
def config
|
31
|
+
@config ||= Configuration.new
|
32
|
+
end
|
33
|
+
|
7
34
|
|
8
35
|
def inherited(base)
|
9
|
-
|
36
|
+
## We don't want to inherit the config from Trailblazer::Finder
|
37
|
+
return if name == 'Trailblazer::Finder'
|
38
|
+
|
39
|
+
base.config = config.clone
|
10
40
|
end
|
11
41
|
|
12
42
|
def entity(&block)
|
13
|
-
config
|
43
|
+
config.entity = block
|
14
44
|
end
|
15
45
|
|
16
|
-
def paging(
|
17
|
-
config
|
18
|
-
config
|
19
|
-
config
|
46
|
+
def paging(per_page: 25, min_per_page: 10, max_per_page: 100)
|
47
|
+
config.paging[:per_page] = per_page
|
48
|
+
config.paging[:min_per_page] = min_per_page
|
49
|
+
config.paging[:max_per_page] = max_per_page
|
20
50
|
end
|
21
51
|
|
22
52
|
def property(name, options = {})
|
23
|
-
config
|
24
|
-
config
|
25
|
-
config
|
53
|
+
config.properties[name] = options
|
54
|
+
config.properties[name][:type] = options[:type] || Types::String
|
55
|
+
config.sorting[name] = options[:sort_direction] || :desc if options[:sortable]
|
26
56
|
end
|
27
57
|
|
28
58
|
def filter_by(name, options = {}, &block)
|
29
59
|
filter_name = name.to_sym
|
30
|
-
config
|
31
|
-
config
|
32
|
-
config
|
33
|
-
config
|
60
|
+
config.filters[filter_name] = {}
|
61
|
+
config.filters[filter_name][:name] = name
|
62
|
+
config.filters[filter_name][:with] = options[:with] if options.include?(:with)
|
63
|
+
config.filters[filter_name][:block] = block || nil
|
64
|
+
end
|
65
|
+
|
66
|
+
def adapter(adapter_name)
|
67
|
+
config.adapter = adapter_name.to_s
|
68
|
+
end
|
69
|
+
|
70
|
+
def paginator(paginator_name)
|
71
|
+
config.paginator = paginator_name.to_s
|
34
72
|
end
|
35
73
|
|
36
|
-
def
|
37
|
-
config
|
74
|
+
def current_adapter
|
75
|
+
config.adapter
|
38
76
|
end
|
39
77
|
|
40
|
-
def
|
41
|
-
config
|
78
|
+
def current_paginator
|
79
|
+
config.paginator
|
42
80
|
end
|
43
81
|
|
44
|
-
def
|
45
|
-
|
82
|
+
def filters_count
|
83
|
+
config.filters.count
|
84
|
+
end
|
46
85
|
|
47
|
-
|
48
|
-
|
49
|
-
entity: nil,
|
50
|
-
properties: {},
|
51
|
-
filters: {},
|
52
|
-
paging: {},
|
53
|
-
sorting: {},
|
54
|
-
adapters: []
|
55
|
-
}
|
86
|
+
def properties_count
|
87
|
+
config.properties.count
|
56
88
|
end
|
89
|
+
|
90
|
+
protected
|
91
|
+
|
92
|
+
attr_writer :config
|
57
93
|
end
|
58
94
|
end
|
59
95
|
end
|
data/lib/trailblazer/finder.rb
CHANGED
@@ -1,45 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require 'forwardable'
|
4
|
+
require 'dry-types'
|
5
|
+
require 'ostruct'
|
6
|
+
require 'zeitwerk'
|
7
|
+
require 'trailblazer/operation'
|
8
|
+
require 'trailblazer/macro'
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
require_relative "finder/utils/extra"
|
13
|
-
require_relative "finder/adapters/active_record/predicates"
|
14
|
-
require_relative "finder/adapters/active_record/paging"
|
15
|
-
require_relative "finder/adapters/active_record/sorting"
|
16
|
-
require_relative "finder/adapters/kaminari/paging"
|
17
|
-
require_relative "finder/adapters/will_paginate/paging"
|
18
|
-
require_relative "finder/adapters/sequel/predicates"
|
19
|
-
require_relative "finder/adapters/sequel/paging"
|
20
|
-
require_relative "finder/adapters/sequel/sorting"
|
21
|
-
require_relative "finder/adapters/basic/predicates"
|
22
|
-
require_relative "finder/adapters/basic/paging"
|
23
|
-
require_relative "finder/adapters/basic/sorting"
|
24
|
-
require_relative "finder/activities/prepare"
|
25
|
-
require_relative "finder/activities/process"
|
26
|
-
require_relative "finder/activities/find"
|
27
|
-
require_relative "finder/helpers/basic"
|
28
|
-
require_relative "finder/helpers/sorting"
|
29
|
-
require_relative "finder/dsl"
|
30
|
-
require_relative "finder/find"
|
31
|
-
require_relative "finder/base"
|
32
|
-
require_relative "operation/finder"
|
10
|
+
loader = Zeitwerk::Loader.for_gem_extension(Trailblazer)
|
11
|
+
adapters = "#{__dir__}/finder/adapters"
|
12
|
+
loader.do_not_eager_load(adapters)
|
13
|
+
loader.setup
|
33
14
|
|
34
15
|
module Trailblazer
|
35
16
|
class Finder
|
36
17
|
module Types
|
37
18
|
include Dry.Types(default: :nominal)
|
38
19
|
end
|
39
|
-
EXT_ORM_ADAPTERS = Types::Strict::String.enum(
|
40
|
-
ORM_ADAPTERS = EXT_ORM_ADAPTERS | Types::Strict::String.enum(
|
41
|
-
PAGING_ADAPTERS = Types::Strict::String.enum(
|
20
|
+
EXT_ORM_ADAPTERS = Types::Strict::String.enum('ActiveRecord', 'Sequel')
|
21
|
+
ORM_ADAPTERS = EXT_ORM_ADAPTERS | Types::Strict::String.enum('Basic')
|
22
|
+
PAGING_ADAPTERS = Types::Strict::String.enum('Kaminari', 'WillPaginate')
|
42
23
|
|
43
24
|
include Base
|
44
25
|
end
|
45
26
|
end
|
27
|
+
|
28
|
+
loader.eager_load
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Trailblazer
|
2
2
|
class Operation
|
3
3
|
def self.Finder(finder_class, action = nil, entity = nil)
|
4
|
-
task =
|
4
|
+
task = Activity::Circuit::TaskAdapter.for_step(Finder.new, binary: true)
|
5
5
|
injections = [
|
6
6
|
:params,
|
7
7
|
{:"finder.class" => ->(*) { finder_class }},
|
@@ -17,7 +17,7 @@ module Trailblazer
|
|
17
17
|
builder = Finder::Builder.new
|
18
18
|
ctx[:finder] = finder = builder.call(options, options[:params])
|
19
19
|
ctx[:model] = finder # Don't like it, but somehow it's needed if contracts are loaded
|
20
|
-
ctx[:"result.finder"] =
|
20
|
+
ctx[:"result.finder"] = Result.new(!finder.nil?, {})
|
21
21
|
|
22
22
|
ctx[:"result.finder"].success?
|
23
23
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'trailblazer/finder'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailblazer-finder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.100.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
@@ -26,6 +26,20 @@ dependencies:
|
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: 1.0.0
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: trailblazer-macro
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 2.1.15
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 2.1.15
|
29
43
|
- !ruby/object:Gem::Dependency
|
30
44
|
name: trailblazer-activity
|
31
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -40,6 +54,20 @@ dependencies:
|
|
40
54
|
- - ">="
|
41
55
|
- !ruby/object:Gem::Version
|
42
56
|
version: 0.13.0
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: zeitwerk
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 2.6.0
|
64
|
+
type: :runtime
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 2.6.0
|
43
71
|
- !ruby/object:Gem::Dependency
|
44
72
|
name: activerecord
|
45
73
|
requirement: !ruby/object:Gem::Requirement
|
@@ -217,6 +245,7 @@ executables: []
|
|
217
245
|
extensions: []
|
218
246
|
extra_rdoc_files: []
|
219
247
|
files:
|
248
|
+
- lib/trailblazer-finder.rb
|
220
249
|
- lib/trailblazer/finder.rb
|
221
250
|
- lib/trailblazer/finder/activities/find.rb
|
222
251
|
- lib/trailblazer/finder/activities/prepare.rb
|