Class: Yuriita::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/yuriita/result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relation: nil, exception: nil) ⇒ Result

Returns a new instance of Result.



13
14
15
16
17
18
19
20
# File 'lib/yuriita/result.rb', line 13

def initialize(relation: nil, exception: nil)
  @relation = relation
  @exception = exception

  if @relation.nil? && @exception.nil?
    raise ArgumentError, "Must provide a relation or an exception"
  end
end

Instance Attribute Details

#exceptionObject (readonly)

Returns the value of attribute exception.



11
12
13
# File 'lib/yuriita/result.rb', line 11

def exception
  @exception
end

#relationObject (readonly)

Returns the value of attribute relation.



11
12
13
# File 'lib/yuriita/result.rb', line 11

def relation
  @relation
end

Class Method Details

.error(exception) ⇒ Object



3
4
5
# File 'lib/yuriita/result.rb', line 3

def self.error(exception)
  new(exception: exception)
end

.success(relation) ⇒ Object



7
8
9
# File 'lib/yuriita/result.rb', line 7

def self.success(relation)
  new(relation: relation)
end

Instance Method Details

#successful?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/yuriita/result.rb', line 22

def successful?
  exception.nil?
end