dslh 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/dslh.rb +23 -3
- data/lib/dslh/version.rb +1 -1
- data/spec/dslh_spec.rb +31 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f54e329df51e56943cdc60617113f7ef8a8ea225
|
4
|
+
data.tar.gz: 913c752ede8898f9a1b0af78f7e76046fabfa17f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 431c84f8b8fc1c5508e0c98bbe6482d8148c803f35f0de60e257f2d4e4c09dc1ed0124794d46576954e5968134d921a672a4bfb4eebb71b567368ba012cfac6a
|
7
|
+
data.tar.gz: e9cb7c46c181de6934a4fd717fdff6d24986221f7ea18d39d5e6c0df4b7a70307ef4d958795b7a0932fc62aadcf84160264e853becb26dcc2881a8a385d5263f
|
data/README.md
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
It define Hash as a DSL.
|
4
4
|
|
5
|
-
[![Gem Version](https://badge.fury.io/rb/dslh.png?
|
6
|
-
[![Build Status](https://drone.io/github.com/winebarrel/dslh/status.png?
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/dslh.png?201403041920)](http://badge.fury.io/rb/dslh)
|
6
|
+
[![Build Status](https://drone.io/github.com/winebarrel/dslh/status.png?201403041920)](https://drone.io/github.com/winebarrel/dslh/latest)
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
data/lib/dslh.rb
CHANGED
@@ -189,7 +189,7 @@ class Dslh
|
|
189
189
|
def method_missing(method_name, *args, &block)
|
190
190
|
key_conv = @__options__[:key_conv]
|
191
191
|
value_conv = @__options__[:value_conv]
|
192
|
-
nested_hash = ScopeBlock.nest(binding, 'block')
|
192
|
+
nested_hash = ScopeBlock.nest(binding, 'block', method_name)
|
193
193
|
method_name = key_conv.call(method_name) if key_conv
|
194
194
|
|
195
195
|
if args.empty?
|
@@ -212,12 +212,32 @@ class Dslh
|
|
212
212
|
end # of Scope
|
213
213
|
|
214
214
|
class ScopeBlock
|
215
|
-
def self.nest(bind, block_var)
|
215
|
+
def self.nest(bind, block_var, key = nil)
|
216
|
+
block_call = nil
|
217
|
+
|
218
|
+
if key
|
219
|
+
block_call = <<-EOS
|
220
|
+
#{block_var}_ = proc do
|
221
|
+
if #{block_var}.arity.zero?
|
222
|
+
#{block_var}.call
|
223
|
+
else
|
224
|
+
#{block_var}.call(#{key.inspect})
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
self.instance_eval(&#{block_var}_)
|
229
|
+
EOS
|
230
|
+
else
|
231
|
+
block_call = <<-EOS
|
232
|
+
self.instance_eval(&#{block_var})
|
233
|
+
EOS
|
234
|
+
end
|
235
|
+
|
216
236
|
eval(<<-EOS, bind)
|
217
237
|
if #{block_var}
|
218
238
|
__hash_orig = @__hash__
|
219
239
|
@__hash__ = {}
|
220
|
-
|
240
|
+
#{block_call}
|
221
241
|
__nested_hash = @__hash__
|
222
242
|
@__hash__ = __hash_orig
|
223
243
|
__nested_hash
|
data/lib/dslh/version.rb
CHANGED
data/spec/dslh_spec.rb
CHANGED
@@ -55,6 +55,37 @@ describe Dslh do
|
|
55
55
|
)
|
56
56
|
end
|
57
57
|
|
58
|
+
it 'should be nested hash with block args' do
|
59
|
+
h = Dslh.eval do
|
60
|
+
key1 'value'
|
61
|
+
key2 100
|
62
|
+
|
63
|
+
key3 do |a1|
|
64
|
+
key31 "value31" do |a2|
|
65
|
+
key311 100
|
66
|
+
key312 "200 #{a1} #{a2}"
|
67
|
+
end
|
68
|
+
|
69
|
+
key32 do |a3|
|
70
|
+
key321 "value321" do |a4|
|
71
|
+
key3211 "XXX #{a1} #{a3} #{a4}"
|
72
|
+
key3212 :XXX
|
73
|
+
end
|
74
|
+
key322 300
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
expect(h).to eq(
|
80
|
+
{:key1=>"value",
|
81
|
+
:key2=>100,
|
82
|
+
:key3=>
|
83
|
+
{:key31=>{"value31"=>{:key311=>100, :key312=>"200 key3 key31"}},
|
84
|
+
:key32=>
|
85
|
+
{:key321=>{"value321"=>{:key3211=>"XXX key3 key32 key321", :key3212=>:XXX}}, :key322=>300}}}
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
58
89
|
it 'can pass hash argument' do
|
59
90
|
h = Dslh.eval do
|
60
91
|
key1 'value'
|
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.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|