Class: Pug::Types::Result
- Inherits:
-
Object
- Object
- Pug::Types::Result
- 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
-
#error ⇒ String
The output of the Action.
-
#type ⇒ Integer
The type of the Result.
-
#value ⇒ String
The value of the Result.
Class Method Summary collapse
-
.error(error) ⇒ Result
Defines an ERROR Result.
-
.info(value) ⇒ Result
Defines an INFO Result.
-
.success(value) ⇒ Result
Defines a SUCCESS Result.
Instance Attribute Details
#error ⇒ String
Note:
exists only for ERROR type
Returns 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 |
#type ⇒ Integer
Returns the type 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 |
#value ⇒ String
Note:
exists only for SUCCESS and INFO types
Returns 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
52 53 54 |
# File 'lib/pug/types/result.rb', line 52 def self.error(error) new(ERROR, nil, error) end |