Class: RailsAdmin::Extensions::MongoidAudit::VersionProxy
- Inherits:
-
Object
- Object
- RailsAdmin::Extensions::MongoidAudit::VersionProxy
- Defined in:
- lib/mongoid-audit/rails_admin.rb
Instance Method Summary collapse
- #created_at ⇒ Object
-
#initialize(version) ⇒ VersionProxy
constructor
A new instance of VersionProxy.
- #item ⇒ Object
- #message ⇒ Object
- #table ⇒ Object
- #username ⇒ Object
Constructor Details
#initialize(version) ⇒ VersionProxy
Returns a new instance of VersionProxy.
5 6 7 |
# File 'lib/mongoid-audit/rails_admin.rb', line 5 def initialize(version) @version = version end |
Instance Method Details
#created_at ⇒ Object
30 31 32 |
# File 'lib/mongoid-audit/rails_admin.rb', line 30 def created_at @version.created_at end |
#item ⇒ Object
55 56 57 |
# File 'lib/mongoid-audit/rails_admin.rb', line 55 def item @version.association_chain.last['id'] end |
#message ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mongoid-audit/rails_admin.rb', line 9 def @message = @version.action if @message == 'create' return 'new' end if @message == 'destroy' return 'delete' end mods = @version.modified.to_a.map do |c| if c[1].class.name == "Moped::BSON::Binary" || c[1].class.name == "BSON::Binary" c[0] + " = {binary data}" elsif c[1].to_s.length > 220 c[0] + " = " + c[1].to_s[0..200] else c[0] + " = " + c[1].to_s end end @version.respond_to?(:modified) ? @message + ' ' + table + " [" + mods.join(", ") + "]" : @message end |
#table ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mongoid-audit/rails_admin.rb', line 34 def table if @version.association_chain.length == 1 @version.association_chain.last['name'] else index = 0 assoc = @version.association_chain while !assoc[index+1].nil? table = assoc[index]['name'].constantize.relations[assoc[index+1]['name']].class_name index += 1 end table end rescue Exception => e puts "mongoid-audit error: #{e.}" nil end |
#username ⇒ Object
51 52 53 |
# File 'lib/mongoid-audit/rails_admin.rb', line 51 def username @version.updater.try(:email) || @version.updater end |