class Rox::Core::FlagRepository
Public Class Methods
new()
click to toggle source
# File lib/rox/core/repositories/flag_repository.rb, line 4 def initialize @strings = {} @flag_added_handlers = [] @mutex = Mutex.new @handlers_mutex = Mutex.new end
Public Instance Methods
add_flag(string, name)
click to toggle source
# File lib/rox/core/repositories/flag_repository.rb, line 11 def add_flag(string, name) string.name = name if string.name.nil? || string.name.empty? @mutex.synchronize do @strings[name] = string end raise_flag_added_event(string) end
all_flags()
click to toggle source
# File lib/rox/core/repositories/flag_repository.rb, line 25 def all_flags @mutex.synchronize do return @strings.values end end
flag(name)
click to toggle source
# File lib/rox/core/repositories/flag_repository.rb, line 19 def flag(name) @mutex.synchronize do return @strings[name] end end
raise_flag_added_event(flag)
click to toggle source
# File lib/rox/core/repositories/flag_repository.rb, line 37 def raise_flag_added_event(flag) handlers = [] @handlers_mutex.synchronize do handlers = @flag_added_handlers.clone end handlers.each do |handler| handler.call(flag) end end
register_flag_added_handler(&block)
click to toggle source
# File lib/rox/core/repositories/flag_repository.rb, line 31 def register_flag_added_handler(&block) @handlers_mutex.synchronize do @flag_added_handlers << block end end