forked from ActsAsParanoid/acts_as_paranoid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.rb
More file actions
36 lines (32 loc) · 1.59 KB
/
init.rb
File metadata and controls
36 lines (32 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class << ActiveRecord::Base
def belongs_to_with_published(association_id, options = {})
with_published = options.delete :with_published
returning belongs_to_without_published(association_id, options) do
if with_published
reflection = reflect_on_association(association_id)
association_accessor_methods(reflection, Caboose::Acts::BelongsToWithPublishedAssociation)
association_constructor_method(:build, reflection, Caboose::Acts::BelongsToWithPublishedAssociation)
association_constructor_method(:create, reflection, Caboose::Acts::BelongsToWithPublishedAssociation)
end
end
end
def has_many_without_published(association_id, options = {}, &extension)
with_published = options.delete :with_published
returning has_many_with_published(association_id, options, &extension) do
if options[:through] && !with_published
reflection = reflect_on_association(association_id)
collection_reader_method(reflection, Caboose::Acts::HasManyThroughWithoutPublishedAssociation)
collection_accessor_methods(reflection, Caboose::Acts::HasManyThroughWithoutPublishedAssociation, false)
end
end
end
alias_method_chain :belongs_to, :published
alias_method :has_many_with_published, :has_many
alias_method :has_many, :has_many_without_published
alias_method :exists_with_published?, :exists?
end
ActiveRecord::Base.send :include, Caboose::Acts::Viewable
ActiveRecord::Base.send :include, Caboose::Acts::ViewableFindWrapper
class << ActiveRecord::Base
alias_method_chain :acts_as_viewable, :find_wrapper
end