Class: ActiveVersioning::Model::VersionProxy
- Inherits:
-
Delegator
- Object
- Delegator
- ActiveVersioning::Model::VersionProxy
- Defined in:
- lib/active_versioning/model/version_proxy.rb
Overview
‘class` should delegate to versioned resource, not return ActiveVersioning::Model::VersionProxy
Constant Summary collapse
- VersionInvalid =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #__getobj__ ⇒ Object
- #__setobj__(record) ⇒ Object
- #commit(params = {}) ⇒ Object
-
#initialize(version) ⇒ VersionProxy
constructor
A new instance of VersionProxy.
- #live? ⇒ Boolean
- #reload ⇒ Object
- #save ⇒ Object
- #save! ⇒ Object
- #to_param ⇒ Object
- #update(attributes) ⇒ Object (also: #update_attributes)
- #update!(attributes) ⇒ Object (also: #update_attributes!)
- #version? ⇒ Boolean
Constructor Details
#initialize(version) ⇒ VersionProxy
Returns a new instance of VersionProxy.
18 19 20 21 |
# File 'lib/active_versioning/model/version_proxy.rb', line 18 def initialize(version) @version = version __setobj__(version.reify) end |
Instance Attribute Details
#version ⇒ Object (readonly)
Returns the value of attribute version.
16 17 18 |
# File 'lib/active_versioning/model/version_proxy.rb', line 16 def version @version end |
Instance Method Details
#__getobj__ ⇒ Object
23 24 25 |
# File 'lib/active_versioning/model/version_proxy.rb', line 23 def __getobj__ @record end |
#__setobj__(record) ⇒ Object
27 28 29 |
# File 'lib/active_versioning/model/version_proxy.rb', line 27 def __setobj__(record) @record = record end |
#commit(params = {}) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/active_versioning/model/version_proxy.rb', line 87 def commit(params = {}) raise draft_exception unless version.draft? attrs = version_attributes.tap do |attrs| attrs.merge!( draft: false, event: ActiveVersioning::Events::COMMIT, committed_at: Time.current ) attrs.merge!(params) end version.update(attrs) __getobj__.update(versioned_attributes) end |
#live? ⇒ Boolean
79 80 81 |
# File 'lib/active_versioning/model/version_proxy.rb', line 79 def live? false end |
#reload ⇒ Object
35 36 37 |
# File 'lib/active_versioning/model/version_proxy.rb', line 35 def reload __setobj__(version.reify) end |
#save ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/active_versioning/model/version_proxy.rb', line 43 def save(*) if valid? version.update(version_attributes) else false end end |
#save! ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/active_versioning/model/version_proxy.rb', line 51 def save!(*) if valid? version.update!(version_attributes) else raise ::ActiveRecord::RecordInvalid.new(__getobj__) end end |
#to_param ⇒ Object
39 40 41 |
# File 'lib/active_versioning/model/version_proxy.rb', line 39 def to_param version.versionable.to_param end |
#update(attributes) ⇒ Object Also known as: update_attributes
59 60 61 62 63 64 65 66 |
# File 'lib/active_versioning/model/version_proxy.rb', line 59 def update(attributes) raise draft_exception unless version.draft? with_transaction_returning_status do assign_attributes(attributes) save end end |
#update!(attributes) ⇒ Object Also known as: update_attributes!
69 70 71 72 73 74 75 76 |
# File 'lib/active_versioning/model/version_proxy.rb', line 69 def update!(attributes) raise draft_exception unless version.draft? with_transaction_returning_status do assign_attributes(attributes) save! end end |
#version? ⇒ Boolean
83 84 85 |
# File 'lib/active_versioning/model/version_proxy.rb', line 83 def version? true end |