Module: Logidze::Detachable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/logidze/detachable.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#create_logidze_snapshot!(timestamp: nil, only: nil, except: nil) ⇒ Object
Initialize log_data with the current state if it’s null for a single record.
- #dup ⇒ Object
- #log_data=(v) ⇒ Object
- #raw_log_data ⇒ Object
-
#reload_log_data ⇒ Object
Loads log_data field from the database, stores to the attributes hash and returns it.
-
#reset_log_data ⇒ Object
Nullify log_data column for a single record.
Instance Method Details
#create_logidze_snapshot!(timestamp: nil, only: nil, except: nil) ⇒ Object
Initialize log_data with the current state if it’s null for a single record
57 58 59 60 61 62 |
# File 'lib/logidze/detachable.rb', line 57 def create_logidze_snapshot!(timestamp: nil, only: nil, except: nil) id_filter = "WHERE #{self.class.quoted_table_name}.id = #{id}" self.class.create_logidze_snapshot(timestamp: , only: only, except: except, sql_filter: id_filter) reload_log_data end |
#dup ⇒ Object
73 74 75 |
# File 'lib/logidze/detachable.rb', line 73 def dup super.tap { _1.logidze_data = logidze_data.dup } end |
#log_data=(v) ⇒ Object
68 69 70 71 |
# File 'lib/logidze/detachable.rb', line 68 def log_data=(v) logidze_data&.assign_attributes(log_data: v) || build_logidze_data(log_data: v) v # rubocop:disable Lint/Void end |
#raw_log_data ⇒ Object
64 65 66 |
# File 'lib/logidze/detachable.rb', line 64 def raw_log_data logidze_data&.read_attribute_before_type_cast(:log_data) end |
#reload_log_data ⇒ Object
Loads log_data field from the database, stores to the attributes hash and returns it
47 48 49 |
# File 'lib/logidze/detachable.rb', line 47 def reload_log_data reload_logidze_data.log_data end |
#reset_log_data ⇒ Object
Nullify log_data column for a single record
52 53 54 |
# File 'lib/logidze/detachable.rb', line 52 def reset_log_data tap { logidze_data.delete }.reload_logidze_data end |