Class: Rox::Core::CustomPropertyRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/rox/core/repositories/custom_property_repository.rb

Instance Method Summary collapse

Constructor Details

#initializeCustomPropertyRepository

Returns a new instance of CustomPropertyRepository.



4
5
6
7
8
9
# 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

Instance Method Details

#add_custom_property(custom_property) ⇒ Object



11
12
13
14
15
16
17
18
19
# 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) ⇒ Object



21
22
23
24
25
26
27
28
29
# 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_propertiesObject



37
38
39
40
41
# 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) ⇒ Object



31
32
33
34
35
# 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) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# 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) ⇒ Object



43
44
45
46
47
# 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