Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DBus::Object.dbus_reader_attr_accessor to declare a common use case with a single call. #140

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .yardopts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--markup markdown
lib/**/*.rb
-
README.md
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 24 additions & 6 deletions lib/dbus/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion spec/mock-service/spaghetti-monster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading