Class: Hai::Delete

Inherits:
Object
  • Object
show all
Defined in:
lib/hai/delete.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, context) ⇒ Delete

Returns a new instance of Delete.



5
6
7
8
# File 'lib/hai/delete.rb', line 5

def initialize(model, context)
  @model = model
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



3
4
5
# File 'lib/hai/delete.rb', line 3

def context
  @context
end

#modelObject (readonly)

Returns the value of attribute model.



3
4
5
# File 'lib/hai/delete.rb', line 3

def model
  @model
end

Instance Method Details

#execute(id:) ⇒ Object

Raises:

  • (UnauthorizedError)


10
11
12
13
14
15
# File 'lib/hai/delete.rb', line 10

def execute(id:)
  record = model.find(id)
  raise UnauthorizedError if record.respond_to?(:check_hai_policy) && record.check_hai_policy(:delete, context)

  record.destroy
end