Module: ActiveZone::Zone::Builtins::Persistence
- Extended by:
- ActiveSupport::Concern
- Included in:
- ActiveZone::Zone::Builtins
- Defined in:
- lib/active_zone/zone/builtins/persistence.rb
Overview
Adds Active Record-like persistence methods to Provider::Zone
Instance Method Summary collapse
-
#destroy ⇒ TrueClass, FalseClass
Destroys a Provider::Zone at the provider and freezes the Provider::Zone.
-
#destroy! ⇒ TrueClass
Destroys a Provider::Zone at the provider, freezes the Provider::Zone and raises errors on failure.
-
#save(**options, &block) ⇒ ActiveZone::Provider::Zone, FalseClass
Persists a Provider::Zone.
-
#save! ⇒ ActiveZone::Provider::Zone
Persists a Provider::Zone and raises an error on failure.
-
#update(attributes) ⇒ ActiveZone::Provider::Zone, FalseClass
Updates attributes of a Provider::Zone and saves it.
-
#update!(attributes) ⇒ ActiveZone::Provider::Zone, FalseClass
Updates attributes of a Provider::Zone, saves it and raises errors on failure.
Instance Method Details
#destroy ⇒ TrueClass, FalseClass
Destroys a Provider::Zone at the provider and freezes the Provider::Zone
116 117 118 119 120 121 122 123 124 |
# File 'lib/active_zone/zone/builtins/persistence.rb', line 116 def destroy run_callbacks(:destroy) do delete! if persisted? freeze end true rescue false end |
#destroy! ⇒ TrueClass
Destroys a Provider::Zone at the provider, freezes the Provider::Zone and raises errors on failure
129 130 131 |
# File 'lib/active_zone/zone/builtins/persistence.rb', line 129 def destroy! destroy || raise("Failed to destroy the zone") end |
#save(**options, &block) ⇒ ActiveZone::Provider::Zone, FalseClass
Persists a Provider::Zone
98 99 100 101 102 103 104 105 |
# File 'lib/active_zone/zone/builtins/persistence.rb', line 98 def save(**, &block) run_callbacks(:save) do persist! end self rescue false end |
#save! ⇒ ActiveZone::Provider::Zone
Persists a Provider::Zone and raises an error on failure
110 111 112 |
# File 'lib/active_zone/zone/builtins/persistence.rb', line 110 def save!(**, &) save(**, &) || raise("Failed to save the zone") end |
#update(attributes) ⇒ ActiveZone::Provider::Zone, FalseClass
Updates attributes of a Provider::Zone and saves it
135 136 137 138 |
# File 'lib/active_zone/zone/builtins/persistence.rb', line 135 def update(attributes) assign_attributes(attributes) save end |
#update!(attributes) ⇒ ActiveZone::Provider::Zone, FalseClass
Updates attributes of a Provider::Zone, saves it and raises errors on failure
143 144 145 |
# File 'lib/active_zone/zone/builtins/persistence.rb', line 143 def update!(attributes) update || raise("Failed to update the zone") end |