Class: OpenHAB::Core::Provider Abstract

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/openhab/core/provider.rb

Overview

This class is abstract.

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

.registryorg.openhab.core.common.registry.Registry (readonly)

This method is abstract.

The registry that this provider provides elements for.

Raises:

  • (NotImplementedError)


104
105
106
# File 'lib/openhab/core/provider.rb', line 104

def registry
  raise NotImplementedError
end

.typeSymbol (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

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

#inspectString



152
153
154
# File 'lib/openhab/core/provider.rb', line 152

def inspect
  "#<#{self.class.name}:#{object_id}>"
end