Module: Fustrate::Rails::Services::LogEdit

Defined in:
lib/fustrate/rails/services/log_edit.rb

Constant Summary collapse

IGNORE_COLUMNS =
%w[id created_at updated_at].freeze
RENAME_COLUMNS =
{}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#forceObject (readonly)

Returns the value of attribute force.



13
14
15
# File 'lib/fustrate/rails/services/log_edit.rb', line 13

def force
  @force
end

#noteObject (readonly)

Returns the value of attribute note.



13
14
15
# File 'lib/fustrate/rails/services/log_edit.rb', line 13

def note
  @note
end

#subjectObject (readonly)

Returns the value of attribute subject.



13
14
15
# File 'lib/fustrate/rails/services/log_edit.rb', line 13

def subject
  @subject
end

#userObject (readonly)

Returns the value of attribute user.



13
14
15
# File 'lib/fustrate/rails/services/log_edit.rb', line 13

def user
  @user
end

Instance Method Details

#call(subject, force: false, note: nil, user: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fustrate/rails/services/log_edit.rb', line 15

def call(subject, force: false, note: nil, user: nil)
  # Make sure any before_validation callbacks are run
  subject.validate

  @subject = subject
  @force = force
  @note = note
  @user = user || ::Current.user

  process_changes

  self.class::RENAME_COLUMNS.each do |from, to|
    changes[to] = changes.delete(from) if changes[from]
  end

  record_edit
end