Module: ObservableObject::DeepWrap

Defined in:
lib/observable_object.rb

Constant Summary collapse

NonWrappable =
[Symbol, Numeric, TrueClass, FalseClass, NilClass]

Class Method Summary collapse

Class Method Details

.is_unwrappable(elem) ⇒ Object



25
26
27
# File 'lib/observable_object.rb', line 25

def self.is_unwrappable(elem)
  NonWrappable.any? { |t| elem.is_a?(t) }
end

.map_obj(obj, notifier) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/observable_object.rb', line 15

def self.map_obj(obj,notifier)
  case obj
    when Array then obj.map { |x| wrap_elem(x,notifier) }
    when Set then obj.clone.map! { |x| wrap_elem(x,notifier) }
    when Hash then obj.map { |k,v| [ k, wrap_elem(v,notifier) ] }.to_h
    else obj
  end 
end

.wrap_elem(elem, notifier) ⇒ Object



28
29
30
# File 'lib/observable_object.rb', line 28

def self.wrap_elem(elem,notifier)
  is_unwrappable(elem) ? elem : Wrapper.new(elem,:detect,true,notifier)
end