dslh 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eaa7072cea6f58fcbe9e341e3cfe3e6569ac7754
4
- data.tar.gz: 9c35be524118f1a0a53ddf349688fdf6780cdeb7
3
+ metadata.gz: 7390c52a2f651e8ae19478c3b499fd156bfe9ce8
4
+ data.tar.gz: a417585a38c5a06e1cdfff655c60edbe5f50cb0e
5
5
  SHA512:
6
- metadata.gz: 32898eaf5f6a60ce2eaa6c5e2e87a07e80ac389c6a62b163cd947fc3be03fc8797195c4770c5f93479d909020dbe6db635f10b715cfe725a92405a924fca5e5a
7
- data.tar.gz: 86d4481731ac1549e55bd1d803dffe825258c7dcb590ffcc844f98aa38f27ad8111d4fadd558a2eafd80af0a480e3fdc0af4505123545eeaa8f278434c020de6
6
+ metadata.gz: 9fd88853d1941b413207e4b5616e6a20f38181f805e8a9038cfefcc51f993162318d368440c8941390abec7354f5be41a5414a01eba5075928bb04b17b384ad2
7
+ data.tar.gz: dae0498effdc33b5086711927e6d786433ac94dbe3febab0693f9d0cc8c70d52ad4a2f34ad60daadb38b042fe3a7dbab4666b367a284f0b04b7993ea18fc27bd
@@ -146,7 +146,7 @@ class Dslh
146
146
  if value.any? {|v| [Array, Hash].any? {|c| v.kind_of?(c) }}
147
147
  nested = true
148
148
 
149
- if not @options[:dump_old_hash_array_format] and value.all? {|i| i.kind_of?(Hash) }
149
+ if not @options[:dump_old_hash_array_format] and value.all? {|i| i.kind_of?(Hash) and not exclude_keys?(i.keys) }
150
150
  value_buf.puts(@options[:use_braces_instead_of_do_end] ? ' {|*|' : ' do |*|')
151
151
 
152
152
  value.each_with_index do |v, i|
@@ -172,9 +172,13 @@ class Dslh
172
172
  value.each_with_index do |v, i|
173
173
  case v
174
174
  when Hash
175
- value_buf.puts(next_indent + '_{')
176
- deval0(v, depth + 2, value_buf)
177
- value_buf.print(next_indent + '}')
175
+ if exclude_keys?(v.keys)
176
+ value_buf.print(INDENT_SPACES * (depth + 1) + v.pretty_inspect.strip)
177
+ else
178
+ value_buf.puts(next_indent + '_{')
179
+ deval0(v, depth + 2, value_buf)
180
+ value_buf.print(next_indent + '}')
181
+ end
178
182
  when Array
179
183
  value_buf.print(next_indent.slice(0...-1))
180
184
  value_proc(v, depth + 1, value_buf, false)
@@ -1,3 +1,3 @@
1
1
  class Dslh
2
- VERSION = '0.3.6'
2
+ VERSION = '0.3.7'
3
3
  end
@@ -2680,6 +2680,58 @@ end
2680
2680
  EOS
2681
2681
  end
2682
2682
 
2683
+ it 'should convert hash to dsl (include hash array with exclude_key)' do
2684
+ exclude_key = proc do |k|
2685
+ k == :title
2686
+ end
2687
+
2688
+ h = {:glossary=>[
2689
+ {:title=>"example glossary",
2690
+ :date=>Time.parse('2016/05/21 00:00 UTC').to_s},
2691
+ {:title=>"example glossary2",
2692
+ :date=>Time.parse('2016/05/21 00:01 UTC').to_s}],
2693
+ :glossary2=>[
2694
+ {:title=>"example glossary",
2695
+ :date=>Time.parse('2016/05/21 00:00 UTC').to_s}]}
2696
+
2697
+ dsl = Dslh.deval(h, :exclude_key => exclude_key)
2698
+ expect(dsl).to eq(<<-EOS)
2699
+ glossary [
2700
+ {:title=>"example glossary", :date=>"2016-05-21 00:00:00 UTC"},
2701
+ {:title=>"example glossary2", :date=>"2016-05-21 00:01:00 UTC"}
2702
+ ]
2703
+ glossary2 [
2704
+ {:title=>"example glossary", :date=>"2016-05-21 00:00:00 UTC"}
2705
+ ]
2706
+ EOS
2707
+ end
2708
+
2709
+ it 'should convert hash to dsl (include hash array with exclude_key and dump_old_hash_array_format)' do
2710
+ exclude_key = proc do |k|
2711
+ k == :title
2712
+ end
2713
+
2714
+ h = {:glossary=>[
2715
+ {:title=>"example glossary",
2716
+ :date=>Time.parse('2016/05/21 00:00 UTC').to_s},
2717
+ {:title=>"example glossary2",
2718
+ :date=>Time.parse('2016/05/21 00:01 UTC').to_s}],
2719
+ :glossary2=>[
2720
+ {:title=>"example glossary",
2721
+ :date=>Time.parse('2016/05/21 00:00 UTC').to_s}]}
2722
+
2723
+ dsl = Dslh.deval(h, :exclude_key => exclude_key)
2724
+ expect(dsl).to eq(<<-EOS)
2725
+ glossary [
2726
+ {:title=>"example glossary", :date=>"2016-05-21 00:00:00 UTC"},
2727
+ {:title=>"example glossary2", :date=>"2016-05-21 00:01:00 UTC"}
2728
+ ]
2729
+ glossary2 [
2730
+ {:title=>"example glossary", :date=>"2016-05-21 00:00:00 UTC"}
2731
+ ]
2732
+ EOS
2733
+ end
2734
+
2683
2735
  it 'should convert dsl to hash (include hash array)' do
2684
2736
  h = {:glossary=>[
2685
2737
  {:title=>"example glossary",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dslh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-23 00:00:00.000000000 Z
11
+ date: 2016-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler