Class: Superset::Dataset::Duplicate

Inherits:
Request
  • Object
show all
Defined in:
lib/superset/dataset/duplicate.rb

Constant Summary

Constants inherited from Request

Request::PAGE_SIZE

Instance Attribute Summary collapse

Attributes inherited from Request

#page_num

Instance Method Summary collapse

Methods inherited from Request

call, #query_params, #result, #superset_host

Methods included from Superset::Display

#display_headers, #headings, #list, #list_attributes, #result, #rows, #table, #title

Constructor Details

#initialize(source_dataset_id:, new_dataset_name:) ⇒ Duplicate

Returns a new instance of Duplicate.



10
11
12
13
# File 'lib/superset/dataset/duplicate.rb', line 10

def initialize(source_dataset_id: , new_dataset_name: )
  @source_dataset_id = source_dataset_id
  @new_dataset_name = new_dataset_name
end

Instance Attribute Details

#new_dataset_nameObject (readonly)

Returns the value of attribute new_dataset_name.



8
9
10
# File 'lib/superset/dataset/duplicate.rb', line 8

def new_dataset_name
  @new_dataset_name
end

#source_dataset_idObject (readonly)

Returns the value of attribute source_dataset_id.



8
9
10
# File 'lib/superset/dataset/duplicate.rb', line 8

def source_dataset_id
  @source_dataset_id
end

Instance Method Details

#paramsObject



29
30
31
32
33
34
# File 'lib/superset/dataset/duplicate.rb', line 29

def params
  {
    "base_model_id" => source_dataset_id,
    "table_name" => new_dataset_name
  }
end

#performObject



15
16
17
18
19
20
21
22
23
# File 'lib/superset/dataset/duplicate.rb', line 15

def perform
  raise "Error: source_dataset_id integer is required" unless source_dataset_id.present? && source_dataset_id.is_a?(Integer)
  raise "Error: new_dataset_name string is required" unless new_dataset_name.present? && new_dataset_name.is_a?(String)
  raise "Error: new_dataset_name already in use in this schema: #{new_dataset_name}. Suggest you add (COPY) as a suffix to the name" if new_dataset_name_already_in_use?

  logger.info("Duplicating Source Dataset #{source_dataset.title} with id #{source_dataset_id}")

  new_dataset_id
end

#responseObject



25
26
27
# File 'lib/superset/dataset/duplicate.rb', line 25

def response
  @response ||= client.post(route, params)
end