kentouzu 0.2.3 → 0.2.4

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: b73eef9055fa6ce7db052eebb04b57717110e2c9
4
- data.tar.gz: c9d8cfbf7a2453a15f6506af1a9c662b58c1ca96
3
+ metadata.gz: eb499faf4fde2bf84fbd4404d3c88b230650cdea
4
+ data.tar.gz: 82f10c25b9016c380727e9ca4246c7924916d08f
5
5
  SHA512:
6
- metadata.gz: beacbda4ff7179b36c6b039f935b246d8826f10108dd4ffacae4f6350a8337a649553118910f5205df8bf2206300ce48e3c1e9a9dbef94294283c0ba520c13a4
7
- data.tar.gz: 7a706e1304061cd246f14d76891cfe262d1323e4508d2ba71f140d47f52fa2153d5d74b46649848733d5f629b78721d38b1cbf96a8546ddfc46d5f94b5e98ac6
6
+ metadata.gz: d6a8a057b323af96a6f1883cfbaf8ad43441b0dad9982da223764274b07d5bb8ed7b62c275d08a468a74ed23b8ca6e127c2e8f84125b8dd1a1c96246538fdbf2
7
+ data.tar.gz: 86ac6fc253293aab3b297c646979a24c41e67d89bedd5c4506c47188c4c16110052f73f9b5aa7aba3d0323ef56d29c4e854915d555117d11f528e2635f4eb2de
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v0.2.4
2
+
3
+ * Keep track of `has_and_belongs_to_many` associations.
4
+
1
5
  ## v0.2.3
2
6
 
3
7
  * Ignore `has_many` associations if they have the `:through` option.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kentouzu (0.2.3)
4
+ kentouzu (0.2.4)
5
5
  activerecord (>= 3.0)
6
6
  railties (>= 3.0)
7
7
 
@@ -91,10 +91,14 @@ class Draft < ActiveRecord::Base
91
91
 
92
92
  has_many_associations = model.class.reflect_on_all_associations(:has_many).reject { |association| association.name == :drafts || association.options.keys.include?(:through) }.map { |association| association.name }
93
93
 
94
+ has_and_belongs_to_many_associations = model.class.reflect_on_all_associations(:has_and_belongs_to_many).map { |association| association.plural_name }
95
+
94
96
  loaded_object.each do |key, value|
95
97
  if model.respond_to?("#{key}=")
96
98
  if has_many_associations.include?(key.to_sym)
97
99
  model.send "#{key}=".to_sym, value.map { |v| model.send(key.to_sym).proxy_association.klass.new(v) }
100
+ elsif has_and_belongs_to_many_associations.include?(key.gsub('_ids', '').pluralize)
101
+ model.send "#{key.gsub('_ids', '').pluralize}=".to_sym, model.class.reflect_on_all_associations(:has_and_belongs_to_many).select { |association| association.plural_name == key.gsub('_ids', '').pluralize }.first.class_name.constantize.where(id: value)
98
102
  else
99
103
  model.send :write_attribute, key.to_sym, value
100
104
  end
@@ -229,7 +229,7 @@ module Kentouzu
229
229
  :event => draft_event.to_s,
230
230
  :source_type => Kentouzu.source.present? ? Kentouzu.source.class.to_s : nil,
231
231
  :source_id => Kentouzu.source.present? ? Kentouzu.source.id : nil,
232
- :object => self.as_json(include: self.class.reflect_on_all_associations(:has_many).reject { |association| association.name == :drafts || association.options.keys.include?(:through) }.map { |association| association.name }).to_yaml
232
+ :object => self.as_json(include: draftable_has_many_associations, methods: draftable_has_and_belongs_to_many_associations).to_yaml
233
233
  }
234
234
 
235
235
  @draft = Draft.new(merge_metadata(data))
@@ -256,6 +256,20 @@ module Kentouzu
256
256
 
257
257
  (on_events.empty? || on_events.include?(draft_event)) && (if_condition.blank? || if_condition.call(self)) && !unless_condition.try(:call, self)
258
258
  end
259
+
260
+ def draftable_associations
261
+ draftable_has_many_associations + draftable_has_and_belongs_to_many_associations
262
+ end
263
+
264
+ def draftable_has_many_associations
265
+ self.class.reflect_on_all_associations(:has_many).reject { |association| association.name == :drafts || association.options.keys.include?(:through) }.map { |association| association.name }
266
+ end
267
+
268
+ def draftable_has_and_belongs_to_many_associations
269
+ self.class.reflect_on_all_associations(:has_and_belongs_to_many).map { |association| "#{association.plural_name.singularize}_ids".to_sym }
270
+
271
+ #self.class.reflect_on_all_associations(:has_and_belongs_to_many).map { |association| association.name }
272
+ end
259
273
  end
260
274
  end
261
275
  end
@@ -1,3 +1,3 @@
1
1
  module Kentouzu
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kentouzu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Eshbaugh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-23 00:00:00.000000000 Z
11
+ date: 2014-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties