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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/kentouzu/draft.rb +4 -0
- data/lib/kentouzu/has_drafts.rb +15 -1
- data/lib/kentouzu/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb499faf4fde2bf84fbd4404d3c88b230650cdea
|
4
|
+
data.tar.gz: 82f10c25b9016c380727e9ca4246c7924916d08f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6a8a057b323af96a6f1883cfbaf8ad43441b0dad9982da223764274b07d5bb8ed7b62c275d08a468a74ed23b8ca6e127c2e8f84125b8dd1a1c96246538fdbf2
|
7
|
+
data.tar.gz: 86ac6fc253293aab3b297c646979a24c41e67d89bedd5c4506c47188c4c16110052f73f9b5aa7aba3d0323ef56d29c4e854915d555117d11f528e2635f4eb2de
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/kentouzu/draft.rb
CHANGED
@@ -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
|
data/lib/kentouzu/has_drafts.rb
CHANGED
@@ -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:
|
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
|
data/lib/kentouzu/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2014-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|