lib/wolf_core/utils/result.rb



module WolfCore
  class Result
    attr_accessor :data, :error
  
    def initialize(success:, data: nil, error: nil)
      @success = success
      @data = data
      @error = error
    end
  
    def self.success(data: {})
      Result.new(success: true, data: OpenStruct.new(data))
    end
  
    def self.failure(error: {})
      Result.new(success: false, error: OpenStruct.new(error))
    end
  
    def success?
      @success
    end
  
    def failure?
      !@success
    end
  end
end