acts_as_belongable 1.1.2 → 2.1.2
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b80c9a93bf4a2ab6180cc848d9fcf43084daeb88dd56bfc8995c2955eaae8cda
|
4
|
+
data.tar.gz: 0e384ccdd8fc420f4e3263697aec4bfd067d426b741ffec420405808b71bcbca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab7d4a5f9d99fc1eae0120f7eb96fc16f5b95146ce24c779a96bb73c53e52285c357a04d26b6bd8c1e9d7d25f306ecf2507b7e43c5a24dd0cec7ae4cd2225201
|
7
|
+
data.tar.gz: af99d1b73b2349ef830ccaf095b87bd9410374ddf43cfcf52bfba4c93bad60c174646bdb7399a031ff956eb3fb2f748b27c2c26eb68f4c28b9a670e617b2362e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -155,7 +155,7 @@ You are also able to restrict associations to specific scopes:
|
|
155
155
|
class User < ApplicationRecord
|
156
156
|
acts_as_belonger
|
157
157
|
belonger :conference_collaborations, 'Conference', scope: :collaboration
|
158
|
-
belonger :conference_attendings, '
|
158
|
+
belonger :conference_attendings, 'Conference', scope: :membership
|
159
159
|
end
|
160
160
|
|
161
161
|
class Conference < ApplicationRecord
|
@@ -1,52 +1,52 @@
|
|
1
|
-
module ActsAsBelongable
|
2
|
-
module Belongable
|
3
|
-
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
module ClassMethods
|
7
|
-
def acts_as_belongable
|
8
|
-
has_many :belongers, through: :belongable_belongings, source: :belonger
|
9
|
-
has_many :belongable_belongings, as: :belongable, class_name: 'Belonging', dependent: :destroy
|
10
|
-
end
|
11
|
-
|
12
|
-
def belongable name, source_type, options = {}
|
13
|
-
if options.has_key? :scope
|
14
|
-
belongable_belongings_with_scope options[:scope]
|
15
|
-
through = "belongable_belongings_#{options[:scope]}".to_sym
|
16
|
-
end
|
17
|
-
through ||= :belongable_belongings
|
18
|
-
has_many name.to_sym, through: through, source: :belonger, source_type: source_type.to_s
|
19
|
-
end
|
20
|
-
def belongable_belongings_with_scope scope
|
21
|
-
has_many "belongable_belongings_#{scope}".to_sym, -> { where(scope: scope.to_s) }, as: :belongable, class_name: 'Belonging', dependent: :destroy
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def add_to_belonger belonger, options = {}
|
26
|
-
options[:belonger] = belonger
|
27
|
-
self.belongable_belongings.create options
|
28
|
-
end
|
29
|
-
def add_to_belonger! belonger, options = {}
|
30
|
-
options[:belonger] = belonger
|
31
|
-
self.belongable_belongings.create! options
|
32
|
-
end
|
33
|
-
|
34
|
-
def create_belonger
|
35
|
-
belonging_options = options.delete
|
36
|
-
object =
|
37
|
-
self.add_to_belonger object, belonging_options
|
38
|
-
object
|
39
|
-
end
|
40
|
-
def create_belonger!
|
41
|
-
belonging_options = options.delete
|
42
|
-
object =
|
43
|
-
self.add_to_belonger! object, belonging_options
|
44
|
-
object
|
45
|
-
end
|
46
|
-
|
47
|
-
def belongers_with_scope scope, source_type = nil
|
48
|
-
self.belongable_belongings.where(scope: scope.to_s).map { |belonging| source_type.nil? || belonging.belonger.class.name == source_type ? belonging.belonger : nil }.compact
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
1
|
+
module ActsAsBelongable
|
2
|
+
module Belongable
|
3
|
+
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def acts_as_belongable
|
8
|
+
has_many :belongers, through: :belongable_belongings, source: :belonger
|
9
|
+
has_many :belongable_belongings, as: :belongable, class_name: 'Belonging', dependent: :destroy
|
10
|
+
end
|
11
|
+
|
12
|
+
def belongable name, source_type, options = {}
|
13
|
+
if options.has_key? :scope
|
14
|
+
belongable_belongings_with_scope options[:scope]
|
15
|
+
through = "belongable_belongings_#{options[:scope]}".to_sym
|
16
|
+
end
|
17
|
+
through ||= :belongable_belongings
|
18
|
+
has_many name.to_sym, through: through, source: :belonger, source_type: source_type.to_s
|
19
|
+
end
|
20
|
+
def belongable_belongings_with_scope scope
|
21
|
+
has_many "belongable_belongings_#{scope}".to_sym, -> { where(scope: scope.to_s) }, as: :belongable, class_name: 'Belonging', dependent: :destroy
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_to_belonger belonger, options = {}
|
26
|
+
options[:belonger] = belonger
|
27
|
+
self.belongable_belongings.create options
|
28
|
+
end
|
29
|
+
def add_to_belonger! belonger, options = {}
|
30
|
+
options[:belonger] = belonger
|
31
|
+
self.belongable_belongings.create! options
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_belonger _class, options = {}
|
35
|
+
belonging_options = options.delete(:belonging) || {}
|
36
|
+
object = _class.create options
|
37
|
+
self.add_to_belonger object, belonging_options
|
38
|
+
object
|
39
|
+
end
|
40
|
+
def create_belonger! _class, options = {}
|
41
|
+
belonging_options = options.delete(:belonging) || {}
|
42
|
+
object = _class.create! options
|
43
|
+
self.add_to_belonger! object, belonging_options
|
44
|
+
object
|
45
|
+
end
|
46
|
+
|
47
|
+
def belongers_with_scope scope, source_type = nil
|
48
|
+
self.belongable_belongings.where(scope: scope.to_s).map { |belonging| source_type.nil? || belonging.belonger.class.name == source_type ? belonging.belonger : nil }.compact
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -31,15 +31,15 @@ module ActsAsBelongable
|
|
31
31
|
self.belonger_belongings.create! options
|
32
32
|
end
|
33
33
|
|
34
|
-
def create_belongable
|
35
|
-
belonging_options = options.delete
|
36
|
-
object =
|
34
|
+
def create_belongable _class, options = {}
|
35
|
+
belonging_options = options.delete(:belonging) || {}
|
36
|
+
object = _class.create options
|
37
37
|
self.add_belongable object, belonging_options
|
38
38
|
object
|
39
39
|
end
|
40
|
-
def create_belongable!
|
41
|
-
belonging_options = options.delete
|
42
|
-
object =
|
40
|
+
def create_belongable! _class, options = {}
|
41
|
+
belonging_options = options.delete(:belonging) || {}
|
42
|
+
object = _class.create! options
|
43
43
|
self.add_belongable! object, belonging_options
|
44
44
|
object
|
45
45
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module ActsAsBelongable
|
2
|
-
|
3
|
-
VERSION = '
|
4
|
-
|
5
|
-
end
|
1
|
+
module ActsAsBelongable
|
2
|
+
|
3
|
+
VERSION = '2.1.2'
|
4
|
+
|
5
|
+
end
|
@@ -1 +1 @@
|
|
1
|
-
Now run `rails db:migrate` to add
|
1
|
+
Now run `rails db:migrate` to add acts_as_belongable to your database.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_belongable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Hübotter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|