Class: Pug::Types::Result

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

Overview

Encapsulates a sucess/failure result

Types collapse

SUCCESS =
0
INFO =
1
ERROR =
2

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#errorString

Note:

exists only for ERROR type

Returns the output of the Action.

Returns:

  • (String)

    the output of the Action



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pug/types/result.rb', line 17

class Result
  attr_reader :type, :value, :error
  private_class_method :new

  # @!group Types
  SUCCESS = 0
  INFO = 1
  ERROR = 2
  # @!endgroup

  # @!visibility private
  def initialize(type, value, error)
    raise 'Invalid type' unless [SUCCESS, INFO, ERROR].include?(type)
    @type = type
    @value = value
    @error = error
  end

  # Defines a SUCCESS Result
  # @param value [String] value for Result
  # @return [Result] with value and no error
  def self.success(value)
    new(SUCCESS, value, nil)
  end

  # Defines an INFO Result
  # @param value [String] value for Result
  # @return [Result] with value and no error
  def self.info(value)
    new(INFO, value, nil)
  end

  # Defines an ERROR Result
  # @param error [String] error for Result
  # @return [Result] with error and no value
  def self.error(error)
    new(ERROR, nil, error)
  end
end

#typeInteger

Returns the type of the Result.

Returns:

  • (Integer)

    the type of the Result

See Also:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pug/types/result.rb', line 17

class Result
  attr_reader :type, :value, :error
  private_class_method :new

  # @!group Types
  SUCCESS = 0
  INFO = 1
  ERROR = 2
  # @!endgroup

  # @!visibility private
  def initialize(type, value, error)
    raise 'Invalid type' unless [SUCCESS, INFO, ERROR].include?(type)
    @type = type
    @value = value
    @error = error
  end

  # Defines a SUCCESS Result
  # @param value [String] value for Result
  # @return [Result] with value and no error
  def self.success(value)
    new(SUCCESS, value, nil)
  end

  # Defines an INFO Result
  # @param value [String] value for Result
  # @return [Result] with value and no error
  def self.info(value)
    new(INFO, value, nil)
  end

  # Defines an ERROR Result
  # @param error [String] error for Result
  # @return [Result] with error and no value
  def self.error(error)
    new(ERROR, nil, error)
  end
end

#valueString

Note:

exists only for SUCCESS and INFO types

Returns the value of the Result.

Returns:

  • (String)

    the value of the Result



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pug/types/result.rb', line 17

class Result
  attr_reader :type, :value, :error
  private_class_method :new

  # @!group Types
  SUCCESS = 0
  INFO = 1
  ERROR = 2
  # @!endgroup

  # @!visibility private
  def initialize(type, value, error)
    raise 'Invalid type' unless [SUCCESS, INFO, ERROR].include?(type)
    @type = type
    @value = value
    @error = error
  end

  # Defines a SUCCESS Result
  # @param value [String] value for Result
  # @return [Result] with value and no error
  def self.success(value)
    new(SUCCESS, value, nil)
  end

  # Defines an INFO Result
  # @param value [String] value for Result
  # @return [Result] with value and no error
  def self.info(value)
    new(INFO, value, nil)
  end

  # Defines an ERROR Result
  # @param error [String] error for Result
  # @return [Result] with error and no value
  def self.error(error)
    new(ERROR, nil, error)
  end
end

Class Method Details

.error(error) ⇒ Result

Defines an ERROR Result

Parameters:

  • error (String)

    error for Result

Returns:

  • (Result)

    with error and no value



52
53
54
# File 'lib/pug/types/result.rb', line 52

def self.error(error)
  new(ERROR, nil, error)
end

.info(value) ⇒ Result

Defines an INFO Result

Parameters:

  • value (String)

    value for Result

Returns:

  • (Result)

    with value and no error



45
46
47
# File 'lib/pug/types/result.rb', line 45

def self.info(value)
  new(INFO, value, nil)
end

.success(value) ⇒ Result

Defines a SUCCESS Result

Parameters:

  • value (String)

    value for Result

Returns:

  • (Result)

    with value and no error



38
39
40
# File 'lib/pug/types/result.rb', line 38

def self.success(value)
  new(SUCCESS, value, nil)
end