Class: ClarkKent::ReportsController::UpdateReport

Inherits:
Object
  • Object
show all
Defined in:
app/interactions/clark_kent/reports_controller/update_report.rb

Instance Method Summary collapse

Constructor Details

#initialize(report, params) ⇒ UpdateReport

Returns a new instance of UpdateReport.



2
3
4
# File 'app/interactions/clark_kent/reports_controller/update_report.rb', line 2

def initialize(report, params)
  @report, @params = report, params
end

Instance Method Details

#callObject



6
7
8
9
10
# File 'app/interactions/clark_kent/reports_controller/update_report.rb', line 6

def call
  @report.assign_attributes(@params)
  validate_resource_type or return false
  @report.save
end

#validate_resource_typeObject



12
13
14
15
16
17
18
19
20
# File 'app/interactions/clark_kent/reports_controller/update_report.rb', line 12

def validate_resource_type
  if @report.report_columns.any? || @report.report_filters.any?
    if @report.changes.keys.include? 'resource_type'
      @report.errors[:resource_type] << "You can't change the type of report after adding columns or filters."
      return false
    end
  end
  return true
end