accepts_nested_ids 0.1.0 → 0.2.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
- SHA1:
3
- metadata.gz: 17cafe27c546d2cba99337b3fe75a190805c048a
4
- data.tar.gz: ccc40cfda5235a83e9ecc0cc036e5a01d809462b
2
+ SHA256:
3
+ metadata.gz: d46bd5aa6f826717d35c0c85d7250b7483e9d9e6b2db19e528ee2aa4d589dd5e
4
+ data.tar.gz: e548f69560b40eb4420ad9a7c236a7d2fe76a72d1fd6d791b1c61c0aca06a9ad
5
5
  SHA512:
6
- metadata.gz: fb214073171ad689b195d39c159eed73555ed42080a84726b53863790a6e535a4f8c666605884dc802b76b25a388ea36bda61b01e9d7bb39e35cd311f3cf6ee0
7
- data.tar.gz: c02d8406d6aa4dc8ce0f4e532b9cd9799b66a7c1f5c1556773c31397c9808a089f6fcc2b8ac3c78a4c050d2cdcb4eb5a954e2c7727bbbf959cbed3d8499381c8
6
+ metadata.gz: 64b38ffe75735cf1959795f83dba1c3c94741bcf2cd93e2fd0cdcee631a7969f3a09b96888b584c23ac9acefc0b01f5760564e2b4676b1f3818de32ea14ee540
7
+ data.tar.gz: bcd80ed8f969985f315e2717fa5ee78928616f52503e86fc133dc0121fe504344b722664539904326b4eb2893a3990ed02cb0d815061b36758a570e22453cf18
data/.travis.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.2.2
4
- before_install: gem install bundler -v 1.10.3
4
+ before_install: gem install bundler -v 2.2.7
data/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ ## 0.2.2 (2021-02-04)
2
+
3
+ Ensure this works with Ruby 3.0.0 by adding the #attribute method within any class to extend ActiveRecord in order to create those helper methods.
4
+ Example:
5
+ `class Company < ActiveRecord::Base
6
+ include AcceptsNestedIds
7
+ has_many :users
8
+ accepts_nested_ids_for :users
9
+ attribute :user_ids
10
+ end`
11
+
12
+
13
+ ## 0.2.1 (2016-02-05)
14
+
15
+ Ensure empty array of nested associations is loaded, to handle situations where a sub class does not define its own associations and the intersection between base and sub class associations was failing.
16
+
17
+ ## 0.2.0 (2016-02-05)
18
+
19
+ Fix for associations defined on a subclass not being saved.
20
+
21
+ ## 0.1.2 (2015-08-12)
22
+
23
+ Fix for STI.
data/README.md CHANGED
@@ -17,11 +17,7 @@ class Project < ActiveRecord::Base
17
17
  has_many :project_users
18
18
  has_many :users, through: :project_users
19
19
  validates :name, presence: true
20
- end
21
-
22
- class User < ActiveRecord::Base
23
- has_many :project_users
24
- has_many :projects, through: :project_users
20
+ attribute :user_ids
25
21
  end
26
22
  ```
27
23
 
@@ -84,7 +80,10 @@ class Project < ActiveRecord::Base
84
80
  has_many :project_users
85
81
  has_many :users, through: :project_users
86
82
  accepts_nested_ids_for :users
83
+ attribute :user_ids
87
84
  end
85
+
86
+ project.user_ids = [...]
88
87
  ```
89
88
 
90
89
  ### When your association has a custom name:
@@ -95,9 +94,14 @@ class Project < ActiveRecord::Base
95
94
  has_many :project_users
96
95
  has_many :included_users, through: :project_users, source: :user
97
96
  accepts_nested_ids_for included_users: "User"
97
+ attribute :user_ids
98
98
  end
99
+
100
+ project.included_user_ids = [...]
99
101
  ```
100
102
 
103
+ When using a custom association name, you must specify the actual class name as a second arg, in this case "User".
104
+
101
105
  ### Mix and match as desired:
102
106
 
103
107
  ```ruby
@@ -107,10 +111,12 @@ class Project < ActiveRecord::Base
107
111
  has_many :project_users
108
112
  has_many :included_users, through: :project_users, source: :user
109
113
  accepts_nested_ids_for :documents, included_users: "User"
114
+ attribute :user_ids
110
115
  end
111
- ```
112
116
 
113
- You can now comfortably set `document_ids` or `user_ids` on a `Project` without making a mess of things.
117
+ project.document_ids = [...]
118
+ project.included_user_ids = [...]
119
+ ```
114
120
 
115
121
  ## Development
116
122
 
@@ -118,6 +124,9 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
118
124
 
119
125
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
120
126
 
127
+ ## Requirements
128
+ Requires Activemodel & Activerecord `6.1.1` or higher
129
+
121
130
  ## Contributing
122
131
 
123
132
  Bug reports and pull requests are welcome on GitHub at https://github.com/uberllama/accepts_nested_ids.
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
  spec.add_dependency "activesupport", ">= 3.0.0"
20
20
  spec.add_development_dependency "activerecord", ">= 4.2.3"
21
- spec.add_development_dependency "bundler", "~> 1.10"
21
+ spec.add_development_dependency "bundler", "~> 2.2.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "rspec"
24
24
  spec.add_development_dependency "sqlite3"
@@ -1,4 +1,5 @@
1
1
  require "accepts_nested_ids/version"
2
+ require "accepts_nested_ids/nested_id_association"
2
3
  require "active_support/concern"
3
4
  require "active_support/core_ext/string/inflections"
4
5
 
@@ -23,7 +24,8 @@ module AcceptsNestedIds
23
24
  # end
24
25
  #
25
26
  def save_nested_id_associations
26
- self.class.nested_id_associations.each do |nested_id_association|
27
+ aggregated_id_associations = self.class.nested_id_associations | self.class.base_class.nested_id_associations
28
+ aggregated_id_associations.each do |nested_id_association|
27
29
  if instance_variable_get("@#{nested_id_association.ids_attr}")
28
30
  association_class = nested_id_association.class_name.constantize
29
31
  ids = send(nested_id_association.ids_attr)
@@ -34,22 +36,15 @@ module AcceptsNestedIds
34
36
 
35
37
  module ClassMethods
36
38
 
37
- # Simple object that contains information about a nested ID association
38
- #
39
- # @param attr [Symbol] association attribute (ex: :documents)
40
- # @param ids_attr [String] ids association attribute (ex: 'document_ids')
41
- # @param class_name [String] association class name (ex: 'Document')
42
- class NestedIdAssociation < Struct.new(:attr, :ids_attr, :class_name); end
43
-
44
39
  # Sets up defered save and dirty tracking for the specified associations
45
40
  #
46
41
  # @example When class_name can be inferred from association name
47
42
  # include AcceptsNestedIds
48
- # accepts_nested_ids_for :documents, :carrier_companies
43
+ # accepts_nested_ids_for :documents, :users
49
44
  #
50
45
  # @example When class_name is different from association name
51
46
  # include AcceptsNestedIds
52
- # accepts_nested_ids_for :documents, included_carrier_companies: "CarrierCompany"
47
+ # accepts_nested_ids_for :documents, included_users: "User"
53
48
  #
54
49
  # @param args [Array]
55
50
  def accepts_nested_ids_for(*args)
@@ -82,14 +77,14 @@ module AcceptsNestedIds
82
77
  define_method("#{nested_id_association.ids_attr}=") do |value|
83
78
  return if send(nested_id_association.ids_attr) == value
84
79
  attribute_will_change!(nested_id_association.ids_attr)
85
- instance_variable_set("@#{nested_id_association.ids_attr}", value)
80
+ instance_variable_set(:"@#{nested_id_association.ids_attr}", value)
86
81
  end
87
82
 
88
83
  end
89
84
  end
90
85
 
91
86
  def nested_id_associations
92
- @_nested_id_associations
87
+ @_nested_id_associations || []
93
88
  end
94
89
 
95
90
  private
@@ -97,11 +92,11 @@ module AcceptsNestedIds
97
92
  # Map module args into array of NestedIdAssociation objects with supporting properties
98
93
  #
99
94
  # @example
100
- # accepts_nested_ids_for :documents, included_carrier_companies: "CarrierCompany"
95
+ # accepts_nested_ids_for :documents, included_users: "User"
101
96
  # =>
102
97
  # [
103
98
  # { attr: :documents:, ids_attr: "document_ids", class_name: "Document"},
104
- # { attr: :included_carrier_companies, ids_attr: "included_carrier_company_ids", class_name: "CarrierCompany" }
99
+ # { attr: :included_users, ids_attr: "included_user_ids", class_name: "User" }
105
100
  # ]
106
101
  #
107
102
  # @param args [Array]
@@ -0,0 +1,11 @@
1
+ module AcceptsNestedIds
2
+
3
+ # Simple object that contains information about a nested ID association
4
+ #
5
+ # @param attr [Symbol] association attribute (ex: :documents)
6
+ # @param ids_attr [String] ids association attribute (ex: 'document_ids')
7
+ # @param class_name [String] association class name (ex: 'Document')
8
+ class NestedIdAssociation < Struct.new(:attr, :ids_attr, :class_name)
9
+ end
10
+
11
+ end
@@ -1,3 +1,3 @@
1
1
  module AcceptsNestedIds
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: accepts_nested_ids
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuval Kordov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2015-07-26 00:00:00.000000000 Z
12
+ date: 2021-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '1.10'
48
+ version: 2.2.7
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '1.10'
55
+ version: 2.2.7
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rake
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -106,6 +106,7 @@ files:
106
106
  - ".gitignore"
107
107
  - ".rspec"
108
108
  - ".travis.yml"
109
+ - CHANGELOG.md
109
110
  - Gemfile
110
111
  - LICENSE.txt
111
112
  - README.md
@@ -114,6 +115,7 @@ files:
114
115
  - bin/console
115
116
  - bin/setup
116
117
  - lib/accepts_nested_ids.rb
118
+ - lib/accepts_nested_ids/nested_id_association.rb
117
119
  - lib/accepts_nested_ids/version.rb
118
120
  homepage: http://github.com/uberllama/accepts_nested_ids
119
121
  licenses:
@@ -134,8 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
136
  - !ruby/object:Gem::Version
135
137
  version: '0'
136
138
  requirements: []
137
- rubyforge_project:
138
- rubygems_version: 2.4.6
139
+ rubygems_version: 3.0.8
139
140
  signing_key:
140
141
  specification_version: 4
141
142
  summary: Predictable nesting of associations via ID