Class: AuditedChangeSet::Change
- Inherits:
-
Object
- Object
- AuditedChangeSet::Change
show all
- Includes:
- Hooks, Enumerable
- Defined in:
- lib/audited_change_set/change.rb
Defined Under Namespace
Modules: Hooks
Classes: Field
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Hooks
#hooks, included
Constructor Details
#initialize(audit, fields = nil) ⇒ Change
Returns a new instance of Change.
106
107
108
109
|
# File 'lib/audited_change_set/change.rb', line 106
def initialize(audit, fields=nil)
@audit = audit
@fields = fields
end
|
Class Method Details
.field_names_for_audits(audits) ⇒ Object
92
93
94
|
# File 'lib/audited_change_set/change.rb', line 92
def field_names_for_audits(audits)
audits_to_changes(audits).map(&:field_names).flatten.uniq.sort
end
|
.for_audits(audits, fields = nil, unfiltered_change_id = nil) ⇒ Object
88
89
90
|
# File 'lib/audited_change_set/change.rb', line 88
def for_audits(audits, fields=nil, unfiltered_change_id=nil)
audits_to_changes(audits, fields, unfiltered_change_id).select(&:relevant?).reverse
end
|
Instance Method Details
#create_field(name, changes) ⇒ Object
111
112
113
|
# File 'lib/audited_change_set/change.rb', line 111
def create_field(name, changes)
Field.new(@audit.auditable_type, name, *[changes].flatten.reverse)
end
|
#date ⇒ Object
127
128
129
|
# File 'lib/audited_change_set/change.rb', line 127
def date
@audit.created_at
end
|
#each(&block) ⇒ Object
143
144
145
|
# File 'lib/audited_change_set/change.rb', line 143
def each(&block)
changed_fields.each(&block)
end
|
#field_names ⇒ Object
139
140
141
|
# File 'lib/audited_change_set/change.rb', line 139
def field_names
non_empty_fields.map { |name, vals| name }
end
|
#relevant? ⇒ Boolean
131
132
133
|
# File 'lib/audited_change_set/change.rb', line 131
def relevant?
any?(&:present?)
end
|
#relevant_field?(field) ⇒ Boolean
135
136
137
|
# File 'lib/audited_change_set/change.rb', line 135
def relevant_field?(field)
@fields ? @fields.map(&:downcase).include?(field.name) : true
end
|
#username ⇒ Object
119
120
121
122
123
124
125
|
# File 'lib/audited_change_set/change.rb', line 119
def username
if @audit.user
hook(:username, @audit.user) || @audit.username
else
'unknown'
end
end
|