Class: Once::ActionKey
- Inherits:
-
Object
- Object
- Once::ActionKey
- Defined in:
- lib/buildonce.rb
Instance Method Summary collapse
- #add_bytes(label, bytes) ⇒ Object
- #add_digest(label, digest) ⇒ Object
- #digest ⇒ Object
-
#initialize(namespace) ⇒ ActionKey
constructor
A new instance of ActionKey.
Constructor Details
#initialize(namespace) ⇒ ActionKey
Returns a new instance of ActionKey.
167 168 169 170 171 172 |
# File 'lib/buildonce.rb', line 167 def initialize(namespace) raise ArgumentError, "namespace must be a String" unless namespace.is_a?(String) @namespace = namespace @inputs = [] end |
Instance Method Details
#add_bytes(label, bytes) ⇒ Object
174 175 176 177 178 |
# File 'lib/buildonce.rb', line 174 def add_bytes(label, bytes) validate_label(label) @inputs << { kind: "bytes", label: label, bytes: bytes.to_s.b.bytes } self end |
#add_digest(label, digest) ⇒ Object
180 181 182 183 184 |
# File 'lib/buildonce.rb', line 180 def add_digest(label, digest) validate_label(label) @inputs << { kind: "digest", label: label, digest: digest } self end |
#digest ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/buildonce.rb', line 186 def digest pointer = Native.once_action_key_json( JSON.generate(namespace: @namespace, inputs: @inputs), ) raise Error, "native Once function returned null" if pointer.null? response = JSON.parse(pointer.read_string) return response.fetch("value") if response.fetch("status") == "ok" raise Error, response.fetch("message") rescue JSON::ParserError, KeyError => e raise Error, e. ensure Native.once_string_free(pointer) if pointer && !pointer.null? end |