mongoid_orderable 6.0.5 → 6.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +105 -99
- data/LICENSE.txt +20 -20
- data/README.md +296 -275
- data/Rakefile +24 -24
- data/lib/config/locales/en.yml +12 -12
- data/lib/mongoid/orderable/configs/field_config.rb +81 -81
- data/lib/mongoid/orderable/configs/global_config.rb +26 -26
- data/lib/mongoid/orderable/errors/invalid_target_position.rb +19 -19
- data/lib/mongoid/orderable/errors/transaction_failed.rb +20 -20
- data/lib/mongoid/orderable/generators/base.rb +21 -21
- data/lib/mongoid/orderable/generators/helpers.rb +37 -37
- data/lib/mongoid/orderable/generators/listable.rb +41 -41
- data/lib/mongoid/orderable/generators/lock_collection.rb +39 -39
- data/lib/mongoid/orderable/generators/movable.rb +62 -62
- data/lib/mongoid/orderable/generators/position.rb +26 -26
- data/lib/mongoid/orderable/generators/scope.rb +26 -26
- data/lib/mongoid/orderable/handlers/base.rb +218 -215
- data/lib/mongoid/orderable/handlers/document.rb +32 -32
- data/lib/mongoid/orderable/handlers/document_embedded.rb +14 -14
- data/lib/mongoid/orderable/handlers/document_transactional.rb +32 -32
- data/lib/mongoid/orderable/handlers/transaction.rb +75 -75
- data/lib/mongoid/orderable/installer.rb +64 -64
- data/lib/mongoid/orderable/mixins/callbacks.rb +45 -45
- data/lib/mongoid/orderable/mixins/cascadeable.rb +15 -15
- data/lib/mongoid/orderable/mixins/helpers.rb +45 -39
- data/lib/mongoid/orderable/mixins/listable.rb +49 -49
- data/lib/mongoid/orderable/mixins/movable.rb +64 -64
- data/lib/mongoid/orderable/version.rb +7 -7
- data/lib/mongoid/orderable.rb +29 -29
- data/lib/mongoid_orderable.rb +34 -33
- metadata +3 -3
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Mongoid
|
|
4
|
-
module Orderable
|
|
5
|
-
module Mixins
|
|
6
|
-
module Listable
|
|
7
|
-
def in_list?(field = nil)
|
|
8
|
-
persisted? && !orderable_position(field).nil?
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
# Returns items above the current document.
|
|
12
|
-
# Items with a position lower than this document's position.
|
|
13
|
-
def previous_items(field = nil)
|
|
14
|
-
field ||= default_orderable_field
|
|
15
|
-
orderable_scope(field).lt(orderable_field(field) => send(field))
|
|
16
|
-
end
|
|
17
|
-
alias prev_items previous_items
|
|
18
|
-
|
|
19
|
-
# Returns items below the current document.
|
|
20
|
-
# Items with a position greater than this document's position.
|
|
21
|
-
def next_items(field = nil)
|
|
22
|
-
field ||= default_orderable_field
|
|
23
|
-
orderable_scope(field).gt(orderable_field(field) => send(field))
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# Returns the previous item in the list
|
|
27
|
-
def previous_item(field = nil)
|
|
28
|
-
field ||= default_orderable_field
|
|
29
|
-
orderable_scope(field).where(orderable_field(field) => send(field) - 1).first
|
|
30
|
-
end
|
|
31
|
-
alias prev_item previous_item
|
|
32
|
-
|
|
33
|
-
# Returns the next item in the list
|
|
34
|
-
def next_item(field = nil)
|
|
35
|
-
field ||= default_orderable_field
|
|
36
|
-
orderable_scope(field).where(orderable_field(field) => send(field) + 1).first
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def first?(field = nil)
|
|
40
|
-
in_list?(field) && orderable_position(field) == orderable_top(field)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def last?(field = nil)
|
|
44
|
-
in_list?(field) && orderable_position(field) == orderable_bottom(field)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mongoid
|
|
4
|
+
module Orderable
|
|
5
|
+
module Mixins
|
|
6
|
+
module Listable
|
|
7
|
+
def in_list?(field = nil)
|
|
8
|
+
persisted? && !orderable_position(field).nil?
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Returns items above the current document.
|
|
12
|
+
# Items with a position lower than this document's position.
|
|
13
|
+
def previous_items(field = nil)
|
|
14
|
+
field ||= default_orderable_field
|
|
15
|
+
orderable_scope(field).lt(orderable_field(field) => send(field))
|
|
16
|
+
end
|
|
17
|
+
alias prev_items previous_items
|
|
18
|
+
|
|
19
|
+
# Returns items below the current document.
|
|
20
|
+
# Items with a position greater than this document's position.
|
|
21
|
+
def next_items(field = nil)
|
|
22
|
+
field ||= default_orderable_field
|
|
23
|
+
orderable_scope(field).gt(orderable_field(field) => send(field))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Returns the previous item in the list
|
|
27
|
+
def previous_item(field = nil)
|
|
28
|
+
field ||= default_orderable_field
|
|
29
|
+
orderable_scope(field).where(orderable_field(field) => send(field) - 1).first
|
|
30
|
+
end
|
|
31
|
+
alias prev_item previous_item
|
|
32
|
+
|
|
33
|
+
# Returns the next item in the list
|
|
34
|
+
def next_item(field = nil)
|
|
35
|
+
field ||= default_orderable_field
|
|
36
|
+
orderable_scope(field).where(orderable_field(field) => send(field) + 1).first
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def first?(field = nil)
|
|
40
|
+
in_list?(field) && orderable_position(field) == orderable_top(field)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def last?(field = nil)
|
|
44
|
+
in_list?(field) && orderable_position(field) == orderable_bottom(field)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Mongoid
|
|
4
|
-
module Orderable
|
|
5
|
-
module Mixins
|
|
6
|
-
module Movable
|
|
7
|
-
def move_to!(target_position, options = {})
|
|
8
|
-
move_field_to target_position, options
|
|
9
|
-
save
|
|
10
|
-
end
|
|
11
|
-
alias insert_at! move_to!
|
|
12
|
-
|
|
13
|
-
def move_to(target_position, options = {})
|
|
14
|
-
move_field_to target_position, options
|
|
15
|
-
end
|
|
16
|
-
alias insert_at move_to
|
|
17
|
-
|
|
18
|
-
def move_to=(target_position, options = {})
|
|
19
|
-
move_field_to target_position, options
|
|
20
|
-
end
|
|
21
|
-
alias insert_at= move_to=
|
|
22
|
-
|
|
23
|
-
%i[top bottom].each do |symbol|
|
|
24
|
-
class_eval <<~KLASS, __FILE__, __LINE__ + 1
|
|
25
|
-
def move_to_#{symbol}(options = {})
|
|
26
|
-
move_to :#{symbol}, options
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def move_to_#{symbol}!(options = {})
|
|
30
|
-
move_to! :#{symbol}, options
|
|
31
|
-
end
|
|
32
|
-
KLASS
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
%i[higher lower].each do |symbol|
|
|
36
|
-
class_eval <<~KLASS, __FILE__, __LINE__ + 1
|
|
37
|
-
def move_#{symbol}(options = {})
|
|
38
|
-
move_to :#{symbol}, options
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def move_#{symbol}!(options = {})
|
|
42
|
-
move_to! :#{symbol}, options
|
|
43
|
-
end
|
|
44
|
-
KLASS
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
private
|
|
48
|
-
|
|
49
|
-
def move_all
|
|
50
|
-
@move_all ||= {}
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def move_field_to(position, options)
|
|
54
|
-
field = options[:field] || default_orderable_field
|
|
55
|
-
move_all[field] = position
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def clear_move_all!
|
|
59
|
-
@move_all = {}
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mongoid
|
|
4
|
+
module Orderable
|
|
5
|
+
module Mixins
|
|
6
|
+
module Movable
|
|
7
|
+
def move_to!(target_position, options = {})
|
|
8
|
+
move_field_to target_position, options
|
|
9
|
+
save
|
|
10
|
+
end
|
|
11
|
+
alias insert_at! move_to!
|
|
12
|
+
|
|
13
|
+
def move_to(target_position, options = {})
|
|
14
|
+
move_field_to target_position, options
|
|
15
|
+
end
|
|
16
|
+
alias insert_at move_to
|
|
17
|
+
|
|
18
|
+
def move_to=(target_position, options = {})
|
|
19
|
+
move_field_to target_position, options
|
|
20
|
+
end
|
|
21
|
+
alias insert_at= move_to=
|
|
22
|
+
|
|
23
|
+
%i[top bottom].each do |symbol|
|
|
24
|
+
class_eval <<~KLASS, __FILE__, __LINE__ + 1
|
|
25
|
+
def move_to_#{symbol}(options = {})
|
|
26
|
+
move_to :#{symbol}, options
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def move_to_#{symbol}!(options = {})
|
|
30
|
+
move_to! :#{symbol}, options
|
|
31
|
+
end
|
|
32
|
+
KLASS
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
%i[higher lower].each do |symbol|
|
|
36
|
+
class_eval <<~KLASS, __FILE__, __LINE__ + 1
|
|
37
|
+
def move_#{symbol}(options = {})
|
|
38
|
+
move_to :#{symbol}, options
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def move_#{symbol}!(options = {})
|
|
42
|
+
move_to! :#{symbol}, options
|
|
43
|
+
end
|
|
44
|
+
KLASS
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
|
|
49
|
+
def move_all
|
|
50
|
+
@move_all ||= {}
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def move_field_to(position, options)
|
|
54
|
+
field = options[:field] || default_orderable_field
|
|
55
|
+
move_all[field] = position
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def clear_move_all!
|
|
59
|
+
@move_all = {}
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Mongoid
|
|
4
|
-
module Orderable
|
|
5
|
-
VERSION = '6.0.
|
|
6
|
-
end
|
|
7
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mongoid
|
|
4
|
+
module Orderable
|
|
5
|
+
VERSION = '6.0.7'
|
|
6
|
+
end
|
|
7
|
+
end
|
data/lib/mongoid/orderable.rb
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Mongoid
|
|
4
|
-
module Orderable
|
|
5
|
-
MUTEX = Mutex.new
|
|
6
|
-
|
|
7
|
-
class << self
|
|
8
|
-
def configure
|
|
9
|
-
yield(config) if block_given?
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def config
|
|
13
|
-
@config || MUTEX.synchronize { @config = ::Mongoid::Orderable::Configs::GlobalConfig.new }
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
extend ActiveSupport::Concern
|
|
18
|
-
|
|
19
|
-
included do
|
|
20
|
-
class_attribute :orderable_configs
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
class_methods do
|
|
24
|
-
def orderable(options = {})
|
|
25
|
-
Mongoid::Orderable::Installer.new(self, options).setup
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mongoid
|
|
4
|
+
module Orderable
|
|
5
|
+
MUTEX = Mutex.new
|
|
6
|
+
|
|
7
|
+
class << self
|
|
8
|
+
def configure
|
|
9
|
+
yield(config) if block_given?
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def config
|
|
13
|
+
@config || MUTEX.synchronize { @config = ::Mongoid::Orderable::Configs::GlobalConfig.new }
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
extend ActiveSupport::Concern
|
|
18
|
+
|
|
19
|
+
included do
|
|
20
|
+
class_attribute :orderable_configs
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class_methods do
|
|
24
|
+
def orderable(options = {})
|
|
25
|
+
Mongoid::Orderable::Installer.new(self, options).setup
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/mongoid_orderable.rb
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require '
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
I18n.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
require 'mongoid/orderable
|
|
12
|
-
require 'mongoid/orderable/
|
|
13
|
-
require 'mongoid/orderable/configs/
|
|
14
|
-
require 'mongoid/orderable/
|
|
15
|
-
require 'mongoid/orderable/errors/
|
|
16
|
-
require 'mongoid/orderable/
|
|
17
|
-
require 'mongoid/orderable/mixins/
|
|
18
|
-
require 'mongoid/orderable/mixins/
|
|
19
|
-
require 'mongoid/orderable/mixins/
|
|
20
|
-
require 'mongoid/orderable/mixins/
|
|
21
|
-
require 'mongoid/orderable/
|
|
22
|
-
require 'mongoid/orderable/generators/
|
|
23
|
-
require 'mongoid/orderable/generators/
|
|
24
|
-
require 'mongoid/orderable/generators/
|
|
25
|
-
require 'mongoid/orderable/generators/
|
|
26
|
-
require 'mongoid/orderable/generators/
|
|
27
|
-
require 'mongoid/orderable/generators/
|
|
28
|
-
require 'mongoid/orderable/
|
|
29
|
-
require 'mongoid/orderable/handlers/
|
|
30
|
-
require 'mongoid/orderable/handlers/
|
|
31
|
-
require 'mongoid/orderable/handlers/
|
|
32
|
-
require 'mongoid/orderable/handlers/
|
|
33
|
-
require 'mongoid/orderable/
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'logger'
|
|
4
|
+
require 'active_support'
|
|
5
|
+
|
|
6
|
+
I18n.enforce_available_locales = false if I18n.respond_to?(:enforce_available_locales)
|
|
7
|
+
I18n.load_path << File.join(File.dirname(__FILE__), 'config', 'locales', 'en.yml')
|
|
8
|
+
|
|
9
|
+
require 'mongoid'
|
|
10
|
+
|
|
11
|
+
require 'mongoid/orderable'
|
|
12
|
+
require 'mongoid/orderable/version'
|
|
13
|
+
require 'mongoid/orderable/configs/global_config'
|
|
14
|
+
require 'mongoid/orderable/configs/field_config'
|
|
15
|
+
require 'mongoid/orderable/errors/invalid_target_position'
|
|
16
|
+
require 'mongoid/orderable/errors/transaction_failed'
|
|
17
|
+
require 'mongoid/orderable/mixins/helpers'
|
|
18
|
+
require 'mongoid/orderable/mixins/callbacks'
|
|
19
|
+
require 'mongoid/orderable/mixins/listable'
|
|
20
|
+
require 'mongoid/orderable/mixins/movable'
|
|
21
|
+
require 'mongoid/orderable/mixins/cascadeable'
|
|
22
|
+
require 'mongoid/orderable/generators/base'
|
|
23
|
+
require 'mongoid/orderable/generators/listable'
|
|
24
|
+
require 'mongoid/orderable/generators/lock_collection'
|
|
25
|
+
require 'mongoid/orderable/generators/movable'
|
|
26
|
+
require 'mongoid/orderable/generators/position'
|
|
27
|
+
require 'mongoid/orderable/generators/scope'
|
|
28
|
+
require 'mongoid/orderable/generators/helpers'
|
|
29
|
+
require 'mongoid/orderable/handlers/base'
|
|
30
|
+
require 'mongoid/orderable/handlers/document'
|
|
31
|
+
require 'mongoid/orderable/handlers/document_embedded'
|
|
32
|
+
require 'mongoid/orderable/handlers/document_transactional'
|
|
33
|
+
require 'mongoid/orderable/handlers/transaction'
|
|
34
|
+
require 'mongoid/orderable/installer'
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mongoid_orderable
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 6.0.
|
|
4
|
+
version: 6.0.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- pyromaniac
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-10-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: mongoid
|
|
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: '0'
|
|
83
83
|
requirements: []
|
|
84
|
-
rubygems_version: 3.
|
|
84
|
+
rubygems_version: 3.5.16
|
|
85
85
|
signing_key:
|
|
86
86
|
specification_version: 4
|
|
87
87
|
summary: Mongoid orderable list implementation
|