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

new(hash = {}) click to toggle source

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

==(other) click to toggle source

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
del(key) click to toggle source

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
get(key) click to toggle source

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(key, val) click to toggle source

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
to_h() click to toggle source

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
to_json(*arg) click to toggle source

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