acts_as_pack_rat 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ #require 'acts_as_pack_rat'
@@ -0,0 +1,77 @@
1
+ class ActiveRecord::Base
2
+
3
+ class << self
4
+
5
+ def acts_as_pack_rat
6
+ alias_method :destroy_without_callbacks!, :destroy_without_callbacks
7
+ class << self
8
+ [:find, :count, :sum, :calculate, :average, :minimum, :maximum].each do |m|
9
+ alias_method "ar_#{m}", m
10
+ alias_method "#{m}_with_deleted", "ar_#{m}"
11
+ end
12
+
13
+ [:find, :count].each do |m|
14
+ eval %{
15
+ def #{m}(*args)
16
+ # puts "acts_as_pack_rat: #{m}!"
17
+ do_without_deleted {ar_#{m}(*args)}
18
+ end
19
+ }
20
+ end
21
+
22
+ [:average, :minimum, :maximum, :sum].each do |m|
23
+ eval %{
24
+ def #{m}(column_name, options = {})
25
+ # puts "acts_as_pack_rat: #{m}!"
26
+ do_without_deleted {ar_#{m}(column_name, options)}
27
+ end
28
+ }
29
+ end
30
+
31
+ def exists_with_deleted?(id_or_conditions)
32
+ # puts "acts_as_pack_rat: exists_with_deleted?!"
33
+ !find_with_deleted(:first, :select => "#{table_name}.#{primary_key}", :conditions => expand_id_conditions(id_or_conditions)).nil?
34
+ rescue ActiveRecord::ActiveRecordError
35
+ false
36
+ end
37
+ end
38
+
39
+ alias_method :ar_destroy, :destroy
40
+
41
+ class_eval do
42
+ def destroy
43
+ unless new_record?
44
+ # puts "acts_as_pack_rat: destroy"
45
+ return false if callback(:before_destroy) == false
46
+ if self.respond_to?(:status_id)
47
+ self.status = Status.deleted
48
+ else
49
+ self.deleted_at = Time.now
50
+ end
51
+ result = self.send(:update_without_callbacks)
52
+ callback(:after_destroy)
53
+ freeze
54
+ return result
55
+ end
56
+ end
57
+
58
+ def destroy!
59
+ ar_destroy
60
+ end
61
+
62
+ end
63
+
64
+ protected
65
+ def do_without_deleted(&block)
66
+ if self.column_names.include?("status_id")
67
+ with_scope({:find => { :conditions => ["#{table_name}.status_id != ?", Status.deleted.id] } }, :merge, &block)
68
+ else
69
+ with_scope({:find => { :conditions => ["#{table_name}.deleted_at IS NULL"] } }, :merge, &block)
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1,5 @@
1
+ --- !ruby/object:RubyForgeConfig
2
+ gem_name: acts_as_pack_rat
3
+ package: acts_as_pack_rat
4
+ project: magrathea
5
+ version: 1.0.0
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: acts_as_pack_rat
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.0
7
+ date: 2007-11-14 00:00:00 -05:00
8
+ summary: acts_as_pack_rat
9
+ require_paths:
10
+ - lib
11
+ - lib
12
+ - lib
13
+ - lib/tasks
14
+ email:
15
+ homepage:
16
+ rubyforge_project: magrathea
17
+ description: "acts_as_pack_rat was developed by: markbates"
18
+ autorequire:
19
+ - acts_as_pack_rat
20
+ default_executable:
21
+ bindir: bin
22
+ has_rdoc: false
23
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
24
+ requirements:
25
+ - - ">"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.0.0
28
+ version:
29
+ platform: ruby
30
+ signing_key:
31
+ cert_chain:
32
+ post_install_message:
33
+ authors:
34
+ - markbates
35
+ files:
36
+ - init.rb
37
+ - lib/acts_as_pack_rat.rb
38
+ - lib/tasks/rubyforge_config.yml
39
+ test_files: []
40
+
41
+ rdoc_options: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ executables: []
46
+
47
+ extensions: []
48
+
49
+ requirements: []
50
+
51
+ dependencies: []
52
+