Class: Importable::ImporterController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/importable/importer_controller.rb

Direct Known Subclasses

ResourcesController, SpreadsheetsController

Instance Method Summary collapse

Instance Method Details

#importer_classObject



14
15
16
# File 'app/controllers/importable/importer_controller.rb', line 14

def importer_class
  "Importable::#{importer_name}".constantize
end

#importer_nameObject



18
19
20
# File 'app/controllers/importable/importer_controller.rb', line 18

def importer_name
  params[:controller].split('/').last.singularize.camelize
end

#init_import_paramsObject



37
38
39
# File 'app/controllers/importable/importer_controller.rb', line 37

def init_import_params
  @importer.import_params = params[:import_params] if params[:import_params]
end

#map_specific_pathObject



33
34
35
# File 'app/controllers/importable/importer_controller.rb', line 33

def map_specific_path
  File.join(Rails.root, 'app/views', @type.pluralize.sub('-', '/'))
end

#newObject



6
7
8
# File 'app/controllers/importable/importer_controller.rb', line 6

def new
  @importer = importer_class.new(mapper_name: @type)
end

#prepend_map_specific_view_pathObject



29
30
31
# File 'app/controllers/importable/importer_controller.rb', line 29

def prepend_map_specific_view_path
  prepend_view_path map_specific_path
end

#require_type_paramObject



22
23
24
25
26
27
# File 'app/controllers/importable/importer_controller.rb', line 22

def require_type_param
  unless Mapper.mapper_type_exists?(params[:type])
    raise ParamRequiredError.new("#{params[:type]} import mapper does not exist")
  end
  @type = params[:type]
end

#return_urlObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/importable/importer_controller.rb', line 41

def return_url
  index_path_sym = "#{@type.pluralize}_path".to_sym
  controller_name = params[:controller].split('/').last

  if params[:return_to] == 'index' and self.respond_to?(index_path_sym)
    main_app.send(index_path_sym)
  elsif params[:return_to] == 'import'
    new_importable_path = "new_#{controller_name.singularize}_path".to_sym
    send(new_importable_path, type: @type, import_params: @importer.import_params)
  else
    importable_path = "#{controller_name.singularize}_path".to_sym
    send(importable_path, id: @importer.id, type: @type)
  end
end

#showObject



10
11
12
# File 'app/controllers/importable/importer_controller.rb', line 10

def show
  @importer = importer_class.find(params[:id])
end