class Rox::Core::CustomPropertyRepository

Public Class Methods

new() click to toggle source
# File lib/rox/core/repositories/custom_property_repository.rb, line 4
def initialize
  @custom_properties = {}
  @property_added_handlers = []
  @mutex = Mutex.new
  @handlers_mutex = Mutex.new
end

Public Instance Methods

add_custom_property(custom_property) click to toggle source
# File lib/rox/core/repositories/custom_property_repository.rb, line 11
def add_custom_property(custom_property)
  return if custom_property.name.nil? || custom_property.name.empty?

  @mutex.synchronize do
    @custom_properties[custom_property.name] = custom_property
  end

  raise_property_added_event(custom_property)
end
add_custom_property_if_not_exists(custom_property) click to toggle source
# File lib/rox/core/repositories/custom_property_repository.rb, line 21
def add_custom_property_if_not_exists(custom_property)
  return if custom_property.name.nil? || custom_property.name.empty?

  @mutex.synchronize do
    return if @custom_properties.include?(custom_property.name)
  end

  add_custom_property(custom_property)
end
all_custom_properties() click to toggle source
# File lib/rox/core/repositories/custom_property_repository.rb, line 37
def all_custom_properties
  @mutex.synchronize do
    return @custom_properties.values
  end
end
custom_property(name) click to toggle source
# File lib/rox/core/repositories/custom_property_repository.rb, line 31
def custom_property(name)
  @mutex.synchronize do
    return @custom_properties[name]
  end
end
raise_property_added_event(custom_property) click to toggle source
# File lib/rox/core/repositories/custom_property_repository.rb, line 49
def raise_property_added_event(custom_property)
  handlers = []
  @handlers_mutex.synchronize do
    handlers = @property_added_handlers.clone
  end

  handlers.each do |handler|
    handler.call(custom_property)
  end
end
register_property_added_handler(&block) click to toggle source
# File lib/rox/core/repositories/custom_property_repository.rb, line 43
def register_property_added_handler(&block)
  @handlers_mutex.synchronize do
    @property_added_handlers << block
  end
end