Class: OpenHAB::Core::Provider Abstract
- Inherits:
-
org.openhab.core.common.registry.AbstractProvider
- Object
- org.openhab.core.common.registry.AbstractProvider
- OpenHAB::Core::Provider
- Includes:
- Enumerable
- Defined in:
- lib/openhab/core/provider.rb
Overview
Direct Known Subclasses
Items::Metadata::Provider, Items::Provider, Items::Semantics::Provider, Rules::Provider, Sitemaps::Provider, Things::Links::Provider, Things::Provider
Class Attribute Summary collapse
-
.registry ⇒ org.openhab.core.common.registry.Registry
readonly
abstract
The registry that this provider provides elements for.
- .type ⇒ Symbol readonly
Class Method Summary collapse
-
.current(preferred_provider = nil, element = nil) ⇒ org.openhab.core.common.registry.Provider
Determines the current provider that should be used to create elements belonging to this registry.
Instance Method Summary collapse
-
#[](key) ⇒ Object
(also: #get)
Get an element from this provider.
-
#all ⇒ Array<Object>
(also: #getAll)
Get all elements in this provider.
- #inspect ⇒ String
Methods included from Enumerable
#all_groups, #all_members, #command, #command!, #decrease, #down, #equipments, #fast_forward, #groups, #increase, #locations, #member_of, #members, #move, #next, #not_member_of, #not_tagged, #off, #on, #pause, #play, #points, #previous, #refresh, #rewind, #stop, #tagged, #toggle, #up, #update!
Class Attribute Details
.registry ⇒ org.openhab.core.common.registry.Registry (readonly)
The registry that this provider provides elements for.
104 105 106 |
# File 'lib/openhab/core/provider.rb', line 104 def registry raise NotImplementedError end |
.type ⇒ Symbol (readonly)
141 142 143 |
# File 'lib/openhab/core/provider.rb', line 141 def type name.split("::")[-2].downcase.to_sym end |
Class Method Details
.current(preferred_provider = nil, element = nil) ⇒ org.openhab.core.common.registry.Provider
Determines the current provider that should be used to create elements belonging to this registry.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/openhab/core/provider.rb', line 75 def current(preferred_provider = nil, element = nil) preferred_provider ||= Thread.current[:openhab_providers]&.[](type) if preferred_provider.is_a?(Proc) preferred_provider = if preferred_provider.arity.zero? || element.nil? preferred_provider.call else preferred_provider.call(element) end end case preferred_provider when nil, :transient instance when :persistent registry.managed_provider.get when org.openhab.core.common.registry.ManagedProvider preferred_provider else raise ArgumentError, "#{preferred_provider.inspect} is not a ManagedProvider" end end |
Instance Method Details
#[](key) ⇒ Object Also known as: get
Get an element from this provider
173 174 175 |
# File 'lib/openhab/core/provider.rb', line 173 def [](key) @elements[key] end |
#all ⇒ Array<Object> Also known as: getAll
Get all elements in this provider
183 184 185 |
# File 'lib/openhab/core/provider.rb', line 183 def all @elements.values end |
#inspect ⇒ String
152 153 154 |
# File 'lib/openhab/core/provider.rb', line 152 def inspect "#<#{self.class.name}:#{object_id}>" end |