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: 59dcd128c5aad1441a5fb6994657e0ec3722a3aeee951847eb5f39ffa4aa2063
4
- data.tar.gz: fd348a047a138e6e0428ad5beaa8c8795264e1259cac600be55920564fd675ca
3
+ metadata.gz: b80c9a93bf4a2ab6180cc848d9fcf43084daeb88dd56bfc8995c2955eaae8cda
4
+ data.tar.gz: 0e384ccdd8fc420f4e3263697aec4bfd067d426b741ffec420405808b71bcbca
5
5
  SHA512:
6
- metadata.gz: 871ef6182d0efdb3f679563dbab71704de64a7480243025d80634c8c9f74b1b0048cdc5358a18aac8edba57ad04bd4bda0dee6ea51ce757df76902cbb8b315ec
7
- data.tar.gz: fdf4eabcec2641d5bcf0617b203c0d9231f597d4230f29abde7cd81b357bf18e0d96e1501c64f83a163f81d5a5bfc1ab68137b550626ddf4852e1c6e1a722b12
6
+ metadata.gz: ab7d4a5f9d99fc1eae0120f7eb96fc16f5b95146ce24c779a96bb73c53e52285c357a04d26b6bd8c1e9d7d25f306ecf2507b7e43c5a24dd0cec7ae4cd2225201
7
+ data.tar.gz: af99d1b73b2349ef830ccaf095b87bd9410374ddf43cfcf52bfba4c93bad60c174646bdb7399a031ff956eb3fb2f748b27c2c26eb68f4c28b9a670e617b2362e
data/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@
4
4
 
5
5
  * nothing yet
6
6
 
7
+ ### 2.1.2 - 2018/05/24
8
+
9
+ * enhancements
10
+ * pass classes to methods instead of their names
11
+ * bugfixes
12
+ * fixed `undefined method '[]=' for nil:NilClass`
13
+
7
14
  ### 1.1.2 - 2018/02/05
8
15
 
9
16
  * bugfixes
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, 'User', scope: :membership
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 class_name, options = {}
35
- belonging_options = options.delete :belonging
36
- object = class_name.constantize.create options
37
- self.add_to_belonger object, belonging_options
38
- object
39
- end
40
- def create_belonger! class_name, options = {}
41
- belonging_options = options.delete :belonging
42
- object = class_name.constantize.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
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 class_name, options = {}
35
- belonging_options = options.delete :belonging
36
- object = class_name.constantize.create options
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! class_name, options = {}
41
- belonging_options = options.delete :belonging
42
- object = class_name.constantize.create! options
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 = '1.1.2'
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 acts_as_favoritor to your database.
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: 1.1.2
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-02-05 00:00:00.000000000 Z
11
+ date: 2018-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties