Class: Warp::Dir::App::Response
Defined Under Namespace
Classes: Type
Constant Summary collapse
- INFO =
Type.new(0, $stdout)
- ERROR =
Type.new(1, $stderr)
- SHELL =
Type.new(2, $stdout)
- RETURN_TYPE =
{ success: INFO, error: ERROR, shell: SHELL }
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#messages ⇒ Object
Returns the value of attribute messages.
Class Method Summary collapse
Instance Method Summary collapse
- #code(value = nil) ⇒ Object
-
#configure(&block) ⇒ Object
Configure & Accessors.
- #exit! ⇒ Object
-
#initialize ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ Object
- #message(message = nil) ⇒ Object
-
#print ⇒ Object
Public Methods.
- #to_s ⇒ Object
- #type(a_type = nil) ⇒ Object
Constructor Details
#initialize ⇒ Response
Returns a new instance of Response.
59 60 61 |
# File 'lib/warp/dir/app/response.rb', line 59 def initialize @messages = [] end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
57 58 59 |
# File 'lib/warp/dir/app/response.rb', line 57 def config @config end |
#messages ⇒ Object
Returns the value of attribute messages.
57 58 59 |
# File 'lib/warp/dir/app/response.rb', line 57 def @messages end |
Class Method Details
.configure(&block) ⇒ Object
81 82 83 |
# File 'lib/warp/dir/app/response.rb', line 81 def self.configure(&block) self.instance.configure(&block) end |
Instance Method Details
#code(value = nil) ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/warp/dir/app/response.rb', line 104 def code(value = nil) if value @type.exit_code = value self else @type.exit_code end end |
#configure(&block) ⇒ Object
Configure & Accessors
76 77 78 79 |
# File 'lib/warp/dir/app/response.rb', line 76 def configure(&block) self.instance_eval(&block) self end |
#exit! ⇒ Object
70 71 72 73 |
# File 'lib/warp/dir/app/response.rb', line 70 def exit! raise ::ArgumentError.new('No type defined for Response object') unless @type system_exit!(@type.exit_code) end |
#inspect ⇒ Object
113 114 115 |
# File 'lib/warp/dir/app/response.rb', line 113 def inspect "#{self.class.name}={#{type.inspect}, #{.inspect}}" end |
#message(message = nil) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/warp/dir/app/response.rb', line 85 def ( = nil) if @messages << self else @messages.join end end |
#print ⇒ Object
Public Methods
64 65 66 67 68 |
# File 'lib/warp/dir/app/response.rb', line 64 def print raise ::ArgumentError.new('No type defined for Response object') unless @type @type.print(@messages.shift) until @messages.empty? self end |
#to_s ⇒ Object
117 118 119 |
# File 'lib/warp/dir/app/response.rb', line 117 def to_s "AppResponse[type: {#{type}}, messages: '#{.join(' ')}']" end |
#type(a_type = nil) ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/warp/dir/app/response.rb', line 94 def type(a_type = nil) if a_type @type = a_type.kind_of?(Warp::Dir::App::Response::Type) ? a_type : RETURN_TYPE[a_type] raise(::ArgumentError.new("Can't find response type #{a_type} #{@type}")) unless @type self else @type end end |