Skip to content

Commit dfa2565

Browse files
committed
Improve hash representation of library properties to support string conversion
1 parent 07fefac commit dfa2565

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2222
- Rubocop expected syntax downgraded from ruby 2.6 to 2.5
2323
- `assertEqual()` and `assertNotEqual()` use actual `==` and `!=` -- they no longer require a type to be totally ordered just to do equality tests
2424
- Evaluative assertions (is true/false/null/etc) now produce simpler error messages instead of masquerading as an operation (e.g. "== true")
25+
- `LibraryProperties.to_h` now properly uses formatters and symbolic keys, in order to support a `.to_s`
2526

2627
### Deprecated
2728

lib/arduino_ci/library_properties.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ def initialize(path)
2424

2525
# @return [Hash] the properties as a hash, all strings
2626
def to_h
27-
@fields.clone
27+
Hash[@fields.map { |k, _| [k.to_sym, send(k)] }]
28+
end
29+
30+
# @return [String] the string representation
31+
def to_s
32+
to_h.to_s
2833
end
2934

3035
# Enable a shortcut syntax for library property accessors, in the style of `attr_accessor` metaprogramming.

spec/library_properties_spec.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@
4646
it "doesn't crash on nonexistent fields" do
4747
expect(library_properties.dot_a_linkage).to be(nil)
4848
end
49+
50+
it "converts to hash" do
51+
h = library_properties.to_h
52+
expect(h[:name].class).to eq(String)
53+
expect(h[:name]).to eq("WebServer")
54+
expect(h[:architectures].class).to eq(Array)
55+
expect(h[:architectures]).to contain_exactly("avr")
56+
end
4957
end
5058

5159
context "Input handling" do
@@ -65,5 +73,4 @@
6573
end
6674
end
6775

68-
6976
end

0 commit comments

Comments
 (0)