Class: Session::Command

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

Overview

class History

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ Command

Returns a new instance of Command.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/session.rb', line 62

def initialize(command)
  @cmd = command.to_s
  @cmdno = self.class.cmdno
  self.class.cmdno += 1
  @err = ''
  @out = ''
  @cid = "%d_%d_%d" % [$$, cmdno, rand(Time.now.usec)]
  @begin_out = "__CMD_OUT_%s_BEGIN__" % cid
  @end_out = "__CMD_OUT_%s_END__" % cid
  @begin_out_pat = %r/#{ Regexp.escape(@begin_out) }/
  @end_out_pat = %r/#{ Regexp.escape(@end_out) }/
  @begin_err = "__CMD_ERR_%s_BEGIN__" % cid
  @end_err = "__CMD_ERR_%s_END__" % cid
  @begin_err_pat = %r/#{ Regexp.escape(@begin_err) }/
  @end_err_pat = %r/#{ Regexp.escape(@end_err) }/
end

Instance Attribute Details

#begin_errObject (readonly)

Returns the value of attribute begin_err.



57
58
59
# File 'lib/session.rb', line 57

def begin_err
  @begin_err
end

#begin_err_patObject (readonly)

Returns the value of attribute begin_err_pat.



59
60
61
# File 'lib/session.rb', line 59

def begin_err_pat
  @begin_err_pat
end

#begin_outObject (readonly)

Returns the value of attribute begin_out.



53
54
55
# File 'lib/session.rb', line 53

def begin_out
  @begin_out
end

#begin_out_patObject (readonly)

Returns the value of attribute begin_out_pat.



55
56
57
# File 'lib/session.rb', line 55

def begin_out_pat
  @begin_out_pat
end

#cidObject (readonly)

Returns the value of attribute cid.



52
53
54
# File 'lib/session.rb', line 52

def cid
  @cid
end

#cmdObject (readonly)

attributes



48
49
50
# File 'lib/session.rb', line 48

def cmd
  @cmd
end

#cmdnoObject (readonly)

Returns the value of attribute cmdno.



49
50
51
# File 'lib/session.rb', line 49

def cmdno
  @cmdno
end

#end_errObject (readonly)

Returns the value of attribute end_err.



58
59
60
# File 'lib/session.rb', line 58

def end_err
  @end_err
end

#end_err_patObject (readonly)

Returns the value of attribute end_err_pat.



60
61
62
# File 'lib/session.rb', line 60

def end_err_pat
  @end_err_pat
end

#end_outObject (readonly)

Returns the value of attribute end_out.



54
55
56
# File 'lib/session.rb', line 54

def end_out
  @end_out
end

#end_out_patObject (readonly)

Returns the value of attribute end_out_pat.



56
57
58
# File 'lib/session.rb', line 56

def end_out_pat
  @end_out_pat
end

#errObject

Returns the value of attribute err.



51
52
53
# File 'lib/session.rb', line 51

def err
  @err
end

#outObject

Returns the value of attribute out.



50
51
52
# File 'lib/session.rb', line 50

def out
  @out
end

Class Method Details

.cmdnoObject



43
# File 'lib/session.rb', line 43

def cmdno; @cmdno ||= 0; end

.cmdno=(n) ⇒ Object



44
# File 'lib/session.rb', line 44

def cmdno= n; @cmdno = n; end

Instance Method Details

#to_hashObject



78
79
80
# File 'lib/session.rb', line 78

def to_hash
  %w(cmdno cmd out err cid).inject({}){|h,k| h.update k => send(k) }
end

#to_yaml(*a, &b) ⇒ Object Also known as: to_s, to_str



81
82
83
# File 'lib/session.rb', line 81

def to_yaml(*a,&b)
  to_hash.to_yaml(*a,&b)
end