Class: Cli::LinksCommand

Inherits:
Thor
  • Object
show all
Defined in:
app/lib/cli/links_command.rb

Constant Summary collapse

DESCRIPTION =
"manage links"

Instance Method Summary collapse

Instance Method Details

#deduplicate ⇒ Object



9
10
11
# File 'app/lib/cli/links_command.rb', line 9

def deduplicate
  Link.find_duplicated.each(&:remove_duplicates!)
end

#purge ⇒ Object



24
25
26
27
28
# File 'app/lib/cli/links_command.rb', line 24

def purge
  scope = Link.where("url LIKE '%#{options[:match]}%'") # rubocop:disable Pundit/UsePolicyScope
  puts "\Removing #{scope.count} links matching #{options[:match]}"
  scope.destroy_all
end

#sync ⇒ Object



15
16
17
18
19
20
# File 'app/lib/cli/links_command.rb', line 15

def sync
  scope = Link.all # rubocop:disable Pundit/UsePolicyScope
  scope = scope.where("url LIKE '%#{options[:match]}%'") if options[:match]
  puts "\nQueueing #{scope.count} links for synchronisation"
  scope.find_each(&:update_metadata_from_link_later)
end