Module: StandardModel
- Extended by:
- ActiveSupport::Concern
- Includes:
- App47Logger, Mongoid::Document, Mongoid::Timestamps
- Included in:
- Cron::Server, Cron::Tab, Notification, NotificationTemplate, SmtpConfiguration, Template
- Defined in:
- lib/app/models/concerns/standard_model.rb
Overview
Mixin to standardize the setup of all models, i.e., the standard or base model definitions they should all have
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
include Auditable.
Instance Method Summary collapse
-
#clear_cache ⇒ Object
Clear the cache.
- #remove_blank_secure_fields(params) ⇒ Object
-
#secure_fields ⇒ Object
List of secure fields, to add fields in concrete class, simply override this method.
-
#update(params) ⇒ Object
(also: #update_attributes)
Remove updates for secure fields that come across as blank to start with and get removed on update.
-
#update!(params) ⇒ Object
(also: #update_attributes!)
Remove updates for secure fields that come across as blank to start with and get removed on update.
Methods included from App47Logger
#clean_params, #delete_parameter_keys, #log_controller_error, #log_debug, log_debug, log_error, #log_error, log_exception, #log_message, log_message, #log_warn, log_warn, #mask_parameter_keys, #update_flash_messages
Class Method Details
.included(base) ⇒ Object
include Auditable
14 15 16 17 18 19 20 21 22 |
# File 'lib/app/models/concerns/standard_model.rb', line 14 def self.included(base) base.class_eval do # # Callbacks # after_save :clear_cache before_destroy :clear_cache end end |
Instance Method Details
#clear_cache ⇒ Object
Clear the cache
130 131 132 133 134 135 136 137 138 |
# File 'lib/app/models/concerns/standard_model.rb', line 130 def clear_cache Rails.cache.delete_matched "*#{id}*" return unless respond_to?(:account) && account.present? && account.is_a?(Account) Rails.cache.delete_matched "*#{account.id}*" true # Force a return of true so that we don't break the callback chain. rescue StandardError false end |
#remove_blank_secure_fields(params) ⇒ Object
122 123 124 125 |
# File 'lib/app/models/concerns/standard_model.rb', line 122 def remove_blank_secure_fields(params) secure_fields.each { |field| params.delete(field) if params[field].blank? } params end |
#secure_fields ⇒ Object
List of secure fields, to add fields in concrete class, simply override this method
118 119 120 |
# File 'lib/app/models/concerns/standard_model.rb', line 118 def secure_fields [] end |
#update(params) ⇒ Object Also known as: update_attributes
Remove updates for secure fields that come across as blank to start with and get removed on update
100 101 102 |
# File 'lib/app/models/concerns/standard_model.rb', line 100 def update(params) super(remove_blank_secure_fields(params)) end |
#update!(params) ⇒ Object Also known as: update_attributes!
Remove updates for secure fields that come across as blank to start with and get removed on update
109 110 111 |
# File 'lib/app/models/concerns/standard_model.rb', line 109 def update!(params) super(remove_blank_secure_fields(params)) end |