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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d13ddbadfac1d2c1ae4f77c6c81ebac6339ddfdb14b3e41a40da8ba93e62ae2
4
- data.tar.gz: fae5d70f39bc682f322c16f6e969b64e01794f9fdd87ed50264fb44ce3beb54a
3
+ metadata.gz: 93d4111c81efb6f7e4f31bca10cfbef5c96a89ff1513db010fc6e31c45905552
4
+ data.tar.gz: d2fd5e70bb3ae83b72524fbb768551d8319db308aa9e0c124735804f29477421
5
5
  SHA512:
6
- metadata.gz: aa7621267ccc7d99735bd5548eb7dbdcce7c4b3e280540dd393d4cd45707b0b671f9213eb55c01023c42a710afed5f31163213eead118b0db35d22365cc9fac1
7
- data.tar.gz: e0e6d7d5a3d2752ac7747439f28256aceb7183e773418836c05896b3f8ade18dbed010b41a54f05a08360f76c8039ac23c87e5900444867491e7405582552bd6
6
+ metadata.gz: 6b81fea732d5131d90cc061fe21536edbdc2a1d35022b90feccd00c90fefb818e0ec4d29487202378c03a4a919bc1aef1e67165774b2e459d38bdf261ed15716
7
+ data.tar.gz: da75ab4163fe2b5ddb37099659ae0c38a248bdd44e2c8bcf627ad5e17ce6d634813c02072bafe876797b0b2a9973797a88f92ba8cf9d230a910462af9327abfe
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oort (0.1.1)
4
+ oort (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -82,4 +82,4 @@ DEPENDENCIES
82
82
  zeitwerk (~> 2.5)
83
83
 
84
84
  BUNDLED WITH
85
- 2.4.10
85
+ 2.5.3
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
- ### Scope
67
- The `ordered_with` scope is also added to the post model. This allows a `user` object to have the following query:
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
@@ -7,6 +7,8 @@ Rake::TestTask.new(:test) do |t|
7
7
  t.libs << "test"
8
8
  t.libs << "lib"
9
9
  t.test_files = FileList["test/**/test_*.rb"]
10
+ t.verbose = true
11
+ t.warning = false
10
12
  end
11
13
 
12
14
  require "rubocop/rake_task"
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
- class Scopes
5
- def self.call(association_class:)
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
- @association_class.class_eval do
20
- scope :ordered_with, lambda { |ids, type = "#{table_name}.id::INTEGER"|
21
- if ids.blank?
22
- order(:id)
23
- else
24
- order(Arel.sql("array_position(ARRAY[#{ids.join(", ")}], #{type})"))
25
- end
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Oort
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
5
5
  end
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.2
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-03-16 00:00:00.000000000 Z
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.gemspec
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