Skip to content

Add .find! methods to system unit modules #187

Merged
merged 3 commits into from Mar 7, 2014

2 participants

@vmoravec
YaST member
vmoravec commented Mar 6, 2014

The reasoning behind this is:
If you can't handle any nil at the place of calling, use the finder with exclamation mark; SystemdSocketNotFound or SystemdServiceNotFound exception will be raised.

 socket = Yast::SystemdSocket.find!('IcanHasCheez')
# => Yast::SystemdSocketNotFound: Socket unit 'IcanHasCheez' not found
@vmoravec vmoravec referenced this pull request in yast/yast-iscsi-client Mar 6, 2014
Merged

add service 'scsci', use systemdSocket #18

@jreidinger jreidinger and 1 other commented on an outdated diff Mar 6, 2014
library/systemd/src/modules/systemd_service.rb
@@ -66,6 +77,12 @@ def find service_name, properties={}
service
end
+ def find! service_name, properties={}
+ service = find(service_name, properties)
+ return service if service
+ raise SystemdServiceNotFound, "Service unit '#{service_name}' not found"
@jreidinger
YaST member
jreidinger added a note Mar 6, 2014

well, you can use also one-liner with || or or

find(service_name, properties) or raise SystemdServiceNotFound, "Service unit '#{service_name}' not found"
@vmoravec
YaST member
vmoravec added a note Mar 6, 2014

Agree, but its 107 characters, you would have to split it into 2 lines to make it fit into a common editor or github window.

@jreidinger
YaST member
jreidinger added a note Mar 6, 2014

ok, just nitpick. In fact I expect that you have own constructor for exception and pass only service_name.
then it will look like

find(service_name, properties) or raise(SystemdServiceNotFound, service_name)
@vmoravec
YaST member
vmoravec added a note Mar 6, 2014

Good point, thanks, I will adapt the exception classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jreidinger
YaST member

just small style nitpick, LGTM

@vmoravec vmoravec merged commit c09dbbf into yast:master Mar 7, 2014
@vmoravec vmoravec deleted the vmoravec:add-exceptions-systemd branch Mar 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.