Class: Vigilem::Core::AbstractDevice
- Inherits:
-
Support::LazySimpleDelegator
- Object
- Support::LazySimpleDelegator
- Vigilem::Core::AbstractDevice
- Extended by:
- Support::ObjSpace, Hooks
- Includes:
- Vigilem::Core::Adapters::Adapter
- Defined in:
- lib/vigilem/core/abstract_device.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
-
#available? ⇒ TrueClass || FalseClass
if any system_checks pass this device is available.
- #import(obj) ⇒ Object
-
#run_system_checks ⇒ Array<Hook>
calls all the hooks with options == :system_check.
-
#setting?(hook) ⇒ TrueClass || FalseClass
test whether or not a hook is a setting.
-
#settings ⇒ Array<CallBack>
the Callbacks that passed/ran.
Methods included from Hooks
Methods included from Hooks::Inheritable
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
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
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
81 82 83 |
# File 'lib/vigilem/core/abstract_device.rb', line 81 def available? self.settings.any? {|name, hook| hook.[:type] == :system_check } end |
#import(obj) ⇒ Object
88 89 90 91 |
# File 'lib/vigilem/core/abstract_device.rb', line 88 def import(obj) self.link = obj __setobj__(obj) end |
#run_system_checks ⇒ Array<Hook>
calls all the hooks with options == :system_check
53 54 55 56 57 |
# File 'lib/vigilem/core/abstract_device.rb', line 53 def run_system_checks self.class.hooks.select {|hook| hook.[: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
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 |
#settings ⇒ Array<CallBack>
the Callbacks that passed/ran
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 |