From 374d3b6163f8f3167174ae7547d0e68b23a93590 Mon Sep 17 00:00:00 2001 From: loadkpi Date: Fri, 27 Apr 2018 18:55:25 +0300 Subject: [PATCH 1/3] Array type converter --- lib/tainbox/type_converter.rb | 5 +++++ spec/tainbox_spec.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/tainbox/type_converter.rb b/lib/tainbox/type_converter.rb index 668e8e4..8592228 100644 --- a/lib/tainbox/type_converter.rb +++ b/lib/tainbox/type_converter.rb @@ -1,3 +1,4 @@ +require 'active_support/core_ext/array/wrap' require 'active_support/values/time_zone' class Tainbox::TypeConverter @@ -72,3 +73,7 @@ def convert !!value end end + +Tainbox.define_converter(Array) do + Array.wrap(value) rescue nil +end \ No newline at end of file diff --git a/spec/tainbox_spec.rb b/spec/tainbox_spec.rb index df45762..0a6f125 100644 --- a/spec/tainbox_spec.rb +++ b/spec/tainbox_spec.rb @@ -166,4 +166,34 @@ def name expect(oliver.name).to eq('John') end end + + describe 'array converter' do + subject { person.phone_numbers } + + let(:person) do + Class.new do + include Tainbox + + attribute :phone_numbers, Array + end.new(phone_numbers: phone_numbers) + end + + context 'without value' do + let(:phone_numbers) { nil } + + it { is_expected.to eq([]) } + end + + context 'with array as a value' do + let(:phone_numbers) { [12345, 67890] } + + it { is_expected.to eq(phone_numbers) } + end + + context 'with string as a value' do + let(:phone_numbers) { '+1 234-500' } + + it { is_expected.to eq([phone_numbers]) } + end + end end From 233afbecac7bfe3f51a19119e1a17e20b1183106 Mon Sep 17 00:00:00 2001 From: loadkpi Date: Mon, 7 May 2018 13:26:23 +0300 Subject: [PATCH 2/3] bump version --- CHANGELOG.md | 4 ++++ lib/tainbox/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee97a27..a4368f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,3 +54,7 @@ semantics ## 2.1.1 * Fix `Time` converter + +## 2.2.0 + +* Add `Array` converter \ No newline at end of file diff --git a/lib/tainbox/version.rb b/lib/tainbox/version.rb index 9150c30..e4a4638 100644 --- a/lib/tainbox/version.rb +++ b/lib/tainbox/version.rb @@ -1,3 +1,3 @@ module Tainbox - VERSION = '2.1.2' + VERSION = '2.2.0' end From 22df42000f3fe99d07a8ca8d217acf57e674b41c Mon Sep 17 00:00:00 2001 From: loadkpi Date: Mon, 7 May 2018 13:29:03 +0300 Subject: [PATCH 3/3] update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f2f508c..727d151 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,7 @@ All converters return nil if conversion could not be made. - Symbol - Time - Boolean +- Array ### String type converter options