Class: Vigilem::Core::AbstractDevice

Inherits:
Support::LazySimpleDelegator
  • Object
show all
Extended by:
Support::ObjSpace, Hooks
Includes:
Vigilem::Core::Adapters::Adapter
Defined in:
lib/vigilem/core/abstract_device.rb

Direct Known Subclasses

Device

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Hooks

extended, run_hook

Methods included from Hooks::Inheritable

#hooks, #inherited

Methods included from Vigilem::Core::Adapters::Adapter

#affix, #attach, #initialize_adapter

Methods included from LockablePipelineComponent

#semaphore, #semaphore!, #synchronize

Methods included from Vigilem::Core::Adapters::BasicAdapter

#initialize_basic_adapter, #source

Class Method Details

.inherited(base) ⇒ Object

Parameters:

  • base (Class)

Returns:



34
35
36
37
38
39
40
41
# File 'lib/vigilem/core/abstract_device.rb', line 34

def inherited(base)
  super(base)
  hooks.select(&:inheritable?).each do |hook|
    base.instance_eval do
      define_method(hook.name, &hook)
    end
  end
end

.new(*args, &block) ⇒ Object

Parameters:

  • args (Array)
  • block (Proc)


25
26
27
28
29
# File 'lib/vigilem/core/abstract_device.rb', line 25

def new(*args, &block)
  ret = obj_register(super(*args, &block))
  run_hook(:after_init, ret)
  ret
end

Instance Method Details

#available?TrueClass || FalseClass

if any system_checks pass this device is available

Returns:

  • (TrueClass || FalseClass)

    whether or not it’s available



81
82
83
# File 'lib/vigilem/core/abstract_device.rb', line 81

def available?
  self.settings.any? {|name, hook| hook.options[:type] == :system_check }
end

#import(obj) ⇒ Object

Parameters:

  • obj

Returns:



88
89
90
91
# File 'lib/vigilem/core/abstract_device.rb', line 88

def import(obj)
  self.link = obj
  __setobj__(obj)
end

#run_system_checksArray<Hook>

calls all the hooks with options == :system_check

Returns:

  • (Array<Hook>)

    the hooks that ran



53
54
55
56
57
# File 'lib/vigilem/core/abstract_device.rb', line 53

def run_system_checks
  self.class.hooks.select {|hook| hook.options[:type] == :system_check }.map do |hook|
    run_hook hook.name
  end
end

#setting?(hook) ⇒ TrueClass || FalseClass

test whether or not a hook is a setting

Parameters:

  • hook (Hook)

    the hook to test

Returns:

  • (TrueClass || FalseClass)


74
75
76
77
# File 'lib/vigilem/core/abstract_device.rb', line 74

def setting?(hook)
  conditional = hook.respond_to?(:passed)
  (not conditional) or (conditional and not hook.passed.empty?)
end

#settingsArray<CallBack>

the Callbacks that passed/ran

Returns:

  • (Array<CallBack>)


61
62
63
64
65
66
67
68
69
# File 'lib/vigilem/core/abstract_device.rb', line 61

def settings
  hks = self.class.hooks
  passed_hooks = hks.select {|hk| hk.respond_to?(:passed) }
  if _hooks_status_hash_cache_ != (nw_hash = passed_hooks.map(&:status_hash).join)
    @settings = hks.select {|hook| setting?(hook) }.compact
    _hooks_status_hash_cache_ = nw_hash
  end
  @settings
end