lib/ayadn/blacklist.rb in ayadn-1.0.13 vs lib/ayadn/blacklist.rb in ayadn-1.1.0

- old
+ new

@@ -23,22 +23,32 @@ puts Status.done end desc "list", "List the content of your blacklist" long_desc Descriptions.blacklist_list + option :raw, aliases: "-x", type: :boolean, desc: "Outputs the raw list in CSV" def list blacklist = BlacklistWorkers.new - blacklist.list + blacklist.list(options) end desc "import DATABASE", "Imports a blacklist database from another Ayadn account" long_desc Descriptions.blacklist_import def import(database) blacklist = BlacklistWorkers.new blacklist.import(database) puts Status.done end + + desc "convert", "Convert your current blacklist database to the new format" + long_desc Descriptions.blacklist_convert + def convert + blacklist = BlacklistWorkers.new + blacklist.convert + puts Status.done + end + end class BlacklistWorkers def initialize Settings.load_config @@ -59,10 +69,17 @@ end ensure Databases.close_all end end + def convert + begin + Databases.convert_blacklist + ensure + Databases.close_all + end + end def add(args) begin type, target = args[0], args[1] case type when 'mention', 'mentions' @@ -98,19 +115,29 @@ end ensure Databases.close_all end end - def list + def list(options) begin - list = Databases.blacklist - unless list.empty? - puts Workers.new.build_blacklist_list(list) - else - abort(Status.empty_list) - end + show_list(options) ensure Databases.close_all + end + end + + private + + def show_list(options) + list = Databases.blacklist + unless list.empty? + if options[:raw] + list.each {|v,k| puts "#{v},#{k}"} + else + puts Workers.new.build_blacklist_list(list) + end + else + abort(Status.empty_list) end end end end