discourse/lib/service/contract_base.rb
Loïc Guitaut 2f334964f2 DEV: Remove hash-like access from service contracts
We decided to keep only one way to access values from a contract. This
patch thus removes the hash-like access from contracts.
2024-10-29 16:02:51 +01:00

28 lines
517 B
Ruby

# frozen_string_literal: true
class Service::ContractBase
include ActiveModel::API
include ActiveModel::Attributes
include ActiveModel::AttributeMethods
include ActiveModel::Validations::Callbacks
delegate :slice, :merge, to: :to_hash
def initialize(*args, options: nil, **kwargs)
@__options__ = options
super(*args, **kwargs)
end
def options
@__options__
end
def to_hash
attributes.symbolize_keys
end
def raw_attributes
@attributes.values_before_type_cast
end
end