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

Instance Method Details

#destroyTrueClass, FalseClass

Destroys a Provider::Zone at the provider and freezes the Provider::Zone

Returns:

  • (TrueClass)

    if true

  • (FalseClass)

    if false



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

Returns:

  • (TrueClass)

Raises:

  • (RuntimeError)


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

Returns:



98
99
100
101
102
103
104
105
# File 'lib/active_zone/zone/builtins/persistence.rb', line 98

def save(**options, &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

Returns:

Raises:

  • (RuntimeError)


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

Returns:



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

Returns:

Raises:

  • (RuntimeError)


143
144
145
# File 'lib/active_zone/zone/builtins/persistence.rb', line 143

def update!(attributes)
  update || raise("Failed to update the zone")
end