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, update: true) { ... } ⇒ 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, #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, #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 |
# File 'lib/openhab/core/items/registry.rb', line 22 def [](name) EntityLookup.lookup_item(name) end |
#build(preferred_provider = nil, update: true) { ... } ⇒ Object
Enter the Item Builder DSL.
56 57 58 59 |
# File 'lib/openhab/core/items/registry.rb', line 56 def build(preferred_provider = nil, update: true, &block) DSL::Items::BaseBuilderDSL.new(preferred_provider, update: update) .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
29 30 31 |
# File 'lib/openhab/core/items/registry.rb', line 29 def key?(name) !$ir.get(name).nil? 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.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/openhab/core/items/registry.rb', line 71 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
38 39 40 |
# File 'lib/openhab/core/items/registry.rb', line 38 def to_a $ir.items.map { |item| Proxy.new(item) } end |