dirty_history 0.6.7 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.7
1
+ 0.7.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "dirty_history"
8
- s.version = "0.6.7"
8
+ s.version = "0.7.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Gavin Todes"]
12
- s.date = "2012-10-11"
12
+ s.date = "2012-11-12"
13
13
  s.description = "Dirty History is a simple gem that allows you to keep track of changes to specific fields in your Rails models using the ActiveRecord::Dirty module."
14
14
  s.email = "gavin.todes@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -30,9 +30,6 @@ module DirtyHistory
30
30
  return if metaclass.included_modules.include?(DirtyHistory::Mixin::ObjectInstanceMethods)
31
31
 
32
32
  has_many :dirty_history_records, :as => :object, :dependent => :destroy
33
- before_save :set_dirty_history_changes
34
- after_save :save_dirty_history
35
-
36
33
  attr_accessor :dirty_history_changes, :initialize_dirty_history
37
34
  cattr_accessor :dirty_history_columns
38
35
 
@@ -40,6 +37,10 @@ module DirtyHistory
40
37
  self.dirty_history_columns ||= []
41
38
 
42
39
  if args.present?
40
+
41
+ before_save :set_dirty_history_changes
42
+ after_save :save_dirty_history
43
+
43
44
  args.each do |arg|
44
45
  if [String,Symbol].include?(arg.class)
45
46
  arg = arg.to_sym
@@ -114,7 +115,17 @@ module DirtyHistory
114
115
 
115
116
  self.dirty_history_records << dhr
116
117
  end
117
-
118
+
119
+ def history_for_column column, options={}
120
+ options[:sort] = true if options[:sort].blank?
121
+
122
+ records = dirty_history_records.for_column(column)
123
+ records = records.send(*options[:scope]) if options[:scope]
124
+ records = records.order_asc if options[:sort]
125
+
126
+ options[:return_objects] ? records : records.map { |s| s.new_value }
127
+ end
128
+
118
129
  end # ObjectInstanceMethods
119
130
 
120
131
  module CreatorInstanceMethods
@@ -7,7 +7,7 @@ class DirtyHistoryRecord < ActiveRecord::Base
7
7
  scope :created_by, lambda { |creator| where(["dirty_history_records.creator_id = ? AND dirty_history_records.creator_type = ?", creator.id, creator.class.name]) }
8
8
  scope :not_created_by, lambda { |non_creator| where(["dirty_history_records.creator_id <> ? OR dirty_history_records.creator_type <> ?", non_creator.id, non_creator.class.name]) }
9
9
  scope :for_object_type, lambda { |object_type| where(:object_type => object_type.to_s.classify) }
10
- scope :for_attribute, lambda { |attribute| where(:column_name => attribute.to_s) }
10
+ scope :for_column, lambda { |column| where(:column_name => column.to_s) }
11
11
  scope :created_in_range, lambda { |range| created_at_gte(range.first).created_at_lte(range.last) }
12
12
  scope :created_at_gte, lambda { |date| created_at_lte_or_gte(date,"gte") }
13
13
  scope :created_at_lte, lambda { |date| created_at_lte_or_gte(date,"lte") }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dirty_history
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.7
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-11 00:00:00.000000000 Z
12
+ date: 2012-11-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: shoulda
@@ -2345,7 +2345,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
2345
2345
  version: '0'
2346
2346
  segments:
2347
2347
  - 0
2348
- hash: -1194552902652385901
2348
+ hash: 1980104175471203861
2349
2349
  required_rubygems_version: !ruby/object:Gem::Requirement
2350
2350
  none: false
2351
2351
  requirements: