mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 14:44:47 +02:00
reordered csv columns
This commit is contained in:
parent
67d7a307a1
commit
2ffa28692f
1 changed files with 22 additions and 1 deletions
|
@ -1,5 +1,4 @@
|
|||
class Domain < ApplicationRecord
|
||||
extend ToCsv
|
||||
include UserEvents
|
||||
include Roids
|
||||
include Versions # version/domain_version.rb
|
||||
|
@ -281,6 +280,21 @@ class Domain < ApplicationRecord
|
|||
)
|
||||
end
|
||||
|
||||
def to_csv
|
||||
CSV.generate do |csv|
|
||||
headers = column_names.dup
|
||||
swap_elements(headers, [[0, 1], [1, 5]])
|
||||
headers[0] = 'Domain'
|
||||
headers[1] = headers[1].humanize
|
||||
csv << headers
|
||||
all.find_each do |item|
|
||||
row = item.attributes.values_at(*column_names)
|
||||
swap_elements(row, [[0, 1], [1, 5]])
|
||||
csv << row
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def registrant_user_domains_by_registrant(registrant_user)
|
||||
|
@ -741,4 +755,11 @@ class Domain < ApplicationRecord
|
|||
def self.uses_zone?(zone)
|
||||
exists?(["name ILIKE ?", "%.#{zone.origin}"])
|
||||
end
|
||||
|
||||
def swap_elements(array, indexes)
|
||||
indexes.each do |index|
|
||||
array[index[0]], array[index[1]] = array[index[1]], array[index[0]]
|
||||
end
|
||||
array
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue