acts_as_statused 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/acts_as_statused.rb +57 -50
  2. metadata +2 -2
@@ -8,74 +8,81 @@ module ActiveRecord #:nodoc:
8
8
 
9
9
  module ClassMethods
10
10
  def acts_as_statused(options = {}, &extension)
11
- # don't allow multiple calls
12
- return if self.included_modules.include?(ActiveRecord::Acts::Statused::ActMethods)
11
+ begin
12
+ # don't allow multiple calls
13
+ return if self.included_modules.include?(ActiveRecord::Acts::Statused::ActMethods)
13
14
 
14
- send :include, ActiveRecord::Acts::Statused::ActMethods
15
+ send :include, ActiveRecord::Acts::Statused::ActMethods
15
16
 
16
- valid_status = []
17
- valid_statuses = options[:only] if options.is_a?(Hash)
17
+ valid_status = []
18
+ valid_statuses = options[:only] if options.is_a?(Hash)
18
19
 
19
- class_name = options.to_s if options.is_a?(Symbol) || options.is_a?(String)
20
- class_name = options[:class_name] if options.is_a?(Hash)
21
- class_name = "Status" if class_name.blank?
20
+ class_name = options.to_s if options.is_a?(Symbol) || options.is_a?(String)
21
+ class_name = options[:class_name] if options.is_a?(Hash)
22
+ class_name = "Status" if class_name.blank?
22
23
 
23
- #puts "class_name = #{class_name}"
24
+ #puts "!!!!!!!!!!!class_name = #{class_name}"
24
25
 
25
- class_eval do
26
- belongs_to :status
26
+ class_eval do
27
+ belongs_to :status
27
28
 
28
- attr_accessor :previous_status
29
+ attr_accessor :previous_status
29
30
 
30
- def after_find
31
- self.previous_status = self.status if respond_to?:status_id
32
- end
31
+ def after_find
32
+ self.previous_status = self.status if respond_to?:status_id
33
+ end
33
34
 
34
- def status
35
- eval "#{class_name}.get(self.status_id)"
36
- end
35
+ eval %{
36
+ def status
37
+ #{class_name}.get(self.status_id)
38
+ end
39
+ }
37
40
 
38
- def has_status_changed?
39
- return self.previous_status != self.status
40
- end
41
+ def has_status_changed?
42
+ return self.previous_status != self.status
43
+ end
41
44
 
42
- begin
43
- rows = eval "#{class_name}.find(:all)"
44
- rows.each do |status| #get all the statuses in the db.
45
- # only define valid statuses
46
- # EX: acts_as_statused :only => ['active', 'inactive', 'pending']
47
- next unless valid_statuses.blank? || valid_statuses.include?(status.name)
45
+ begin
46
+ rows = eval "#{class_name}.find(:all)"
47
+ rows.each do |status| #get all the statuses in the db.
48
+ # only define valid statuses
49
+ # EX: acts_as_statused :only => ['active', 'inactive', 'pending']
50
+ next unless valid_statuses.blank? || valid_statuses.include?(status.name)
48
51
 
49
- define_method("status_is_#{status.name}?") do #define the method status_is_statusname?
50
- return self.status_id == status.id
51
- end
52
+ define_method("status_is_#{status.name}?") do #define the method status_is_statusname?
53
+ return self.status_id == status.id
54
+ end
55
+ end
56
+ rescue
52
57
  end
53
- rescue
54
- end
55
58
 
56
- end
57
-
58
- %w{save update create destroy}.each do |verb|
59
- define_method("before_#{verb}_status_changed") do
60
- #puts "before_#{verb}_status_changed"
61
59
  end
60
+
61
+ %w{save update create destroy}.each do |verb|
62
+ define_method("before_#{verb}_status_changed") do
63
+ #puts "before_#{verb}_status_changed"
64
+ end
62
65
 
63
- define_method("after_#{verb}_status_changed") do
64
- #puts "after_#{verb}_status_changed"
65
- end
66
+ define_method("after_#{verb}_status_changed") do
67
+ #puts "after_#{verb}_status_changed"
68
+ end
66
69
 
67
- define_method("do_before_#{verb}_status_changed") do
68
- eval %{before_#{verb}_status_changed if self.has_status_changed?}
69
- end
70
+ define_method("do_before_#{verb}_status_changed") do
71
+ eval %{before_#{verb}_status_changed if self.has_status_changed?}
72
+ end
70
73
 
71
- define_method("do_after_#{verb}_status_changed") do
72
- eval %{after_#{verb}_status_changed if self.has_status_changed?}
73
- end
74
+ define_method("do_after_#{verb}_status_changed") do
75
+ eval %{after_#{verb}_status_changed if self.has_status_changed?}
76
+ end
74
77
 
75
- eval %{
76
- before_#{verb} :do_before_#{verb}_status_changed
77
- after_#{verb} :do_after_#{verb}_status_changed
78
- }
78
+ eval %{
79
+ before_#{verb} :do_before_#{verb}_status_changed
80
+ after_#{verb} :do_after_#{verb}_status_changed
81
+ }
82
+ end
83
+ rescue => ex
84
+ puts "Error in acts_as_statused: #{ex.message}"
85
+ puts ex.backtrace
79
86
  end
80
87
  end
81
88
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: acts_as_statused
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.1
7
- date: 2007-02-27 00:00:00 -05:00
6
+ version: 1.0.2
7
+ date: 2007-02-28 00:00:00 -05:00
8
8
  summary: Acts as Statused
9
9
  require_paths:
10
10
  - lib