Class: Dobby::FlagManager
- Inherits:
-
Object
- Object
- Dobby::FlagManager
- Defined in:
- lib/dobby/flag_manager.rb
Overview
Simple interface for managing whitelist/allowed flags of defects.
Instance Attribute Summary collapse
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
Instance Method Summary collapse
- #add(flag, id, ticket) ⇒ Object
- #builk_remove(flag, ids) ⇒ Object
- #bulk_add(flag, ids) ⇒ Object
- #bulk_move(src, dst, ids) ⇒ Object
- #dump ⇒ Object
-
#initialize(file, who) ⇒ FlagManager
constructor
A new instance of FlagManager.
- #move(src, dst, id) ⇒ Object
- #remove(flag, id) ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(file, who) ⇒ FlagManager
Returns a new instance of FlagManager.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/dobby/flag_manager.rb', line 11 def initialize(file, who) flags = { whitelist: {}, allowed: {} } @file = file @flags = flags.merge!(Psych.load_file(file)) @who = who end |
Instance Attribute Details
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
6 7 8 |
# File 'lib/dobby/flag_manager.rb', line 6 def flags @flags end |
Instance Method Details
#add(flag, id, ticket) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/dobby/flag_manager.rb', line 22 def add(flag, id, ticket) return false if @flags[flag].key?(id) @flags[flag][id] = { by: @who, on: Time.now.utc, ticket: ticket } end |
#builk_remove(flag, ids) ⇒ Object
49 50 51 |
# File 'lib/dobby/flag_manager.rb', line 49 def builk_remove(flag, ids) ids.each { |id| remove(flag, id) } end |
#bulk_add(flag, ids) ⇒ Object
45 46 47 |
# File 'lib/dobby/flag_manager.rb', line 45 def bulk_add(flag, ids) ids.each { |id| remove(flag, id) } end |
#bulk_move(src, dst, ids) ⇒ Object
53 54 55 |
# File 'lib/dobby/flag_manager.rb', line 53 def bulk_move(src, dst, ids) ids.each { |id| move(src, dst, id) } end |
#dump ⇒ Object
57 58 59 |
# File 'lib/dobby/flag_manager.rb', line 57 def dump @flags.to_yaml end |
#move(src, dst, id) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/dobby/flag_manager.rb', line 38 def move(src, dst, id) ticket = @flags[src][id][:ticket] return false unless remove(src, id) add(dst, id, ticket) end |
#remove(flag, id) ⇒ Object
32 33 34 35 36 |
# File 'lib/dobby/flag_manager.rb', line 32 def remove(flag, id) return false unless @flags[flag].key?(id) @flags[flag].delete id end |
#write ⇒ Object
61 62 63 64 65 |
# File 'lib/dobby/flag_manager.rb', line 61 def write File.open(@file, 'w') do |f| f.write(@flags.to_yaml) end end |