oort 0.1.2 → 0.2.0
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/Gemfile.lock +2 -2
- data/README.md +12 -2
- data/Rakefile +2 -0
- data/lib/oort/ordered.rb +0 -5
- data/lib/oort/scopes.rb +9 -19
- data/lib/oort/version.rb +1 -1
- data/oort-0.1.2.gem +0 -0
- metadata +3 -3
- data/oort.gemspec +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93d4111c81efb6f7e4f31bca10cfbef5c96a89ff1513db010fc6e31c45905552
|
4
|
+
data.tar.gz: d2fd5e70bb3ae83b72524fbb768551d8319db308aa9e0c124735804f29477421
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b81fea732d5131d90cc061fe21536edbdc2a1d35022b90feccd00c90fefb818e0ec4d29487202378c03a4a919bc1aef1e67165774b2e459d38bdf261ed15716
|
7
|
+
data.tar.gz: da75ab4163fe2b5ddb37099659ae0c38a248bdd44e2c8bcf627ad5e17ce6d634813c02072bafe876797b0b2a9973797a88f92ba8cf9d230a910462af9327abfe
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -63,8 +63,18 @@ These callbacks automatically insert a new post at the first position and remove
|
|
63
63
|
To change to order of a post, simply call `post.insert_at(12)`
|
64
64
|
To remove a post, simply call `post.remove_from_reorderable`
|
65
65
|
|
66
|
-
###
|
67
|
-
|
66
|
+
### Scopes
|
67
|
+
You can add the `ordered_with` scope.
|
68
|
+
|
69
|
+
```RUBY
|
70
|
+
class Post < ActiveRecord::Base
|
71
|
+
include Oort::Scopes
|
72
|
+
|
73
|
+
belongs_to :user
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
This allows a `user` object to have the following query:
|
68
78
|
|
69
79
|
```RUBY
|
70
80
|
user.posts.ordered_with(user.posts_ordering)
|
data/Rakefile
CHANGED
data/lib/oort/ordered.rb
CHANGED
@@ -7,10 +7,6 @@ module Oort
|
|
7
7
|
module Ordered
|
8
8
|
def self.included(base)
|
9
9
|
base.extend ClassMethods
|
10
|
-
# base.include InstanceMethods
|
11
|
-
|
12
|
-
base.class_eval do
|
13
|
-
end
|
14
10
|
end
|
15
11
|
|
16
12
|
module ClassMethods
|
@@ -27,7 +23,6 @@ module Oort
|
|
27
23
|
|
28
24
|
Inserts.call(**args.slice(:stored_in, :insert_method_name, :class_name))
|
29
25
|
Removes.call(**args.slice(:stored_in, :remove_from_method_name, :class_name))
|
30
|
-
Scopes.call(**args.slice(:association_class))
|
31
26
|
Callbacks.call(
|
32
27
|
**args.slice(:association_class, :remove_from_method_name, :insert_method_name, :instance_name, :default)
|
33
28
|
)
|
data/lib/oort/scopes.rb
CHANGED
@@ -1,30 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Oort
|
4
|
-
|
5
|
-
def self.
|
6
|
-
new(association_class: association_class).call
|
7
|
-
end
|
8
|
-
|
9
|
-
def initialize(association_class:)
|
10
|
-
@association_class = association_class
|
11
|
-
end
|
12
|
-
|
13
|
-
def call
|
4
|
+
module Scopes
|
5
|
+
def self.included(base)
|
14
6
|
# user = User.find(909)
|
15
7
|
# user.posts.ordered_with(user.posts_ordered)
|
16
8
|
# by default this will use posts.id::INTEGER
|
17
9
|
# but you can pass in something else if you have joins and items
|
18
10
|
# stored in another table
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
}
|
27
|
-
end
|
11
|
+
base.scope :ordered_with, lambda { |ids, type = "#{table_name}.id::INTEGER"|
|
12
|
+
if ids.blank?
|
13
|
+
order(:id)
|
14
|
+
else
|
15
|
+
order(Arel.sql("array_position(ARRAY[#{ids.join(", ")}], #{type})"))
|
16
|
+
end
|
17
|
+
}
|
28
18
|
end
|
29
19
|
end
|
30
20
|
end
|
data/lib/oort/version.rb
CHANGED
data/oort-0.1.2.gem
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oort
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tobyond
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Rails sorting and ordering without deadlocks
|
14
14
|
email:
|
@@ -40,7 +40,7 @@ files:
|
|
40
40
|
- lib/oort/removes.rb
|
41
41
|
- lib/oort/scopes.rb
|
42
42
|
- lib/oort/version.rb
|
43
|
-
- oort.
|
43
|
+
- oort-0.1.2.gem
|
44
44
|
- sig/oort.rbs
|
45
45
|
homepage: https://github.com/tobyond/oort
|
46
46
|
licenses:
|
data/oort.gemspec
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "lib/oort/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "oort"
|
7
|
-
spec.version = Oort::VERSION
|
8
|
-
spec.authors = ["tobyond"]
|
9
|
-
spec.homepage = "https://github.com/tobyond/oort"
|
10
|
-
|
11
|
-
spec.summary = "Oort to sort, order"
|
12
|
-
spec.description = "Rails sorting and ordering without deadlocks"
|
13
|
-
spec.license = "MIT"
|
14
|
-
spec.required_ruby_version = ">= 3.2.0"
|
15
|
-
|
16
|
-
spec.metadata["source_code_uri"] = "https://github.com/tobyond/oort"
|
17
|
-
|
18
|
-
# Specify which files should be added to the gem when it is released.
|
19
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
-
spec.files = Dir.chdir(__dir__) do
|
21
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
22
|
-
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
|
23
|
-
end
|
24
|
-
end
|
25
|
-
spec.bindir = "exe"
|
26
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
27
|
-
spec.require_paths = ["lib"]
|
28
|
-
|
29
|
-
# Uncomment to register a new dependency of your gem
|
30
|
-
# spec.add_dependency "rspec"
|
31
|
-
|
32
|
-
# For more information and examples about making a new gem, check out our
|
33
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
34
|
-
end
|