Class: TurbineRb::Client::App::Collection

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, records, stream, app) ⇒ Collection

Returns a new instance of Collection.



107
108
109
110
111
112
# File 'lib/turbine_rb/client.rb', line 107

def initialize(name, records, stream, app)
  @name = name
  @pb_records = records
  @pb_stream = stream
  @app = app
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



99
100
101
# File 'lib/turbine_rb/client.rb', line 99

def app
  @app
end

#nameObject

Returns the value of attribute name.



99
100
101
# File 'lib/turbine_rb/client.rb', line 99

def name
  @name
end

#pb_recordsObject

Returns the value of attribute pb_records.



99
100
101
# File 'lib/turbine_rb/client.rb', line 99

def pb_records
  @pb_records
end

#pb_streamObject

Returns the value of attribute pb_stream.



99
100
101
# File 'lib/turbine_rb/client.rb', line 99

def pb_stream
  @pb_stream
end

Class Method Details

.unwrap(collection) ⇒ Object



101
102
103
104
105
# File 'lib/turbine_rb/client.rb', line 101

def self.unwrap(collection)
  return collection.unwrap if collection.instance_of?(Collection)

  collection
end

Instance Method Details

#process_with(process:) ⇒ Object



118
119
120
# File 'lib/turbine_rb/client.rb', line 118

def process_with(process:)
  app.process(records: self, process: process)
end

#recordsObject



122
123
124
125
126
# File 'lib/turbine_rb/client.rb', line 122

def records
  return pb_records.to_a if pb_records.respond_to?(:to_a)

  [pb_records].compact.flatten
end

#unwrapObject



128
129
130
131
132
133
134
# File 'lib/turbine_rb/client.rb', line 128

def unwrap
  TurbineCore::Collection.new( # convert back to TurbineCore::Collection
    name: name,
    records: records,
    stream: pb_stream
  )
end

#write_to(resource:, collection:, configs: nil) ⇒ Object



114
115
116
# File 'lib/turbine_rb/client.rb', line 114

def write_to(resource:, collection:, configs: nil)
  resource.write(records: self, collection: collection, configs: configs)
end