class HatebloMixedContentsFinder::CLI

Public Instance Methods

update_all() click to toggle source
# File lib/hateblo_mixed_contents_finder/cli.rb, line 42
def update_all
  sleep_sec = options[:sleep_sec]
  path = options[:path]

  count = File.read(path).lines.size
  puts "[WARNING] Please backup your entries before update!!"
  print "Do you update #{count} entries? [yes|no]: "
  res = STDIN.gets.chomp.downcase
  return unless res == 'yes'

  client = HatenaClient.new
  File.foreach(path) do |url|
    client.update_entry(url.chomp)
    sleep sleep_sec
  end
  puts 'Completed.'
end
validate_all(site_url) click to toggle source
# File lib/hateblo_mixed_contents_finder/cli.rb, line 10
def validate_all(site_url)
  entire_page = options[:entire_page]
  limit = options[:limit]
  path = options[:path]

  invalid_contents = MixedContentsFinder.new(entire_page: entire_page).validate_all(site_url, limit: limit)
  FileUtils.rm(path) if File.exist?(path)
  File.write(path, invalid_contents.join("\n"))
  if invalid_contents.empty?
    puts 'OK💚'
  else
    puts "#{invalid_contents.size} errors found. Please open result.txt."
  end
end
validate_entry(entry_url) click to toggle source
# File lib/hateblo_mixed_contents_finder/cli.rb, line 27
def validate_entry(entry_url)
  entire_page = options[:entire_page]

  invalid_contents = MixedContentsFinder.new(entire_page: entire_page).validate_entry(entry_url)
  if invalid_contents.empty?
    puts 'OK💚'
  else
    puts
    puts invalid_contents
  end
end