historyable 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTM5ODJlNzZkMzQ0YzUyZGRhNDUzMzM4MjhhZTIwODRiMGUzMmM0Yg==
4
+ YTk1ODJjMGVlYmQ3YzJmYWFjNzU2MjQ2YzM5MDRiMGJmOGZlZThkYQ==
5
5
  data.tar.gz: !binary |-
6
- YTE5MWRmNWJhNGUyNDhmYzBkYjNjMTNmZjRkZDA0ZjlmYmQzNjBiOQ==
7
- !binary "U0hBNTEy":
6
+ OGY2N2QzYzhkMWZkOTZjNTlhNGMyOTY3YTFkODc3ZGFlMjk3ZjdiYQ==
7
+ SHA512:
8
8
  metadata.gz: !binary |-
9
- ZWYzNDQ2NTMyYjc1OWVhODJhZmUxMjg5NGQ1ZWQzMDllY2JiN2M0ZTdiYmJk
10
- YThhODc1NjFhNmU4YjJmMzQwOWJkNzQ1ODUyNjI1ODVmMjdiN2MxOGMzOTBi
11
- NGM5NmVlMzRmNGFlZTFjN2UyZGYxYWM4YTRkYjQyNjE5OTY2MDU=
9
+ YmFhNjhlMTY1YjFlNGI1ZjhiMTA1NjRjMmExZjYzYTlkNmM5Mjc5OTI2MTM5
10
+ YjY1OGExNDcyMTUxMWM1YjdiYmYyNzg4Y2RmM2IzNDM3MmQxZTllYzFiOTk4
11
+ ZDZiMGU4OGNjMGVhOGZkNThmZDYwZjE0NTg1YjhkNTQwZjc0YTQ=
12
12
  data.tar.gz: !binary |-
13
- NmMyYjg2NWI2ZGM4ZjU1MDk2ODhhN2VkZmNjNGJiMzQzOTRlNzdkYzMzYzI1
14
- Y2ZhMzY1NmE3ODljZDE5OWVkYjFiMmNiOTJkMDkxMTBiOGIzOTU5ZWNmZGM1
15
- M2YyMWQxNzNhYTE3ZWM1MWJhZWY0ODNkMzZkODZmZDE3ODE5MjQ=
13
+ NGE5OWQ4NzI3Y2RiODg3YmZkNDM0NTkzY2Y4NTUwNDJjNGZmYTU5MzRjZTk0
14
+ OTc0OTUyMGQyYmZjZmRkMGQ5NzI3MzZkMGEwOGM3M2Q3M2Y2MzAzODAwOWFh
15
+ YmJlYzYxMWUyMGU1NDU3ZDE4MzhmYWYzOWQxMjM2N2JhMzI1NWM=
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/historyable.rb CHANGED
@@ -1,10 +1,10 @@
1
- require "historyable/version"
1
+ require 'historyable/version'
2
2
 
3
- require "active_record"
4
- require "historyable/change"
3
+ require 'active_record'
4
+ require 'historyable/change'
5
5
 
6
6
  module Historyable
7
- class Item < Struct.new(:attribute_name, :association_name); end
7
+ Item = Struct.new(:attribute_name, :association_name)
8
8
 
9
9
  extend ActiveSupport::Concern
10
10
 
@@ -32,69 +32,78 @@ module Historyable
32
32
  dependent: :destroy
33
33
  end
34
34
 
35
-
36
35
  # Instance methods
37
36
  historyable_items.each do |historyable|
37
+ define_historyable_attribute_history_raw(historyable)
38
+ define_historyable_attribute_history(historyable)
39
+ define_historyable_attribute_history?(historyable)
40
+ end
38
41
 
39
- # attribute_history_raw
40
- #
41
- # @example
42
- #
43
- # @user.name_history_raw
44
- #
45
- # @return [ActiveRecord::Relation]
46
- define_method("#{historyable.attribute_name.to_s}_history_raw") do
47
- send(historyable.association_name)
48
- .where(object_attribute: historyable.attribute_name)
49
- .order('created_at DESC')
50
- .select(:object_attribute_value, :created_at)
51
- end
42
+ # Callbacks
43
+ around_save :save_changes
44
+ end
52
45
 
53
46
 
54
- # attribute_history
55
- #
56
- # @example
57
- #
58
- # @user.name_history
59
- #
60
- # @return [Array]
61
- define_method("#{historyable.attribute_name.to_s}_history") do
62
- unless instance_variable_get("@#{historyable.attribute_name.to_s}_history".to_sym)
63
- array = []
64
-
65
- records = send("#{historyable.attribute_name}_history_raw")
66
- .pluck(:object_attribute_value, :created_at)
67
- records.map do |attribute_value, created_at|
68
- hash = HashWithIndifferentAccess.new
69
- hash[:attribute_value] = attribute_value
70
- hash[:changed_at] = created_at
71
-
72
- array << hash
73
- end
74
-
75
- # Sets attribute_history cache
76
- instance_variable_set("@#{historyable.attribute_name.to_s}_history".to_sym, array)
77
- array
78
- else
79
- instance_variable_get("@#{historyable.attribute_name.to_s}_history".to_sym)
47
+ private
48
+
49
+ # attribute_history_raw
50
+ #
51
+ # @example
52
+ #
53
+ # @user.name_history_raw
54
+ #
55
+ # @return [ActiveRecord::Relation]
56
+ def define_historyable_attribute_history_raw(historyable)
57
+ define_method("#{historyable.attribute_name.to_s}_history_raw") do
58
+ send(historyable.association_name)
59
+ .where(object_attribute: historyable.attribute_name)
60
+ .order('created_at DESC')
61
+ .select(:object_attribute_value, :created_at)
62
+ end
63
+ end
64
+
65
+ # attribute_history
66
+ #
67
+ # @example
68
+ #
69
+ # @user.name_history
70
+ #
71
+ # @return [Array]
72
+ def define_historyable_attribute_history(historyable)
73
+ define_method("#{historyable.attribute_name.to_s}_history") do
74
+ unless instance_variable_get("@#{historyable.attribute_name.to_s}_history".to_sym)
75
+ collection = []
76
+
77
+ records = send("#{historyable.attribute_name}_history_raw")
78
+ .pluck(:object_attribute_value, :created_at)
79
+ records.map do |attribute_value, created_at|
80
+ item = HashWithIndifferentAccess.new
81
+ item[:attribute_value] = attribute_value
82
+ item[:changed_at] = created_at
83
+
84
+ collection << item
80
85
  end
81
- end
82
86
 
83
- # attribute_history?
84
- #
85
- # @example
86
- #
87
- # @user.name_history?
88
- #
89
- # @return [Boolean]
90
- define_method("#{historyable.attribute_name.to_s}_history?") do
91
- send("#{historyable.attribute_name}_history_raw").any?
87
+ # Sets attribute_history cache
88
+ instance_variable_set("@#{historyable.attribute_name.to_s}_history".to_sym, collection)
89
+ collection
90
+ else
91
+ instance_variable_get("@#{historyable.attribute_name.to_s}_history".to_sym)
92
92
  end
93
93
  end
94
+ end
94
95
 
95
-
96
- # Callbacks
97
- around_save :save_changes
96
+ # attribute_history?
97
+ #
98
+ # @example
99
+ #
100
+ # @user.name_history?
101
+ #
102
+ # @return [Boolean]
103
+ def define_historyable_attribute_history?(historyable)
104
+ define_method("#{historyable.attribute_name.to_s}_history?") do
105
+ send("#{historyable.attribute_name}_history_raw").any?
106
+ end
98
107
  end
99
108
  end
100
109
 
@@ -1,3 +1,3 @@
1
1
  module Historyable
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: historyable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philippe Dionne
@@ -38,22 +38,92 @@ cert_chain:
38
38
  aW9OckllMC8xNWRIcERvSUVESUxhNnpVNDZCClhEdHAxWXhkZVZHSUJ1Tm9Q
39
39
  MXZqRFN2TktZajBwTWpSQUVQcnFLMzlqS0U9Ci0tLS0tRU5EIENFUlRJRklD
40
40
  QVRFLS0tLS0K
41
- date: 2013-08-23 00:00:00.000000000 Z
41
+ date: 2013-09-24 00:00:00.000000000 Z
42
42
  dependencies:
43
43
  - !ruby/object:Gem::Dependency
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: 3.0.0
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 3.0.0
54
+ type: :runtime
44
55
  prerelease: false
45
56
  name: activerecord
57
+ - !ruby/object:Gem::Dependency
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '1.3'
46
63
  version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '1.3'
68
+ type: :development
69
+ prerelease: false
70
+ name: bundler
71
+ - !ruby/object:Gem::Dependency
72
+ requirement: !ruby/object:Gem::Requirement
47
73
  requirements:
48
74
  - - ! '>='
49
75
  - !ruby/object:Gem::Version
50
- version: 3.0.0
76
+ version: '0'
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ name: rake
85
+ - !ruby/object:Gem::Dependency
51
86
  requirement: !ruby/object:Gem::Requirement
52
87
  requirements:
53
88
  - - ! '>='
54
89
  - !ruby/object:Gem::Version
55
- version: 3.0.0
56
- type: :runtime
90
+ version: '0'
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ name: rspec
99
+ - !ruby/object:Gem::Dependency
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ name: sqlite3
113
+ - !ruby/object:Gem::Dependency
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ name: database_cleaner
57
127
  description: A simple and solid concern to track ActiveRecord models attributes changes.
58
128
  email:
59
129
  - philippe.dionne@hooktstudios.com
@@ -86,8 +156,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
156
  - !ruby/object:Gem::Version
87
157
  version: '0'
88
158
  requirements: []
89
- rubyforge_project: ! '[none]'
90
- rubygems_version: 2.0.3
159
+ rubyforge_project:
160
+ rubygems_version: 2.1.3
91
161
  signing_key:
92
162
  specification_version: 4
93
163
  summary: A simple and solid concern to track ActiveRecord models attributes changes.
metadata.gz.sig CHANGED
Binary file