servactory 1.6.3 → 1.6.4

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: 321c1d5afff2d05fca47c222254ed759bcab36acce61f346d4a141f936e25fa7
4
- data.tar.gz: 9820d66f4f2985665b3552583c2f84eddeb6860cb588c5444da7f32d32bf6c89
3
+ metadata.gz: e8baf1ff3aab8a43c92e83987cb5f4cfbc426be9aacabf5fe63dd01e133c891e
4
+ data.tar.gz: 0af5e8fe8bf02fe5f15c68655e298b2d097b402764d231045683907afa35ded3
5
5
  SHA512:
6
- metadata.gz: 3db3d15d89132bcb65afe6d25f278cb59e3c40f1cae70a02bb9f8af681356dc2aa14e05017c03088a10baf6b1de22833aaa3b70fb6f3138027cb283a279b77cb
7
- data.tar.gz: 1d01c55aba13762649115010a8cb3ca99489773abc8d48236529139318f9f12e636de08b8b66c417157918ff44b7223d0d9bd9a0f9faa9663aef1e908a869d79
6
+ metadata.gz: aa8ffc01e6bab482d397f07e18847ec5d0b70bbd1e94bf7ff1ab6f080efca2502547ee92db3b663ba2bac15c2c6add762094ab37d9c47b73eb7b66f8f3ed9b10
7
+ data.tar.gz: a15fc2c38e21b6637ff5b9f1273006c0aae2dfe5d8d084390a18e2ce262329510fe80ab2bc16d47f18f3da8a40c5f5daea0533ad4b611a0e9ce8868eacf87b8f
@@ -5,10 +5,14 @@ module Servactory
5
5
  class Collection
6
6
  # NOTE: http://words.steveklabnik.com/beware-subclassing-ruby-core-classes
7
7
  extend Forwardable
8
- def_delegators :@collection, :<<, :each, :merge, :empty?
8
+ def_delegators :@collection, :<<, :each, :merge, :sort_by, :size, :empty?
9
9
 
10
- def initialize(*)
11
- @collection = Set.new
10
+ def initialize(collection = Set.new)
11
+ @collection = collection
12
+ end
13
+
14
+ def sorted_by_position
15
+ Collection.new(sort_by(&:position))
12
16
  end
13
17
  end
14
18
  end
@@ -16,8 +16,12 @@ module Servactory
16
16
 
17
17
  private
18
18
 
19
- def make(name, **options)
20
- collection_of_methods << Method.new(name, **options)
19
+ def make(name, position: nil, **options)
20
+ collection_of_methods << Method.new(
21
+ name,
22
+ position: position.presence || next_position,
23
+ **options
24
+ )
21
25
  end
22
26
 
23
27
  def method_missing(shortcut_name, *args, &block)
@@ -34,6 +38,10 @@ module Servactory
34
38
  Servactory.configuration.method_shortcuts.include?(shortcut_name) || super
35
39
  end
36
40
 
41
+ def next_position
42
+ collection_of_methods.size + 1
43
+ end
44
+
37
45
  def collection_of_methods
38
46
  @collection_of_methods ||= Collection.new
39
47
  end
@@ -4,11 +4,13 @@ module Servactory
4
4
  module Methods
5
5
  class Method
6
6
  attr_reader :name,
7
+ :position,
7
8
  :condition,
8
9
  :is_condition_opposite
9
10
 
10
- def initialize(name, **options)
11
+ def initialize(name, position:, **options)
11
12
  @name = name
13
+ @position = position
12
14
 
13
15
  @is_condition_opposite = false
14
16
  @condition = options.fetch(:if, nil)
@@ -18,7 +18,7 @@ module Servactory
18
18
  def run!
19
19
  return try_to_use_call if collection_of_methods.empty?
20
20
 
21
- collection_of_methods.each do |make_method|
21
+ collection_of_methods.sorted_by_position.each do |make_method|
22
22
  next if unnecessary_for?(make_method)
23
23
 
24
24
  context.send(make_method.name)
@@ -4,7 +4,7 @@ module Servactory
4
4
  module VERSION
5
5
  MAJOR = 1
6
6
  MINOR = 6
7
- PATCH = 3
7
+ PATCH = 4
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servactory
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.3
4
+ version: 1.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sokolov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-30 00:00:00.000000000 Z
11
+ date: 2023-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport