Module: BridgeCache::Data::BridgeModel

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



4
5
6
7
8
9
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 4

def self.extended(base)
  base.class_eval do
    scope :in_domain, -> (domain_id) {for_domain(domain_id)}
    scope :active, -> {is_active?}
  end
end

Instance Method Details

#cleanup(row_ids) ⇒ Object



19
20
21
22
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 19

def cleanup(row_ids)
  # Implement this method in your model if you want to do any sort of post creation cleanup.
  # See tagging.rb for an example.
end

#create_from_csv_row(row) ⇒ Object



15
16
17
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 15

def create_from_csv_row(row)
  BridgeCache::Plugins::CSVDump::dump_row(self, row)
end

#for_domain(domain_id) ⇒ Object



40
41
42
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 40

def for_domain(domain_id)
  where(domain_id: domain_id)
end

#import_from_csv(file_path) ⇒ Object



11
12
13
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 11

def import_from_csv(file_path)
  BridgeCache::Plugins::CSVDump::dump_to_table(self, file_path)
end

#is_active?Boolean

Returns:

  • (Boolean)


44
45
46
47
48
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 44

def is_active?
  if self.column_names.include? 'deleted_at'
    where(deleted_at: nil)
  end
end

#webhook_completed(message) ⇒ Object



36
37
38
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 36

def webhook_completed(message)
  raise "Method not implemented"
end

#webhook_created(message) ⇒ Object



28
29
30
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 28

def webhook_created(message)
  create_or_update_from_webhook(message)
end

#webhook_deleted(message) ⇒ Object



32
33
34
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 32

def webhook_deleted(message)
  message.payload_class.where(bridge_id: message.resource_object['id']).destroy_all
end

#webhook_updated(message) ⇒ Object



24
25
26
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 24

def webhook_updated(message)
  create_or_update_from_webhook(message)
end