Class: OpenHAB::Core::Items::Registry
- Inherits:
-
Object
- Object
- OpenHAB::Core::Items::Registry
- Includes:
- LazyArray
- Defined in:
- lib/openhab/core/items/registry.rb
Overview
Provides access to all openHAB items, and acts like an array.
Instance Method Summary collapse
-
#[](name) ⇒ Item
Fetches the named item from the the ItemRegistry.
-
#build(preferred_provider = nil) { ... } ⇒ Object
Enter the Item Builder DSL.
-
#key?(name) ⇒ true, false
(also: #include?, #has_key?)
Returns true if the given item name exists.
-
#remove(item_name, recursive: false) ⇒ Item?
Remove an item.
-
#to_a ⇒ Array
Explicit conversion to array.
Methods included from LazyArray
#each, #method_missing, #to_ary
Methods included from Enumerable
#all_groups, #all_members, #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, #up, #update
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class OpenHAB::Core::LazyArray
Instance Method Details
#[](name) ⇒ Item
Fetches the named item from the the ItemRegistry
22 23 24 25 26 |
# File 'lib/openhab/core/items/registry.rb', line 22 def [](name) EntityLookup.lookup_item(name) rescue org.openhab.core.items.ItemNotFoundException nil end |
#build(preferred_provider = nil) { ... } ⇒ Object
Enter the Item Builder DSL.
(see Items::Builder)
53 54 55 |
# File 'lib/openhab/core/items/registry.rb', line 53 def build(preferred_provider = nil, &block) DSL::Items::BaseBuilderDSL.new(preferred_provider).instance_eval_with_dummy_items(&block) end |
#key?(name) ⇒ true, false Also known as: include?, has_key?
Returns true if the given item name exists
31 32 33 |
# File 'lib/openhab/core/items/registry.rb', line 31 def key?(name) !$ir.getItems(name).empty? end |
#remove(item_name, recursive: false) ⇒ Item?
Remove an item.
The item must be a managed item (typically created by Ruby or in the UI).
Any associated metadata or channel links are also removed.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/openhab/core/items/registry.rb', line 67 def remove(item_name, recursive: false) item_name = item_name.name if item_name.is_a?(Item) provider = Provider.registry.provider_for(item_name) unless provider.is_a?(ManagedProvider) raise "Cannot remove item #{item_name} from non-managed provider #{provider.inspect}" end Metadata::Provider.registry.providers.grep(ManagedProvider).each do |managed_provider| managed_provider.remove_item_metadata(item_name) end Things::Links::Provider.registry.providers.grep(ManagedProvider).each do |managed_provider| managed_provider.remove_links_for_item(item_name) end provider.remove(item_name, recursive) end |
#to_a ⇒ Array
Explicit conversion to array
40 41 42 |
# File 'lib/openhab/core/items/registry.rb', line 40 def to_a $ir.items.map { |item| Proxy.new(item) } end |