Class: ProtectedRecord::UseCase::ChangeRequest::Create

Inherits:
Object
  • Object
show all
Includes:
PayDirt::UseCase
Defined in:
lib/protected_record/use_case/change_request/create.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Create

Returns a new instance of Create.



6
7
8
9
10
11
12
13
# File 'lib/protected_record/use_case/change_request/create.rb', line 6

def initialize(options)
  options = {
    record_class: ::ProtectedRecord::ChangeRequest::Record
  }.merge!(options) if !options.has_key?(:record_class)

  load_options(:record_class, :user, :protected_record, options)
  validate_state
end

Instance Method Details

#execute!Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/protected_record/use_case/change_request/create.rb', line 15

def execute!
  return PayDirt::Result.new(data: {}, success: true) if !requested_changes.present?

  initialize_change_request_record

  if @record.save
    return PayDirt::Result.new(data: { change_request_record: @record }, success: true)
  else
    return PayDirt::Result.new(data: { change_request_record: @record }, success: false)
  end
end