Skip to content

Commit 43729c1

Browse files
committed
Support erb in config file
1 parent 4a8f395 commit 43729c1

File tree

7 files changed

+11
-9
lines changed

7 files changed

+11
-9
lines changed

CONFIG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ enum:
4545
```
4646
4747
## Full configuration file
48-
[config/default.yml](config/default.yml) is used by https://github.com/ruby-go-gem/go-gem-wrapper to generate bindings for Go.
48+
[config/default.yml.erb](config/default.yml.erb) is used by https://github.com/ruby-go-gem/go-gem-wrapper to generate bindings for Go.
4949
5050
## `function.include_name`, `struct.include_name`, `type.include_name`, `enum.include_name`
5151
Return functions and structures that match the condition with a [RubyHeaderParser::Parser](lib/ruby_header_parser/parser.rb)
File renamed without changes.

lib/ruby_header_parser.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require "yaml"
44
require "tmpdir"
5+
require "erb"
56

67
require_relative "ruby_header_parser/version"
78

lib/ruby_header_parser/config.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class Config
1111
#
1212
# @note See [CONFIG.md](../file.CONFIG.html) for config file details
1313
def initialize(config_file)
14-
yaml = File.read(config_file)
14+
erb = File.read(config_file)
15+
yaml = ERB.new(erb).result
1516
@data = YAML.safe_load(yaml, aliases: true, permitted_classes: [Regexp])
1617
end
1718

lib/ruby_header_parser/parser.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Parser # rubocop:disable Metrics/ClassLength
3030
# @param include_paths [Array<String>]
3131
# @param dist_preprocessed_header_file [String,nil] Destination path to the output of preprocessed ruby.h.
3232
# (default: `"#{Dir.tmpdir}/ruby_preprocessed.h"`)
33-
# @param config_file [String,nil] Path to config file (default: `config/default.yml`)
33+
# @param config_file [String,nil] Path to config file (default: `config/default.yml.erb`)
3434
#
3535
# @note `dist_preprocessed_header_file` is used as the output destination for temporary files when the parser
3636
# is executed
@@ -42,7 +42,7 @@ def initialize(dist_preprocessed_header_file: nil, header_file: DEFAULT_HEADER_F
4242
@include_paths = include_paths
4343
@dist_preprocessed_header_file = dist_preprocessed_header_file || File.join(Dir.tmpdir, "ruby_preprocessed.h")
4444

45-
config_file ||= File.expand_path("../../config/default.yml", __dir__.to_s)
45+
config_file ||= File.expand_path("../../config/default.yml.erb", __dir__.to_s)
4646
@config = Config.new(config_file)
4747
end
4848

spec/ruby_header_parser/config_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
describe "#function_arg_pointer_hint" do
77
subject { config.function_arg_pointer_hint(function_name:, pos:) }
88

9-
context "found in config/default.yml" do
9+
context "found in config/default.yml.erb" do
1010
let(:function_name) { "rb_funcallv" }
1111
let(:pos) { 4 }
1212

1313
it { should eq :array }
1414
end
1515

16-
context "not found in config/default.yml" do
16+
context "not found in config/default.yml.erb" do
1717
let(:function_name) { "rb_funcallv" }
1818
let(:pos) { 5 }
1919

@@ -24,13 +24,13 @@
2424
describe "#function_self_pointer_hint" do
2525
subject { config.function_self_pointer_hint(function_name) }
2626

27-
context "found in default.yml" do
27+
context "found in default.yml.erb" do
2828
let(:function_name) { "RSTRING_PTR" }
2929

3030
it { should eq :raw }
3131
end
3232

33-
context "not found in config/default.yml" do
33+
context "not found in config/default.yml.erb" do
3434
let(:function_name) { "rb_class2name" }
3535

3636
it { should eq :ref }

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929

3030
# @return [String]
3131
def default_config_file
32-
File.expand_path("../config/default.yml", __dir__)
32+
File.expand_path("../config/default.yml.erb", __dir__)
3333
end

0 commit comments

Comments
 (0)