Class: KSConnect::API::Plugin::Data
- Inherits:
-
Object
- Object
- KSConnect::API::Plugin::Data
- Includes:
- Logs
- Defined in:
- lib/ksconnect/api/plugin/data.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #[](field) ⇒ Object
- #[]=(field, value) ⇒ Object
- #delete(field) ⇒ Object
- #getall ⇒ Object
-
#initialize(plugin_name, domain_name, type = :data, use_cache = true) ⇒ Data
constructor
A new instance of Data.
- #key ⇒ Object
- #reload ⇒ Object
- #setall(hash) ⇒ Object
Methods included from Logs
Constructor Details
#initialize(plugin_name, domain_name, type = :data, use_cache = true) ⇒ Data
Returns a new instance of Data.
12 13 14 15 16 17 18 19 20 |
# File 'lib/ksconnect/api/plugin/data.rb', line 12 def initialize(plugin_name, domain_name, type = :data, use_cache = true) @plugin_name = plugin_name @domain_name = domain_name @type = type @use_cache = use_cache @cache = ActiveSupport::HashWithIndifferentAccess.new if @use_cache @cache_uuid = nil end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/ksconnect/api/plugin/data.rb', line 10 def type @type end |
Instance Method Details
#[](field) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/ksconnect/api/plugin/data.rb', line 34 def [](field) if @use_cache @cache = redis.hgetall(key) if @cache.empty? @cache[field] else redis.hget(key, field) end end |
#[]=(field, value) ⇒ Object
22 23 24 25 26 |
# File 'lib/ksconnect/api/plugin/data.rb', line 22 def []=(field, value) @cache[field] = value if @use_cache redis.hset(key, field, value) redis.publish("core:push", { plugin_name: @plugin_name, domain_name: @domain_name, request_type: 'update' }.to_json) end |
#delete(field) ⇒ Object
56 57 58 59 |
# File 'lib/ksconnect/api/plugin/data.rb', line 56 def delete(field) @cache.delete(field) if @use_cache redis.hdel(key, field) end |
#getall ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/ksconnect/api/plugin/data.rb', line 43 def getall if @use_cache @cache = redis.hgetall(key) if @cache.empty?; @cache else redis.hgetall(key) end end |
#key ⇒ Object
61 62 63 64 |
# File 'lib/ksconnect/api/plugin/data.rb', line 61 def key set_data_uuid unless @cache_uuid "kloudsec_data:#{@cache_uuid}" end |
#reload ⇒ Object
51 52 53 54 |
# File 'lib/ksconnect/api/plugin/data.rb', line 51 def reload @cache = redis.hgetall(key) if @use_cache @cache end |
#setall(hash) ⇒ Object
28 29 30 31 32 |
# File 'lib/ksconnect/api/plugin/data.rb', line 28 def setall(hash) @cache = @cache.merge(hash) if @use_cache redis.mapped_hmset(key, hash) redis.publish("core:push", { plugin_name: @plugin_name, domain_name: @domain_name, request_type: 'update' }.to_json) end |