Class: ReactiveObservers::Observer::Container

Inherits:
Object
  • Object
show all
Defined in:
lib/reactive_observers/observer/container.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(observer, observed, options) ⇒ Container

Returns a new instance of Container.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/reactive_observers/observer/container.rb', line 15

def initialize(observer, observed, options)
  @observer = observer
  @observed = observed.is_a?(Symbol) ? observed.to_s.classify.constantize : observed
  @on = Array.wrap options[:on]
  @fields = Array.wrap options[:fields]
  @only = options[:only]
  @trigger = options[:trigger] || ReactiveObservers.configuration.default_trigger
  @notify = options[:notify]
  @refine = options[:refine]
  @context = options[:context]
  ReactiveObservers::Observer::ContainerValidator.new(self).run_validations!
  @constrain = load_observer_constrains
  @trigger_with_previous_values = options[:trigger_with_previous_values] || false
end

Instance Attribute Details

#constrainObject

Returns the value of attribute constrain.



12
13
14
# File 'lib/reactive_observers/observer/container.rb', line 12

def constrain
  @constrain
end

#contextObject

Returns the value of attribute context.



11
12
13
# File 'lib/reactive_observers/observer/container.rb', line 11

def context
  @context
end

#fieldsObject

Returns the value of attribute fields.



12
13
14
# File 'lib/reactive_observers/observer/container.rb', line 12

def fields
  @fields
end

#notifyObject

Returns the value of attribute notify.



11
12
13
# File 'lib/reactive_observers/observer/container.rb', line 11

def notify
  @notify
end

#observedObject

Returns the value of attribute observed.



10
11
12
# File 'lib/reactive_observers/observer/container.rb', line 10

def observed
  @observed
end

#observerObject

Returns the value of attribute observer.



10
11
12
# File 'lib/reactive_observers/observer/container.rb', line 10

def observer
  @observer
end

#onObject

Returns the value of attribute on.



12
13
14
# File 'lib/reactive_observers/observer/container.rb', line 12

def on
  @on
end

#onlyObject

Returns the value of attribute only.



12
13
14
# File 'lib/reactive_observers/observer/container.rb', line 12

def only
  @only
end

#refineObject

Returns the value of attribute refine.



11
12
13
# File 'lib/reactive_observers/observer/container.rb', line 11

def refine
  @refine
end

#triggerObject

Returns the value of attribute trigger.



11
12
13
# File 'lib/reactive_observers/observer/container.rb', line 11

def trigger
  @trigger
end

#trigger_with_previous_valuesObject

Returns the value of attribute trigger_with_previous_values.



13
14
15
# File 'lib/reactive_observers/observer/container.rb', line 13

def trigger_with_previous_values
  @trigger_with_previous_values
end

Instance Method Details

#compareObject



30
31
32
# File 'lib/reactive_observers/observer/container.rb', line 30

def compare
  ReactiveObservers::Observer::ContainerComparator.new(self)
end

#klass_observed?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/reactive_observers/observer/container.rb', line 38

def klass_observed?
  @observed.is_a? Class
end

#klass_observer?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/reactive_observers/observer/container.rb', line 34

def klass_observer?
  @observer.is_a? Class
end

#observed_klassObject



48
49
50
51
52
# File 'lib/reactive_observers/observer/container.rb', line 48

def observed_klass
  return @observed if klass_observed?

  @observed.class
end

#observer_klassObject



42
43
44
45
46
# File 'lib/reactive_observers/observer/container.rb', line 42

def observer_klass
  return @observer if klass_observer?

  @observer.class
end

#to_hObject



54
55
56
57
# File 'lib/reactive_observers/observer/container.rb', line 54

def to_h
  { observer: @observer, observed: @observed, fields: @fields, on: @on, only: @only, constrain: @constrain,
    trigger: @trigger, refine: @refine, notify: @notify, context: @context}
end