Class: Moon::Action::Model::Destroy

Inherits:
Object
  • Object
show all
Defined in:
lib/moon/action/model/destroy.rb

Overview

Generic model destroy action. Removes the specified model from the storage.

Instance Method Summary collapse

Constructor Details

#initialize(model_symbol) ⇒ Destroy

Returns a new instance of Destroy.



5
6
7
# File 'lib/moon/action/model/destroy.rb', line 5

def initialize(model_symbol)
  @model_symbol = model_symbol
end

Instance Method Details

#perform(context) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/moon/action/model/destroy.rb', line 9

def perform(context)
  model = context.models[@model_symbol]
  model_class = model.class
  if model
    GOM::Storage.remove model
    Moon::Response::JSON::Message.new 200, "#{model_class} destroyed."
  else
    Moon::Response::JSON::Message.new 401, "#{model_class} destruction failed."
  end
end