Class: KRPC::Streaming::Stream

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#argsObject (readonly)

Returns the value of attribute args.



83
84
85
# File 'lib/krpc/streaming.rb', line 83

def args
  @args
end

#idObject (readonly)

Returns the value of attribute id.



83
84
85
# File 'lib/krpc/streaming.rb', line 83

def id
  @id
end

#kwargsObject (readonly)

Returns the value of attribute kwargs.



83
84
85
# File 'lib/krpc/streaming.rb', line 83

def kwargs
  @kwargs
end

#managerObject (readonly)

Returns the value of attribute manager.



83
84
85
# File 'lib/krpc/streaming.rb', line 83

def manager
  @manager
end

#methodObject (readonly)

Returns the value of attribute method.



83
84
85
# File 'lib/krpc/streaming.rb', line 83

def method
  @method
end

#return_typeObject (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

Parameters:

  • value

    the value to set the attribute value to.



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).

Returns:



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

#getObject Also known as: value

Get the current stream value. Has alias method ‘value`.

Raises:



95
96
97
98
# File 'lib/krpc/streaming.rb', line 95

def get
  raise @value if @value.is_a?(Exception)
  @value
end

#inspectObject



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_inactiveObject

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

#removeObject 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_sObject



114
115
116
# File 'lib/krpc/streaming.rb', line 114

def to_s
  inspect.gsub(/\n|\t/," ").squeeze(" ").uncolorize
end