Class: TurbineRb::Client::App

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

Defined Under Namespace

Classes: Collection, Resource

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(grpc_server, recording:) ⇒ App

Returns a new instance of App.



10
11
12
13
# File 'lib/turbine_rb/client.rb', line 10

def initialize(grpc_server, recording:)
  @core_server = grpc_server
  @recording = recording
end

Instance Attribute Details

#core_serverObject (readonly)

Returns the value of attribute core_server.



8
9
10
# File 'lib/turbine_rb/client.rb', line 8

def core_server
  @core_server
end

Instance Method Details

#process(records:, process:) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/turbine_rb/client.rb', line 25

def process(records:, process:)
  new_records = records.dup
  pb_collection = core_server.add_process_to_collection(
    TurbineCore::ProcessCollectionRequest.new(
      collection: Collection.unwrap(new_records),
      process: TurbineCore::ProcessCollectionRequest::Process.new(name: process.class.name)
    )
  )
  new_records.tap do |r|
    r.pb_records = process_call(process: process, pb_collection: pb_collection)
    r.pb_stream = pb_collection.stream
  end
end

#process_call(process:, pb_collection:) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/turbine_rb/client.rb', line 39

def process_call(process:, pb_collection:)
  return pb_collection.records if recording?

  process
    .call(records: TurbineRb::Records.new(pb_collection.records))
    .map(&:serialize_core_record)
end

#recording?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/turbine_rb/client.rb', line 15

def recording?
  @recording
end

#register_secrets(secrets) ⇒ Object

register_secrets accepts either a single string or an array of strings



48
49
50
51
52
53
54
55
# File 'lib/turbine_rb/client.rb', line 48

def register_secrets(secrets)
  [secrets].flatten.map do |secret|
    raise MissingSecretError, "secret #{secret} is not an environment variable" unless ENV.key?(secret)

    req = TurbineCore::Secret.new(name: secret, value: ENV[secret])
    core_server.register_secret(req)
  end
end

#resource(name:) ⇒ Object



19
20
21
22
23
# File 'lib/turbine_rb/client.rb', line 19

def resource(name:)
  req = TurbineCore::GetResourceRequest.new(name: name)
  res = @core_server.get_resource(req)
  Resource.new(res, self)
end