Class: Recluse::CLI::Blacklist

Inherits:
Thor
  • Object
show all
Defined in:
lib/recluse/cli/blacklist.rb

Overview

Blacklist related commands.

Instance Method Summary collapse

Instance Method Details

#add(name, *patterns) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/recluse/cli/blacklist.rb', line 10

def add(name, *patterns)
  uconf = UserConfig.new '.recluse'
  unless uconf.exist?("#{name}.yaml")
    puts "Profile #{name} doesn't exist"
    exit(-1)
  end
  profile = uconf["#{name}.yaml"]
  if profile.key?('blacklist')
    profile['blacklist'] += patterns
  else
    profile['blacklist'] = patterns
  end
  profile.save
end

#clear(name) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/recluse/cli/blacklist.rb', line 37

def clear(name)
  uconf = UserConfig.new '.recluse'
  unless uconf.exist?("#{name}.yaml")
    puts "Profile #{name} doesn't exist"
    exit(-1)
  end
  profile = uconf["#{name}.yaml"]
  profile['blacklist'] = []
  profile.save
end

#list(name) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/recluse/cli/blacklist.rb', line 48

def list(name)
  uconf = UserConfig.new '.recluse'
  unless uconf.exist?("#{name}.yaml")
    puts "Profile #{name} doesn't exist"
    exit(-1)
  end
  profile = uconf["#{name}.yaml"]
  profile['blacklist'].each { |pattern| puts pattern } if profile.key?('blacklist')
end

#remove(name, *patterns) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/recluse/cli/blacklist.rb', line 25

def remove(name, *patterns)
  uconf = UserConfig.new '.recluse'
  unless uconf.exist?("#{name}.yaml")
    puts "Profile #{name} doesn't exist"
    exit(-1)
  end
  profile = uconf["#{name}.yaml"]
  return unless profile.key?('blacklist')
  profile['blacklist'] -= patterns
  profile.save
end