Class: Hai::Delete
- Inherits:
-
Object
- Object
- Hai::Delete
- Defined in:
- lib/hai/delete.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #execute(id:) ⇒ Object
-
#initialize(model, context) ⇒ Delete
constructor
A new instance of Delete.
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
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'lib/hai/delete.rb', line 3 def context @context end |
#model ⇒ Object (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
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 |