dslh 0.1.9 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 041bb7cf886d6a16fb6be02ba6ef356bf31810c7
4
- data.tar.gz: b96cb8ee97322d53745dda628eca4e8fe6ace944
3
+ metadata.gz: bf9e9e4937fa96b3e6896e280e24d44b63622287
4
+ data.tar.gz: ac2fe663b7d7c66d0a7530d6a77f57019586a525
5
5
  SHA512:
6
- metadata.gz: 6753cfa8efa4438bcdfb2193bb827c4268c65bef24f302d2494c759047de84442d3b318dc79871e013214641aca7e19e99e0c102e9256c53eb47fd8dab069d0a
7
- data.tar.gz: 7d43a7ca6c3633460e47e5251dbadcb7336f7f6e342965bda4404737c2426fc9fe17125d718b221de5b33860bd6c36c706670282da265e5dfd46c0fcb93b8e8c
6
+ metadata.gz: a58ffa0d678c4831fd55c47c27a24dea2b8f28e59aa2b5cb0a0653fe7f7ed1c76b26065f418024dc676e59ef8f3d7a6a3e2e07836b4d2a3514a9e8b5ba07422f
7
+ data.tar.gz: 29ab30743682fd4820dc144e5e7b7629dcd2a7bf3586f0b785302b6f8c927933a2b6830cbacb2413fc4f2df78748781d680f438201f38e2f7acd2dbe258b441b
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  It define Hash as a DSL.
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/dslh.png)](http://badge.fury.io/rb/dslh)
6
- [![Build Status](https://drone.io/bitbucket.org/winebarrel/dslh/status.png)](https://drone.io/bitbucket.org/winebarrel/dslh/latest)
6
+ [![Build Status](https://drone.io/github.com/winebarrel/dslh/status.png)](https://drone.io/github.com/winebarrel/dslh/latest)
7
7
 
8
8
  ## Installation
9
9
 
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['sugawara@cookpad.com']
11
11
  spec.summary = %q{It define Hash as a DSL.}
12
12
  spec.description = %q{It define Hash as a DSL.}
13
- spec.homepage = 'https://bitbucket.org/winebarrel/dslh'
13
+ spec.homepage = 'https://github.com/winebarrel/dslh'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -39,6 +39,8 @@ class Dslh
39
39
 
40
40
  def initialize(options = {})
41
41
  @options = options.dup
42
+ @options[:key_conv] ||= @options[:conv]
43
+ @options[:value_conv] ||= @options[:conv]
42
44
  end
43
45
 
44
46
  def eval(expr = nil, &block)
@@ -74,11 +76,11 @@ class Dslh
74
76
  def deval0(hash, depth, buf)
75
77
  indent = (INDENT_SPACES * depth)
76
78
  next_indent = (INDENT_SPACES * (depth + 1))
77
- key_conv = @options[:key_conv] || @options[:conv]
78
- value_conv = @options[:value_conv] || @options[:conv]
79
+ key_conv = @options[:key_conv]
80
+ value_conv = @options[:value_conv]
79
81
  nested = false
80
82
 
81
- if exclude_key?(key_conv, hash.keys)
83
+ if exclude_key?(hash.keys)
82
84
  buf.puts('(' + ("\n" + hash.pretty_inspect.strip).gsub("\n", "\n" + indent) + ')')
83
85
  return
84
86
  end
@@ -87,7 +89,7 @@ class Dslh
87
89
  value_proc = proc do |value_buf|
88
90
  case value
89
91
  when Hash
90
- if exclude_key?(key_conv, value.keys)
92
+ if exclude_key?(value.keys)
91
93
  value_buf.puts('(' + ("\n" + value.pretty_inspect.strip).gsub("\n", "\n" + next_indent) + ')')
92
94
  else
93
95
  nested = true
@@ -155,12 +157,13 @@ class Dslh
155
157
  end
156
158
  end
157
159
 
158
- def exclude_key?(key_conv, keys)
159
- exclude_key = @options[:exclude_key] || proc {|k| k.to_s !~ /\A[_a-z]\w+\Z/i }
160
+ def exclude_key?(keys)
161
+ key_conv = @options[:key_conv]
160
162
 
161
- if not @options.has_key?(:exclude_key) and key_conv
162
- keys = keys.map {|k| key_conv.call(k) }
163
- end
163
+ exclude_key = @options[:exclude_key] || proc {|k|
164
+ k = key_conv.call(k) if key_conv
165
+ k.to_s !~ /\A[_a-z]\w+\Z/i
166
+ }
164
167
 
165
168
  keys.any? {|k| exclude_key.call(k) }
166
169
  end
@@ -171,8 +174,8 @@ class Dslh
171
174
  end
172
175
 
173
176
  def method_missing(method_name, *args, &block)
174
- key_conv = @__options__[:key_conv] || @__options__[:conv]
175
- value_conv = @__options__[:value_conv] || @__options__[:conv]
177
+ key_conv = @__options__[:key_conv]
178
+ value_conv = @__options__[:value_conv]
176
179
  nested_hash = ScopeBlock.nest(binding, 'block')
177
180
  method_name = key_conv.call(method_name) if key_conv
178
181
 
@@ -1,3 +1,3 @@
1
1
  class Dslh
2
- VERSION = '0.1.9'
2
+ VERSION = '0.2.0'
3
3
  end
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.1.9
4
+ version: 0.2.0
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-02-28 00:00:00.000000000 Z
11
+ date: 2014-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,7 +71,7 @@ files:
71
71
  - spec/Drupal_Multi_AZ.template
72
72
  - spec/dslh_spec.rb
73
73
  - spec/spec_helper.rb
74
- homepage: https://bitbucket.org/winebarrel/dslh
74
+ homepage: https://github.com/winebarrel/dslh
75
75
  licenses:
76
76
  - MIT
77
77
  metadata: {}