Class: Cloudtasker::MetaStore
- Inherits:
-
Object
- Object
- Cloudtasker::MetaStore
- Defined in:
- lib/cloudtasker/meta_store.rb
Overview
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).
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Equality operator.
-
#del(key) ⇒ Any
Remove a meta information.
-
#get(key) ⇒ Any
Retrieve meta entry.
-
#initialize(hash = {}) ⇒ MetaStore
constructor
Build a new instance of the class.
-
#set(key, val) ⇒ Any
Set meta entry.
-
#to_h ⇒ Hash
Return the meta store as Hash.
-
#to_json(*arg) ⇒ String
Return the meta store as json.
Constructor Details
#initialize(hash = {}) ⇒ MetaStore
Build a new instance of the class.
16 17 18 |
# File 'lib/cloudtasker/meta_store.rb', line 16 def initialize(hash = {}) @meta = JSON.parse((hash || {}).to_json, symbolize_names: true) end |
Instance Method Details
#==(other) ⇒ Boolean
Equality operator.
82 83 84 |
# File 'lib/cloudtasker/meta_store.rb', line 82 def ==(other) to_json == other.try(:to_json) end |
#del(key) ⇒ Any
Remove a meta information.
50 51 52 |
# File 'lib/cloudtasker/meta_store.rb', line 50 def del(key) @meta.delete(key.to_sym) if key end |
#get(key) ⇒ Any
Retrieve meta entry.
27 28 29 |
# File 'lib/cloudtasker/meta_store.rb', line 27 def get(key) @meta[key.to_sym] if key end |
#set(key, val) ⇒ Any
Set meta entry
39 40 41 |
# File 'lib/cloudtasker/meta_store.rb', line 39 def set(key, val) @meta[key.to_sym] = val if key end |
#to_h ⇒ Hash
Return the meta store as Hash.
59 60 61 62 |
# 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) ⇒ String
Return the meta store as json.
71 72 73 |
# File 'lib/cloudtasker/meta_store.rb', line 71 def to_json(*arg) @meta.to_json(*arg) end |