track_history 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,16 +18,16 @@ module TrackHistory
18
18
  # Make a model historical
19
19
  # Takes a hash of options, which can only be :model_name to force a different model name
20
20
  # Default model name is ModelHistory
21
- def track_history(options = {})
21
+ def track_history(options = {}, &block)
22
22
  options.assert_valid_keys(:model_name, :table_name)
23
23
  @historical_fields = []
24
24
  @historical_tracks = {}
25
25
  define_historical_model(self, options[:model_name], options[:table_name])
26
- yield if block_given?
26
+ module_eval(&block) if block_given?
27
27
  end
28
28
 
29
29
  def annotate(field, &block) # haha
30
- @historical_tracks ||= []
30
+ @historical_tracks ||= {}
31
31
  @historical_tracks[field] = block
32
32
  unless @klass_reference.columns_hash.has_key?(field.is_a?(Symbol) ? field.to_s : field)
33
33
  raise ActiveRecord::StatementInvalid.new("No such attribute '#{field}' on #{@klass_reference.name}")
@@ -66,7 +66,7 @@ module TrackHistory
66
66
 
67
67
  # tell the other class about us
68
68
  # purposely don't define these until after getting historical_fields
69
- has_many :histories, :class_name => model_name, :order => 'created_at desc', :dependent => :destroy
69
+ has_many :histories, :class_name => model_name, :order => 'created_at desc'
70
70
  before_update :record_historical_changes
71
71
 
72
72
  end
@@ -83,9 +83,7 @@ module TrackHistory
83
83
  end
84
84
 
85
85
  def to_s
86
- modifications.map do |field|
87
- "#{field}: " + send(:"#{field}_before") + '=>' + send(:"#{field}_after")
88
- end.join(', ')
86
+ 'modified ' + modifications.join(', ') + " on #{historical_relation}"
89
87
  end
90
88
 
91
89
  end
@@ -1,5 +1,5 @@
1
1
  module TrackHistory
2
2
 
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: track_history
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Crepezzi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-06 00:00:00 -05:00
18
+ date: 2011-01-10 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency