para 0.7.2 → 0.7.3.p1

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
  SHA1:
3
- metadata.gz: 0f2e4cc7267a3d024fb9690cf426b0064bdb5da8
4
- data.tar.gz: eea345a2e6a7b354420b6fb27d8bcef5bda8d5b9
3
+ metadata.gz: 9914054a92494ea3515aff6b5d6666cedac890dd
4
+ data.tar.gz: e315815203d4e228705bcf9d0c65f79ce90628e2
5
5
  SHA512:
6
- metadata.gz: 75f8375384ace99363c1d518f82df23c7261cc96d86b925d743dcf6052b8d9d79a767eb2c2d21ebbe549798cf22caa429ca7cd88d1bb32acd96f497bf9afc9b0
7
- data.tar.gz: ea104d47ae45e079a54d0af2c2af8212dc2d5148722ee432f54764594d09cfff86988ec4ff2b4bdb15f96938c668fbb817e6c19f6774519c3ddcf5f99c96f0a5
6
+ metadata.gz: bacae843ada593e3530f3e71a9aa432a1db3a45b17d1e4bacd7acc99033ba4eddbed1aa514abce6e96240bc7b0b52d7a5f67b64ff630717d8c9534c00b517f1c
7
+ data.tar.gz: a332a031f1e49cb77eda71bdffd8166055e5b8962432513ed444f2d096f61c8b29a693fd209c08c467e6748192f2ce4b1dc00d1a9a1993c529504592b2ba83de
@@ -3,7 +3,7 @@ module Para
3
3
  class Section < ActiveRecord::Base
4
4
  self.table_name = 'para_page_sections'
5
5
 
6
- acts_as_orderable
6
+ acts_as_orderable parent: :page, as: :sections
7
7
 
8
8
  page_relation_options = { polymorphic: true }
9
9
 
@@ -3,7 +3,7 @@ module Para
3
3
  class SectionResource < ActiveRecord::Base
4
4
  self.table_name = 'para_page_section_resources'
5
5
 
6
- acts_as_orderable
6
+ acts_as_orderable parent: :section, as: :section_resources
7
7
 
8
8
  belongs_to :section
9
9
  belongs_to :resource, polymorphic: true
@@ -4,14 +4,18 @@ module Para
4
4
 
5
5
  included do
6
6
  scope :ordered, -> { order("#{ table_name }.position ASC") }
7
+
7
8
  before_create :orderable_assign_position
9
+ after_commit :reprocess_ordering
10
+ after_destroy :reprocess_ordering
8
11
  end
9
12
 
13
+ private
14
+
10
15
  def orderable_assign_position
11
16
  return if attribute_present?(:position)
12
17
 
13
- last_resource = self.class.unscoped
14
- .ordered
18
+ last_resource = orderable_scope
15
19
  .where.not(position: nil)
16
20
  .select(:position)
17
21
  .first
@@ -22,20 +26,45 @@ module Para
22
26
  0
23
27
  end
24
28
  end
29
+
30
+ # Unfragment existing resources positions
31
+ #
32
+ def reprocess_ordering
33
+ orderable_scope.each_with_index do |resource, index|
34
+ resource.update_column(:position, index)
35
+ end
36
+ end
37
+
38
+ def orderable_scope
39
+ if (parent = _orderable_options[:parent]) && (as = _orderable_options[:as])
40
+ try(parent).try(as).try(:ordered) || []
41
+ else
42
+ self.class.unscoped.ordered
43
+ end
44
+ end
25
45
  end
26
46
 
27
47
  module ActiveRecordOrderableMixin
28
48
  extend ActiveSupport::Concern
29
49
 
30
50
  included do
31
- class_attribute :orderable
51
+ class_attribute :orderable, :_orderable_options
32
52
  end
33
53
 
34
54
  module ClassMethods
35
- def acts_as_orderable
55
+ def acts_as_orderable(options = {})
36
56
  return if orderable?
37
57
 
58
+ unless (
59
+ ( options[:parent] && options[:as]) ||
60
+ (!options[:parent] && !options[:as])
61
+ )
62
+ raise "You need to either pass :parent and :as options to the " \
63
+ "acts_as_orderable macro, or no options at all."
64
+ end
65
+
38
66
  self.orderable = true
67
+ self._orderable_options = options
39
68
  include Para::Orderable
40
69
  end
41
70
 
data/lib/para/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Para
2
- VERSION = '0.7.2'
2
+ VERSION = '0.7.3.p1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: para
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3.p1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valentin Ballestrino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-05 00:00:00.000000000 Z
11
+ date: 2018-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -833,9 +833,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
833
833
  version: '0'
834
834
  required_rubygems_version: !ruby/object:Gem::Requirement
835
835
  requirements:
836
- - - ">="
836
+ - - ">"
837
837
  - !ruby/object:Gem::Version
838
- version: '0'
838
+ version: 1.3.1
839
839
  requirements: []
840
840
  rubyforge_project:
841
841
  rubygems_version: 2.6.11