Class: Nexo::Folder

Inherits:
ApplicationRecord show all
Defined in:
app/models/nexo/folder.rb

Instance Method Summary collapse

Instance Method Details

#discard!Object



62
63
64
# File 'app/models/nexo/folder.rb', line 62

def discard!
  update!(discarded_at: Time.current)
end

#discarded?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'app/models/nexo/folder.rb', line 58

def discarded?
  discarded_at.present?
end

#find_element(synchronizable:) ⇒ Object

TODO: use find_sole_by



44
45
46
47
48
49
50
51
52
# File 'app/models/nexo/folder.rb', line 44

def find_element(synchronizable:)
  ary = elements.where(synchronizable:, discarded_at: nil).to_a

  if ary.count > 1
    raise Errors::MoreThanOneElementInFolderForSynchronizable
  end

  ary.first
end

#policy_applies?(synchronizable) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/models/nexo/folder.rb', line 39

def policy_applies?(synchronizable)
  PolicyService.instance.applies?(self, synchronizable)
end

#sync_external_changes?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'app/models/nexo/folder.rb', line 27

def sync_external_changes?
  sync_out_in? || sync_bidirectional?
end

#sync_internal_changes?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'app/models/nexo/folder.rb', line 31

def sync_internal_changes?
  sync_in_out? || sync_bidirectional?
end

#time_zoneObject



54
55
56
# File 'app/models/nexo/folder.rb', line 54

def time_zone
  Rails.application.config.time_zone
end

#to_sObject



66
67
68
# File 'app/models/nexo/folder.rb', line 66

def to_s
  name.presence || super
end