Class: Rox::Core::FlagRepository
- Inherits:
-
Object
- Object
- Rox::Core::FlagRepository
- Defined in:
- lib/rox/core/repositories/flag_repository.rb
Instance Method Summary collapse
- #add_flag(string, name) ⇒ Object
- #all_flags ⇒ Object
- #flag(name) ⇒ Object
-
#initialize ⇒ FlagRepository
constructor
A new instance of FlagRepository.
- #raise_flag_added_event(flag) ⇒ Object
- #register_flag_added_handler(&block) ⇒ Object
Constructor Details
#initialize ⇒ FlagRepository
Returns a new instance of FlagRepository.
4 5 6 7 8 9 |
# File 'lib/rox/core/repositories/flag_repository.rb', line 4 def initialize @strings = {} @flag_added_handlers = [] @mutex = Mutex.new @handlers_mutex = Mutex.new end |
Instance Method Details
#add_flag(string, name) ⇒ Object
11 12 13 14 15 16 17 |
# 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 ⇒ Object
25 26 27 28 29 |
# File 'lib/rox/core/repositories/flag_repository.rb', line 25 def all_flags @mutex.synchronize do return @strings.values end end |
#flag(name) ⇒ Object
19 20 21 22 23 |
# 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) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# 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) ⇒ Object
31 32 33 34 35 |
# 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 |