Files
velour/app/services/result.rb
Dan Milne 88a906064f
Some checks failed
CI / scan_ruby (push) Has been cancelled
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
CI / system-test (push) Has been cancelled
Much base work started
2025-10-31 14:36:14 +11:00

35 lines
607 B
Ruby

class Result
attr_reader :data, :error
def initialize(success:, data: {}, error: nil)
@success = success
@data = data
@error = error
end
def success?
@success
end
def failure?
!@success
end
def self.success(data = {})
new(success: true, data: data)
end
def self.failure(error)
new(success: false, error: error)
end
# Allow accessing data as methods
def method_missing(method, *args)
return @data[method] if @data.key?(method)
super
end
def respond_to_missing?(method, include_private = false)
@data.key?(method) || super
end
end