oort 0.1.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +12 -2
- data/Rakefile +2 -0
- data/lib/oort/callbacks.rb +1 -1
- 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: 6bf4b76facec9d22229f5bedbdfaa93120e7f4ca6f5e37f6f79d78cdc0f8ea74
|
4
|
+
data.tar.gz: 9c9a905cdaf773c79e383b68448183a8eeea2c8025bfd7214c661111cf467495
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c086ca2f59b8cfa75516e145b82d0f6284ae0a2b5adeb0ecd75eebcbc3f0587f50be0ccc28be460b18ac9d0a0944b08ea6ca61f7b24e131d5d3ecfe09347e2a8
|
7
|
+
data.tar.gz: 353af62388058aad2fab87d358abb219ba2b2b7b78bc824fcb13b50805b7392f4aae01359825b46a05b66290051a641940da4973cafc5cca208b4c85cb2e99fc
|
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/callbacks.rb
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.1
|
4
|
+
version: 0.2.1
|
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-17 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
|