Module: Sequel::Plugins::Temporal::InstanceMethods
- Defined in:
- lib/sequel/plugins/temporal.rb
Instance Attribute Summary collapse
-
#pending_version ⇒ Object
readonly
Returns the value of attribute pending_version.
Instance Method Summary collapse
- #after_create ⇒ Object
- #attributes ⇒ Object
- #attributes=(attributes) ⇒ Object
- #before_update ⇒ Object
- #before_validation ⇒ Object
- #destroy ⇒ Object
- #pending_or_current_version ⇒ Object
- #update_attributes(attributes = {}) ⇒ Object
- #validate ⇒ Object
Instance Attribute Details
#pending_version ⇒ Object (readonly)
Returns the value of attribute pending_version.
65 66 67 |
# File 'lib/sequel/plugins/temporal.rb', line 65 def pending_version @pending_version end |
Instance Method Details
#after_create ⇒ Object
112 113 114 115 116 117 |
# File 'lib/sequel/plugins/temporal.rb', line 112 def after_create super if pending_version return false unless save_pending_version end end |
#attributes ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/sequel/plugins/temporal.rb', line 83 def attributes if pending_version pending_version.values elsif current_version current_version.values else {} end end |
#attributes=(attributes) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/sequel/plugins/temporal.rb', line 93 def attributes=(attributes) if !new? && attributes.delete(:partial_update) && current_version current_attributes = current_version.keys.inject({}) do |hash, key| hash[key] = current_version.send key hash end attributes = current_attributes.merge attributes end attributes.delete :id @pending_version ||= model.version_class.new pending_version.set attributes pending_version.master_id = id unless new? end |
#before_update ⇒ Object
119 120 121 122 123 124 125 |
# File 'lib/sequel/plugins/temporal.rb', line 119 def before_update if pending_version expire_previous_version return false unless save_pending_version end super end |
#before_validation ⇒ Object
67 68 69 70 |
# File 'lib/sequel/plugins/temporal.rb', line 67 def before_validation prepare_pending_version super end |
#destroy ⇒ Object
127 128 129 |
# File 'lib/sequel/plugins/temporal.rb', line 127 def destroy versions_dataset.where(expired_at: nil).update expired_at: Time.now end |
#pending_or_current_version ⇒ Object
79 80 81 |
# File 'lib/sequel/plugins/temporal.rb', line 79 def pending_or_current_version pending_version || current_version end |
#update_attributes(attributes = {}) ⇒ Object
107 108 109 110 |
# File 'lib/sequel/plugins/temporal.rb', line 107 def update_attributes(attributes={}) self.attributes = attributes save raise_on_failure: false end |
#validate ⇒ Object
72 73 74 75 76 77 |
# File 'lib/sequel/plugins/temporal.rb', line 72 def validate super pending_version.errors.each do |key, key_errors| key_errors.each{|error| errors.add key, error} end if pending_version && !pending_version.valid? end |