dslh 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dslh.rb +19 -2
- data/lib/dslh/version.rb +1 -1
- data/spec/dslh_spec.rb +60 -0
- data/spec/spec_helper.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb022da4335f23ff59901ac5652400831dd13c6f
|
4
|
+
data.tar.gz: 1e257ec574e65f1d24409001864aed67be2c8d84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90d4d8d730e57bab79f1e438996f6d0e1de4d7c5a5701b0affb0bb9da9ecc056633426d8c204d48f00ea7029ac2ee725c42673761161a6fc5493f558658aee57
|
7
|
+
data.tar.gz: 78e73bcd8b3686b8dbfc6d8dff8a0e9d56a0f53d77730d991fef01270bde4b0ac5a7ed0a5c432d631e3115b2d8df1fb1f50dac79ff689d3c13a158c8ca08ac4a
|
data/lib/dslh.rb
CHANGED
@@ -38,7 +38,10 @@ class Dslh
|
|
38
38
|
end # of class methods
|
39
39
|
|
40
40
|
def initialize(options = {})
|
41
|
-
@options =
|
41
|
+
@options = {
|
42
|
+
:time_inspecter => method(:inspect_time)
|
43
|
+
}.merge(options)
|
44
|
+
|
42
45
|
@options[:key_conv] ||= (@options[:conv] || proc {|i| i.to_s })
|
43
46
|
@options[:value_conv] ||= @options[:conv]
|
44
47
|
end
|
@@ -176,7 +179,13 @@ class Dslh
|
|
176
179
|
end
|
177
180
|
else
|
178
181
|
value = value_conv.call(value) if value_conv
|
179
|
-
|
182
|
+
|
183
|
+
if @options[:time_inspecter] and value.kind_of?(Time)
|
184
|
+
value = @options[:time_inspecter].call(value)
|
185
|
+
value_buf.puts(' ' + value)
|
186
|
+
else
|
187
|
+
value_buf.puts(' ' + value.inspect)
|
188
|
+
end
|
180
189
|
end
|
181
190
|
|
182
191
|
return nested
|
@@ -193,6 +202,14 @@ class Dslh
|
|
193
202
|
keys.any? {|k| exclude_key.call(k) }
|
194
203
|
end
|
195
204
|
|
205
|
+
def inspect_time(time)
|
206
|
+
if Time.respond_to?(:parse)
|
207
|
+
"Time.parse(#{time.to_s.inspect})"
|
208
|
+
else
|
209
|
+
"Time.at(#{time.tv_sec}, #{time.tv_usec})"
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
196
213
|
class Scope
|
197
214
|
def _(key = nil, &block)
|
198
215
|
nested_hash = ScopeBlock.nest(binding, 'block')
|
data/lib/dslh/version.rb
CHANGED
data/spec/dslh_spec.rb
CHANGED
@@ -2531,6 +2531,18 @@ end
|
|
2531
2531
|
)
|
2532
2532
|
end
|
2533
2533
|
|
2534
|
+
it 'include time"' do
|
2535
|
+
h = Dslh.eval do
|
2536
|
+
key1 'value'
|
2537
|
+
key2 Time.parse('2016/05/21 00:00 UTC')
|
2538
|
+
end
|
2539
|
+
|
2540
|
+
expect(h).to eq(
|
2541
|
+
{"key1"=>"value",
|
2542
|
+
"key2"=>Time.parse('2016/05/21 00:00 UTC')}
|
2543
|
+
)
|
2544
|
+
end
|
2545
|
+
|
2534
2546
|
it 'should convert hash to dsl (symbol key)' do
|
2535
2547
|
h = {:glossary=>
|
2536
2548
|
{:title=>"example glossary",
|
@@ -2570,6 +2582,54 @@ glossary do
|
|
2570
2582
|
end
|
2571
2583
|
end
|
2572
2584
|
end
|
2585
|
+
end
|
2586
|
+
EOS
|
2587
|
+
end
|
2588
|
+
|
2589
|
+
it 'should convert hash to dsl (inclute Time)' do
|
2590
|
+
h = {:glossary=>
|
2591
|
+
{:title=>"example glossary",
|
2592
|
+
:date=>Time.parse('2016/05/21 00:00 UTC')}}
|
2593
|
+
|
2594
|
+
parse_method = Time.method(:parse)
|
2595
|
+
time_cc = (class << Time; self; end)
|
2596
|
+
time_cc.send(:undef_method, :parse)
|
2597
|
+
|
2598
|
+
dsl = Dslh.deval(h)
|
2599
|
+
expect(dsl).to eq(<<-EOS)
|
2600
|
+
glossary do
|
2601
|
+
title "example glossary"
|
2602
|
+
date Time.at(1463788800, 0)
|
2603
|
+
end
|
2604
|
+
EOS
|
2605
|
+
|
2606
|
+
time_cc.send(:define_method, :parse, &parse_method)
|
2607
|
+
end
|
2608
|
+
|
2609
|
+
it 'should convert hash to dsl (inclute Time / use Time#parse)' do
|
2610
|
+
h = {:glossary=>
|
2611
|
+
{:title=>"example glossary",
|
2612
|
+
:date=>Time.parse('2016/05/21 00:00 UTC')}}
|
2613
|
+
|
2614
|
+
dsl = Dslh.deval(h)
|
2615
|
+
expect(dsl).to eq(<<-EOS)
|
2616
|
+
glossary do
|
2617
|
+
title "example glossary"
|
2618
|
+
date Time.parse("2016-05-21 00:00:00 UTC")
|
2619
|
+
end
|
2620
|
+
EOS
|
2621
|
+
end
|
2622
|
+
|
2623
|
+
it 'should convert hash to dsl (inclute Time / pass time_inspecter)' do
|
2624
|
+
h = {:glossary=>
|
2625
|
+
{:title=>"example glossary",
|
2626
|
+
:date=>Time.parse('2016/05/21 00:00 UTC')}}
|
2627
|
+
|
2628
|
+
dsl = Dslh.deval(h, :time_inspecter => proc {|i| i.to_s.inspect })
|
2629
|
+
expect(dsl).to eq(<<-EOS)
|
2630
|
+
glossary do
|
2631
|
+
title "example glossary"
|
2632
|
+
date "2016-05-21 00:00:00 UTC"
|
2573
2633
|
end
|
2574
2634
|
EOS
|
2575
2635
|
end
|
data/spec/spec_helper.rb
CHANGED