Module: BridgeCache::Data::BridgeModel
- Included in:
- AffiliatedSubAccount, CourseTemplate, CustomField, BridgeCache::Domain, Enrollment, EnrollmentProfile, Grant, Group, GroupEnrollment, Host, LearnerCustomFieldValue, LiveCourse, LiveCourseEnrollment, LiveCourseSession, LiveCourseSessionRegistration, Membership, Program, ProgramEnrollment, ProgramGroupEnrollment, ProgramItem, Tag, Tagging, User, UserCourseVisit
- Defined in:
- app/lib/bridge_cache/data/bridge_model.rb
Constant Summary collapse
- EXCLUDED_COLUMNS =
Set['id', 'created_at', 'updated_at']
- OVERRIDDEN_COLUMNS =
{ 'bridge_created_at' => 'created_at'.freeze, 'bridge_updated_at' => 'updated_at'.freeze }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #adjusted_table_name ⇒ Object
- #cleanup(row_ids) ⇒ Object
- #create_from_csv_row(row) ⇒ Object
- #csv_mapping ⇒ Object
- #for_domain(domain_id) ⇒ Object
- #format_import_row(row) ⇒ Object
- #import_from_csv(file_path) ⇒ Object
- #is_active? ⇒ Boolean
- #uniq_constraint_name ⇒ Object
- #unique_column_names ⇒ Object
- #webhook_completed(_message) ⇒ Object
- #webhook_created(message) ⇒ Object
- #webhook_deleted(message) ⇒ Object
- #webhook_updated(message) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
17 18 19 20 21 22 23 |
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 17 def self.extended(base) base.class_eval do scope :in_domain, ->(domain_id) { for_domain(domain_id) } scope :active, -> { is_active? } self.table_name = adjusted_table_name end end |
Instance Method Details
#adjusted_table_name ⇒ Object
9 10 11 12 13 14 15 |
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 9 def adjusted_table_name if BridgeCache.use_internal_database table_name else to_s.demodulize.underscore.pluralize end end |
#cleanup(row_ids) ⇒ Object
37 38 39 40 |
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 37 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
33 34 35 |
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 33 def create_from_csv_row(row) BridgeCache::Plugins::CSVDump.dump_row(self, row) end |
#csv_mapping ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 74 def csv_mapping columns = column_names.as_json mapping = {} columns.each do |column| next if EXCLUDED_COLUMNS.include? column if OVERRIDDEN_COLUMNS.key?(column) mapping[OVERRIDDEN_COLUMNS[column]] = column else mapping[column] = column end end mapping['bridge_id'] = 'bridge_id' mapping end |
#for_domain(domain_id) ⇒ Object
58 59 60 |
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 58 def for_domain(domain_id) where(domain_id: domain_id) end |
#format_import_row(row) ⇒ Object
25 26 27 |
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 25 def format_import_row(row) row end |
#import_from_csv(file_path) ⇒ Object
29 30 31 |
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 29 def import_from_csv(file_path) BridgeCache::Plugins::CSVDump.dump_to_table(self, file_path) end |
#is_active? ⇒ Boolean
70 71 72 |
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 70 def is_active? where(deleted_at: nil) if column_names.include? 'deleted_at' end |
#uniq_constraint_name ⇒ Object
62 63 64 |
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 62 def uniq_constraint_name "#{table_name.downcase}_bridge_uniq" end |
#unique_column_names ⇒ Object
66 67 68 |
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 66 def unique_column_names %w[bridge_id] end |
#webhook_completed(_message) ⇒ Object
54 55 56 |
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 54 def webhook_completed() raise 'Method not implemented' end |
#webhook_created(message) ⇒ Object
46 47 48 |
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 46 def webhook_created() create_or_update_from_webhook() end |
#webhook_deleted(message) ⇒ Object
50 51 52 |
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 50 def webhook_deleted() .payload_class.where(bridge_id: .resource_object['id']).destroy_all end |
#webhook_updated(message) ⇒ Object
42 43 44 |
# File 'app/lib/bridge_cache/data/bridge_model.rb', line 42 def webhook_updated() create_or_update_from_webhook() end |