diff --git a/.yardopts b/.yardopts index 2678add..63c0c51 100644 --- a/.yardopts +++ b/.yardopts @@ -1,3 +1,4 @@ +--markup markdown lib/**/*.rb - README.md diff --git a/NEWS.md b/NEWS.md index 118180a..1e8def3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,10 @@ ## Unreleased +API: + * Add DBus::Object.dbus_reader_attr_accessor to declare a common use case + with a single call. + ## Ruby D-Bus 0.23.0.beta2 - 2023-06-23 License: diff --git a/lib/dbus/object.rb b/lib/dbus/object.rb index 125d191..2bcb982 100644 --- a/lib/dbus/object.rb +++ b/lib/dbus/object.rb @@ -156,18 +156,32 @@ def self.dbus_attr_accessor(ruby_name, type, dbus_name: nil, emits_changed_signa dbus_accessor(ruby_name, type, dbus_name: dbus_name, emits_changed_signal: emits_changed_signal) end + # A read-only property accessing a read-write instance variable. + # A combination of `attr_accessor` and {.dbus_reader}. + # + # @param (see .dbus_attr_accessor) + # @return (see .dbus_attr_accessor) + def self.dbus_reader_attr_accessor(ruby_name, type, dbus_name: nil, emits_changed_signal: nil) + attr_accessor(ruby_name) + + dbus_reader(ruby_name, type, dbus_name: dbus_name, emits_changed_signal: emits_changed_signal) + end + # A read-only property accessing an instance variable. # A combination of `attr_reader` and {.dbus_reader}. # + # You may be instead looking for a variant which is read-write from the Ruby side: + # {.dbus_reader_attr_accessor}. + # # Whenever the property value gets changed from "inside" the object, # you should emit the `PropertiesChanged` signal by calling # {#dbus_properties_changed}. # - # dbus_properties_changed(interface_name, {dbus_name.to_s => value}, []) + # dbus_properties_changed(interface_name, {dbus_name.to_s => value}, []) # # or, omitting the value in the signal, # - # dbus_properties_changed(interface_name, {}, [dbus_name.to_s]) + # dbus_properties_changed(interface_name, {}, [dbus_name.to_s]) # # @param (see .dbus_attr_accessor) # @return (see .dbus_attr_accessor) @@ -213,18 +227,22 @@ def self.dbus_accessor(ruby_name, type, dbus_name: nil, emits_changed_signal: ni # implement it with a read-write attr_accessor. In that case this method # uses {.dbus_watcher} to set up the PropertiesChanged signal. # - # attr_accessor :foo_bar - # dbus_reader :foo_bar, "s" + # attr_accessor :foo_bar + # dbus_reader :foo_bar, "s" + # + # The above two declarations have a shorthand: + # + # dbus_reader_attr_accessor :foo_bar, "s" # # If the property value should change by other means than its attr_writer, # you should emit the `PropertiesChanged` signal by calling # {#dbus_properties_changed}. # - # dbus_properties_changed(interface_name, {dbus_name.to_s => value}, []) + # dbus_properties_changed(interface_name, {dbus_name.to_s => value}, []) # # or, omitting the value in the signal, # - # dbus_properties_changed(interface_name, {}, [dbus_name.to_s]) + # dbus_properties_changed(interface_name, {}, [dbus_name.to_s]) # # @param (see .dbus_attr_accessor) # @return (see .dbus_attr_accessor) diff --git a/spec/mock-service/spaghetti-monster.rb b/spec/mock-service/spaghetti-monster.rb index 1ccbd90..55f4326 100755 --- a/spec/mock-service/spaghetti-monster.rb +++ b/spec/mock-service/spaghetti-monster.rb @@ -23,7 +23,7 @@ def initialize(opath) end dbus_interface "org.ruby.TestChild" do - dbus_attr_reader :name, "s" + dbus_reader_attr_accessor :name, "s" end end