Class: KRPC::Streaming::Stream
- Inherits:
-
Object
- Object
- KRPC::Streaming::Stream
- Defined in:
- lib/krpc/streaming.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#kwargs ⇒ Object
readonly
Returns the value of attribute kwargs.
-
#manager ⇒ Object
readonly
Returns the value of attribute manager.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#return_type ⇒ Object
readonly
Returns the value of attribute return_type.
-
#value ⇒ Object
writeonly
Sets the attribute value.
Instance Method Summary collapse
-
#active? ⇒ Boolean
Check if stream is active (i.e. not removed).
- #coderay(x) ⇒ Object
-
#get ⇒ Object
(also: #value)
Get the current stream value.
-
#initialize(manager, id, return_type, value, method, *args, **kwargs) ⇒ Stream
constructor
A new instance of Stream.
- #inspect ⇒ Object
-
#mark_as_inactive ⇒ Object
Mark stream as inactive.
-
#remove ⇒ Object
(also: #close)
Remove stream.
- #to_s ⇒ Object
Constructor Details
#initialize(manager, id, return_type, value, method, *args, **kwargs) ⇒ Stream
Returns a new instance of Stream.
86 87 88 89 90 91 92 |
# File 'lib/krpc/streaming.rb', line 86 def initialize(manager, id, return_type, value, method, *args, **kwargs) @manager = manager @id = id @return_type, @value = return_type, value @method, @args, @kwargs = method, args, kwargs @active = true end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
83 84 85 |
# File 'lib/krpc/streaming.rb', line 83 def args @args end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
83 84 85 |
# File 'lib/krpc/streaming.rb', line 83 def id @id end |
#kwargs ⇒ Object (readonly)
Returns the value of attribute kwargs.
83 84 85 |
# File 'lib/krpc/streaming.rb', line 83 def kwargs @kwargs end |
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
83 84 85 |
# File 'lib/krpc/streaming.rb', line 83 def manager @manager end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
83 84 85 |
# File 'lib/krpc/streaming.rb', line 83 def method @method end |
#return_type ⇒ Object (readonly)
Returns the value of attribute return_type.
83 84 85 |
# File 'lib/krpc/streaming.rb', line 83 def return_type @return_type end |
#value=(value) ⇒ Object (writeonly)
Sets the attribute value
84 85 86 |
# File 'lib/krpc/streaming.rb', line 84 def value=(value) @value = value end |
Instance Method Details
#active? ⇒ Boolean
Check if stream is active (i.e. not removed).
108 |
# File 'lib/krpc/streaming.rb', line 108 def active?; @active end |
#coderay(x) ⇒ Object
119 120 121 122 123 124 125 126 |
# File 'lib/krpc/streaming.rb', line 119 def coderay(x) require 'coderay' if x.is_a?(Array) then "[" + x.map{|e| e.is_a?(Gen::ClassBase) ? e.inspect : coderay(e.inspect)}.join(", ") + "]" elsif x.is_a?(Hash) then "{" + x.map{|k,v| coderay(k.inspect) + "=>" + (v.is_a?(Gen::ClassBase) ? v.inspect : coderay(v.inspect))}.join(", ") + "}" else CodeRay.scan(x, :ruby).term end rescue Exception x.inspect end |
#get ⇒ Object Also known as: value
Get the current stream value. Has alias method ‘value`.
95 96 97 98 |
# File 'lib/krpc/streaming.rb', line 95 def get raise @value if @value.is_a?(Exception) @value end |
#inspect ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/krpc/streaming.rb', line 118 def inspect def coderay(x) require 'coderay' if x.is_a?(Array) then "[" + x.map{|e| e.is_a?(Gen::ClassBase) ? e.inspect : coderay(e.inspect)}.join(", ") + "]" elsif x.is_a?(Hash) then "{" + x.map{|k,v| coderay(k.inspect) + "=>" + (v.is_a?(Gen::ClassBase) ? v.inspect : coderay(v.inspect))}.join(", ") + "}" else CodeRay.scan(x, :ruby).term end rescue Exception x.inspect end "#<#{self.class}".green + " @id" + "=".green + id.to_s.bold.blue + " @active" + "=".green + @active.to_s.bold.light_cyan + "\n\t@method" + "=".green + method.inspect.green + (args.empty? ? "" : "\n\t@args" + "=".green + coderay(args)) + (kwargs.empty? ? "" : "\n\t@kwargs" + "=".green + coderay(kwargs)) + "\n\treturn_ruby_type" + "=".green + coderay(return_type.ruby_type) + ">".green end |
#mark_as_inactive ⇒ Object
Mark stream as inactive. WARNING: This method does not remove the stream. To remove the stream call Stream#remove instead.
112 |
# File 'lib/krpc/streaming.rb', line 112 def mark_as_inactive; @active = false end |
#remove ⇒ Object Also known as: close
Remove stream. Has alias method ‘close`.
102 103 104 |
# File 'lib/krpc/streaming.rb', line 102 def remove manager.remove_stream self end |
#to_s ⇒ Object
114 115 116 |
# File 'lib/krpc/streaming.rb', line 114 def to_s inspect.gsub(/\n|\t/," ").squeeze(" ").uncolorize end |