Class: Textus::CLI::Verb::Put
- Inherits:
-
Textus::CLI::Verb
- Object
- Textus::CLI::Verb
- Textus::CLI::Verb::Put
- Defined in:
- lib/textus/cli/verb/put.rb
Instance Attribute Summary
Attributes inherited from Textus::CLI::Verb
Instance Method Summary collapse
-
#call(store) ⇒ Object
rubocop:disable Metrics/AbcSize.
Methods inherited from Textus::CLI::Verb
command_name, #context_for, descendants, #emit, inherited, #initialize, needs_store?, #operations_for, option, options, parent_group, #parse, #resolved_role
Constructor Details
This class inherits a constructor from Textus::CLI::Verb
Instance Method Details
#call(store) ⇒ Object
rubocop:disable Metrics/AbcSize
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/textus/cli/verb/put.rb', line 11 def call(store) # rubocop:disable Metrics/AbcSize key = positional.shift or raise UsageError.new("put requires a key") raise UsageError.new("put requires --stdin in v1") unless use_stdin role = resolved_role(store) raw = @stdin.read payload = if fetch_name callable = store.bus.rpc_callable(:resolve_intake, fetch_name) result = begin Timeout.timeout(Textus::Application::Refresh::Worker::FETCH_TIMEOUT_SECONDS) do callable.call(config: { "bytes" => raw }, store: store, args: {}) end rescue Timeout::Error raise UsageError.new( "fetch '#{fetch_name}' exceeded #{Textus::Application::Refresh::Worker::FETCH_TIMEOUT_SECONDS}s timeout", ) end basename = key.split(".").last { "_meta" => { "name" => basename, "last_refreshed_at" => Time.now.utc.iso8601, "fetched_with" => fetch_name, }.merge(result[:_meta] || result["_meta"] || {}), "body" => result[:body] || result["body"] || "", } else JSON.parse(raw) end = payload["_meta"] || {} body = payload["body"] || "" if_etag = payload["if_etag"] result = Textus::Operations.for(store, role: role).put(key, meta: , body: body, if_etag: if_etag) emit(result.to_h_for_wire) end |