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

Expose Syslog::VERSION #5

Merged
merged 1 commit into from Apr 25, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions ext/syslog/syslog.c
Expand Up @@ -12,6 +12,8 @@
#include "ruby/util.h"
#include <syslog.h>

#define SYSLOG_VERSION "0.1.1"

/* Syslog class */
static VALUE mSyslog;
/*
Expand Down Expand Up @@ -574,6 +576,8 @@ void Init_syslog(void)

/* Syslog macros */

rb_define_const(mSyslog, "VERSION", rb_str_new_cstr(SYSLOG_VERSION));

rb_define_method(mSyslogMacros, "LOG_MASK", mSyslogMacros_LOG_MASK, 1);
rb_define_method(mSyslogMacros, "LOG_UPTO", mSyslogMacros_LOG_UPTO, 1);
rb_define_singleton_method(mSyslogMacros, "included", mSyslogMacros_included, 1);
Expand Down
13 changes: 12 additions & 1 deletion syslog.gemspec
@@ -1,6 +1,17 @@

source_version = ["", "ext/syslog/"].find do |dir|
begin
break File.open(File.join(__dir__, "#{dir}syslog.c")) {|f|
f.gets("\n#define SYSLOG_VERSION ")
f.gets[/\s*"(.+)"/, 1]
}
rescue Errno::ENOENT
end
Comment on lines +2 to +9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd rather do it this way:

Suggested change
source_version = ["", "ext/syslog/"].find do |dir|
begin
break File.open(File.join(__dir__, "#{dir}syslog.c")) {|f|
f.gets("\n#define SYSLOG_VERSION ")
f.gets[/\s*"(.+)"/, 1]
}
rescue Errno::ENOENT
end
source_version = %w[. ext/syslog].find do |dir|
break $1 if File.foreach(File.join(__dir__, dir, "syslog.c")).any?(/^#define\s+SYSLOG_VERSION\s+"(.+)"/)
rescue Errno::ENOENT

end

Gem::Specification.new do |spec|
spec.name = "syslog"
spec.version = "0.1.1"
spec.version = source_version
spec.authors = ["Akinori MUSHA"]
spec.email = ["knu@idaemons.org"]

Expand Down