Class: ShareDataWatcher::Type::Base
- Inherits:
-
Object
- Object
- ShareDataWatcher::Type::Base
show all
- Extended by:
- Forwardable
- Includes:
- Loggable
- Defined in:
- lib/share-data-watcher/type/base.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Loggable
#debug, #error, #info, #warn
Constructor Details
#initialize(endpoints, key, opt = {}) ⇒ Base
Returns a new instance of Base.
14
15
16
17
18
19
20
21
22
|
# File 'lib/share-data-watcher/type/base.rb', line 14
def initialize(endpoints, key, opt = {})
@key = key
@struct = determine_struct_klass(opt[:struct])
@extension = opt[:extension]
@regex = extension && Regexp.new("^#{key}#{extension.gsub(/[.]/, '[.]').gsub(/%{(\w+)}/, '([a-zA-Z0-9\-\_]+)')}$")
@connection = Connection.new(endpoints)
reset
on_init
end
|
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
12
13
14
|
# File 'lib/share-data-watcher/type/base.rb', line 12
def key
@key
end
|
Instance Method Details
#get(**params) ⇒ Object
24
25
26
27
|
# File 'lib/share-data-watcher/type/base.rb', line 24
def get(**params)
key = fetch_key(params)
values[key.to_sym]
end
|
#restart ⇒ Object
37
38
39
40
|
# File 'lib/share-data-watcher/type/base.rb', line 37
def restart
shutdown
on_init
end
|
#shutdown ⇒ Object
33
34
35
|
# File 'lib/share-data-watcher/type/base.rb', line 33
def shutdown
reset
end
|
#to_h ⇒ Object
Also known as:
to_hash
42
43
44
45
46
|
# File 'lib/share-data-watcher/type/base.rb', line 42
def to_h
values.each_with_object({}) do |(key, value), result|
result[key] = value.respond_to?(:to_h) ? value.to_h : value
end
end
|
#valid? ⇒ Boolean
29
30
31
|
# File 'lib/share-data-watcher/type/base.rb', line 29
def valid?
@valid
end
|