Class: OpenHAB::Core::Sitemaps::Registry
- Inherits:
-
Object
- Object
- OpenHAB::Core::Sitemaps::Registry
- Includes:
- LazyArray
- Defined in:
- lib/openhab/core/sitemaps/registry.rb
Overview
Provides access to all openHAB sitemap definitions, and acts like an array.
Instance Method Summary collapse
-
#[](name) ⇒ Sitemap?
(also: #include?, #key?, #has_key?)
Gets a specific sitemap definition.
-
#build(update: true) { ... } ⇒ void
Enter the Sitemap Builder DSL.
-
#remove(sitemap) ⇒ Sitemap
Remove a sitemap.
-
#to_a ⇒ Array<Sitemap>
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) ⇒ Sitemap? Also known as: include?, key?, has_key?
Gets a specific sitemap definition.
23 24 25 26 |
# File 'lib/openhab/core/sitemaps/registry.rb', line 23 def [](name) # @deprecated OH 5.2: Remove the registry check when dropping OH 5.1 Provider.registry ? Provider.registry.get(name) : Provider.current.get(name) end |
#build(update: true) { ... } ⇒ void
This method returns an undefined value.
Enter the Sitemap Builder DSL.
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/openhab/core/sitemaps/registry.rb', line 117 def build(update: true, &block) builder_proxy = SimpleDelegator.new(nil) if block.arity == 1 builder = DSL::Sitemaps::Builder.new(builder_proxy, update:) if block.arity == 1 builder_proxy.__setobj__(builder) DSL::ThreadLocal.thread_local(openhab_create_dummy_items: true) do yield builder_proxy end else builder.instance_eval(&block) end end |
#remove(sitemap) ⇒ Sitemap
Remove a sitemap.
The sitemap must be managed by Ruby.
139 140 141 142 143 144 145 146 147 |
# File 'lib/openhab/core/sitemaps/registry.rb', line 139 def remove(sitemap) sitemap = sitemap.uid if sitemap.respond_to?(:uid) old_instance = Provider.current.remove(sitemap) old_instance ||= Provider.registry&.remove(sitemap) raise "Cannot remove sitemap #{sitemap}" unless old_instance old_instance end |