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.
61 62 63 |
# File 'lib/warp/dir/app/response.rb', line 61 def initialize @messages = [] end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
59 60 61 |
# File 'lib/warp/dir/app/response.rb', line 59 def config @config end |
#messages ⇒ Object
Returns the value of attribute messages.
59 60 61 |
# File 'lib/warp/dir/app/response.rb', line 59 def @messages end |
Class Method Details
.configure(&block) ⇒ Object
83 84 85 |
# File 'lib/warp/dir/app/response.rb', line 83 def self.configure(&block) self.instance.configure(&block) end |
Instance Method Details
#code(value = nil) ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/warp/dir/app/response.rb', line 106 def code(value = nil) if value @type.exit_code = value self else @type.exit_code end end |
#configure(&block) ⇒ Object
Configure & Accessors
78 79 80 81 |
# File 'lib/warp/dir/app/response.rb', line 78 def configure(&block) self.instance_eval(&block) self end |
#exit! ⇒ Object
72 73 74 75 |
# File 'lib/warp/dir/app/response.rb', line 72 def exit! raise ::ArgumentError.new('No type defined for Response object') unless @type system_exit!(@type.exit_code) end |
#inspect ⇒ Object
115 116 117 |
# File 'lib/warp/dir/app/response.rb', line 115 def inspect "#{self.class.name}={#{type.inspect}, #{.inspect}}" end |
#message(message = nil) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/warp/dir/app/response.rb', line 87 def ( = nil) if @messages << self else @messages.join('') end end |
#print ⇒ Object
Public Methods
66 67 68 69 70 |
# File 'lib/warp/dir/app/response.rb', line 66 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
119 120 121 |
# File 'lib/warp/dir/app/response.rb', line 119 def to_s "AppResponse[type: {#{type}}, messages: '#{.join(' ')}']" end |
#type(a_type = nil) ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/warp/dir/app/response.rb', line 96 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 |