Class: RailsAdmin::Extensions::History::AuditingAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_admin/extensions/history/auditing_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(controller, user_class = User) ⇒ AuditingAdapter

Returns a new instance of AuditingAdapter.



5
6
7
8
9
# File 'lib/rails_admin/extensions/history/auditing_adapter.rb', line 5

def initialize(controller, user_class = User)
  @controller = controller
  @user_class = user_class.to_s.constantize
  require 'rails_admin/extensions/history/history'
end

Instance Method Details

#create_object(object, model, user) ⇒ Object



23
24
25
# File 'lib/rails_admin/extensions/history/auditing_adapter.rb', line 23

def create_object(object, model, user)
  ::RailsAdmin::History.create_history_item('new', object, model, user)
end

#delete_object(object, model, user) ⇒ Object



15
16
17
# File 'lib/rails_admin/extensions/history/auditing_adapter.rb', line 15

def delete_object(object, model, user)
  ::RailsAdmin::History.create_history_item('delete', object, model, user)
end

#latestObject



11
12
13
# File 'lib/rails_admin/extensions/history/auditing_adapter.rb', line 11

def latest
  ::RailsAdmin::History.latest
end

#listing_for_model(model, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20)) ⇒ Object



27
28
29
# File 'lib/rails_admin/extensions/history/auditing_adapter.rb', line 27

def listing_for_model(model, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))
  ::RailsAdmin::History.history_for_model(model, query, sort, sort_reverse, all, page, per_page)
end

#listing_for_object(model, object, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20)) ⇒ Object



31
32
33
# File 'lib/rails_admin/extensions/history/auditing_adapter.rb', line 31

def listing_for_object(model, object, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))
  ::RailsAdmin::History.history_for_object(model, object, query, sort, sort_reverse, all, page, per_page)
end

#update_object(object, model, user, changes) ⇒ Object



19
20
21
# File 'lib/rails_admin/extensions/history/auditing_adapter.rb', line 19

def update_object(object, model, user, changes)
  ::RailsAdmin::History.create_history_item(changes.map{|k,v| "#{k}: #{v.map(&:inspect).join(' -> ')}"}, object, model, user)
end