Class: Synchronisable::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/synchronisable/context.rb

Overview

Synchronization context.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, parent) ⇒ Context

Returns a new instance of Context.


7
8
9
10
11
# File 'lib/synchronisable/context.rb', line 7

def initialize(model, parent)
  @model, @parent = model, parent
  @errors = []
  @before, @after, @deleted = 0, 0, 0
end

Instance Attribute Details

#afterObject

Returns the value of attribute after


4
5
6
# File 'lib/synchronisable/context.rb', line 4

def after
  @after
end

#beforeObject

Returns the value of attribute before


4
5
6
# File 'lib/synchronisable/context.rb', line 4

def before
  @before
end

#deletedObject

Returns the value of attribute deleted


4
5
6
# File 'lib/synchronisable/context.rb', line 4

def deleted
  @deleted
end

#errorsObject

Returns the value of attribute errors


4
5
6
# File 'lib/synchronisable/context.rb', line 4

def errors
  @errors
end

#modelObject

Returns the value of attribute model


4
5
6
# File 'lib/synchronisable/context.rb', line 4

def model
  @model
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)

13
14
15
# File 'lib/synchronisable/context.rb', line 13

def success?
  errors.empty?
end

#summary_messageString

Returns summary synchronization info.

Returns:

  • (String)

    summary synchronization info


18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/synchronisable/context.rb', line 18

def summary_message
  msg = I18n.t('messages.result',
    :model   => model,
    :parent  => @parent.try(:model) || 'nil',
    :before  => before,
    :after   => after,
    :deleted => deleted,
    :errors  => errors.count
  )

  msg << I18n.t('messages.errors', errors: errors.join('. ')) if errors.any?
  msg
end