class Cloudtasker::MetaStore
Manage meta information on workers. This meta stored is intended to be used by middlewares needing to store extra information on the job. The objective of this class is to provide a shared store to middleware while controlling access to its keys by preveenting access the hash directly (e.g. avoid wild merge or replace operations).
Public Class Methods
Build a new instance of the class.
@param [<Type>] hash The worker meta hash
# File lib/cloudtasker/meta_store.rb, line 16 def initialize(hash = {}) @meta = JSON.parse((hash || {}).to_json, symbolize_names: true) end
Public Instance Methods
Equality operator.
@param [Any] other The object being compared.
@return [Boolean] True if the object is equal.
# File lib/cloudtasker/meta_store.rb, line 82 def ==(other) to_json == other.try(:to_json) end
Remove a meta information.
@param [String, Symbol] key The key of the entry to delete.
@return [Any] The value of the deleted key
# File lib/cloudtasker/meta_store.rb, line 50 def del(key) @meta.delete(key.to_sym) if key end
Retrieve meta entry.
@param [String, Symbol] key The key of the meta entry.
@return [Any] The value of the meta entry.
# File lib/cloudtasker/meta_store.rb, line 27 def get(key) @meta[key.to_sym] if key end
Set meta entry
@param [String, Symbol] key The key of the meta entry. @param [Any] val The value of the meta entry.
@return [Any] The value set
# File lib/cloudtasker/meta_store.rb, line 39 def set(key, val) @meta[key.to_sym] = val if key end
Return the meta store as Hash.
@return [Hash] The meta store as Hash.
# File lib/cloudtasker/meta_store.rb, line 59 def to_h # Deep dup JSON.parse(@meta.to_json, symbolize_names: true) end
Return the meta store as json.
@param [Array<any>] *arg The to_json
args.
@return [String] The meta store as json.
# File lib/cloudtasker/meta_store.rb, line 71 def to_json(*arg) @meta.to_json(*arg) end