Class: Hai::Update
- Inherits:
-
Object
- Object
- Hai::Update
- Defined in:
- lib/hai/update.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:, attributes:) ⇒ Object
-
#initialize(model, context) ⇒ Update
constructor
A new instance of Update.
Constructor Details
#initialize(model, context) ⇒ Update
Returns a new instance of Update.
5 6 7 8 |
# File 'lib/hai/update.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/update.rb', line 3 def context @context end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
3 4 5 |
# File 'lib/hai/update.rb', line 3 def model @model end |
Instance Method Details
#execute(id:, attributes:) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/hai/update.rb', line 10 def execute(id:, attributes:) record = model.find(id) return unless check_policy(record) if record.update(**attributes) { errors: [], result: record } else { errors: record.errors.map(&:full_message), result: nil } end end |