Module: Nexo::Synchronizable

Extended by:
ActiveSupport::Concern
Included in:
CalendarEvent
Defined in:
app/models/concerns/nexo/synchronizable.rb

Defined Under Namespace

Modules: Associations, ClassMethods

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object



57
58
59
60
61
62
63
# File 'app/models/concerns/nexo/synchronizable.rb', line 57

def method_missing(method_name, *, &)
  if method_name.in?(protocol_methods)
    raise Errors::InterfaceMethodNotImplemented, method_name
  end

  super
end

Instance Method Details

#conflicted?Boolean



74
75
76
# File 'app/models/concerns/nexo/synchronizable.rb', line 74

def conflicted?
  nexo_elements.conflicted.any?
end

#increment_sequence!Object

:nocov:



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/models/concerns/nexo/synchronizable.rb', line 92

def increment_sequence!
  if sequence.nil?
    Nexo.logger.warn("Synchronizable sequence is nil on increment_sequence!: #{self.to_gid}")
  end

  # This operation is performed directly in the database without the need
  # to read the current value first. So, it is atomic at a database level,
  # though the in-memory object consitency is subject to race conditions.
  #
  # increment(:sequence), without the bang, is not atomic
  #
  # https://api.rubyonrails.org/v7.2/classes/ActiveRecord/Persistence.html#method-i-increment-21
  increment!(:sequence)
end

#protocol_methodsObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/models/concerns/nexo/synchronizable.rb', line 5

def protocol_methods
  # uuid (deprecated)
  #   hay un problema con generar un uuid por synchronizable y es que si se
  #   inserta en un google calendar y luego se elimina, luego ya no se
  #   puede volver a insertar con el mismo uuid, sería mejor que el id se
  #   genere automáticamente por google y guardarlo en Element
  #
  # sequence
  #   autoincremental integer, starting at 0. its recommended that
  #   the attribute is always initialized with 0 value on creation
  i[
    sequence
  ]
end

#translate_fields(fields, for_create: false, folder: nil) ⇒ Object



87
88
89
# File 'app/models/concerns/nexo/synchronizable.rb', line 87

def translate_fields(fields, for_create: false, folder: nil)
  raise "must be implemented in subclass"
end

#update_from_fields!(fields) ⇒ Object



83
84
85
# File 'app/models/concerns/nexo/synchronizable.rb', line 83

def update_from_fields!(fields)
  raise "must be implemented in subclass"
end

#validate_synchronizable!Object

:nocov: borderline



79
80
81
# File 'app/models/concerns/nexo/synchronizable.rb', line 79

def validate_synchronizable!
  raise "must be implemented in subclass"
end