Class: ShareDataWatcher::Type::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Loggable
Defined in:
lib/share-data-watcher/type/base.rb

Overview

Base Type

Direct Known Subclasses

Fetch, Watch

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

#keyObject (readonly)

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

#restartObject



37
38
39
40
# File 'lib/share-data-watcher/type/base.rb', line 37

def restart
  shutdown
  on_init
end

#shutdownObject



33
34
35
# File 'lib/share-data-watcher/type/base.rb', line 33

def shutdown
  reset
end

#to_hObject 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

Returns:

  • (Boolean)


29
30
31
# File 'lib/share-data-watcher/type/base.rb', line 29

def valid?
  @valid
end