tbpgr_utils 0.0.63 → 0.0.64
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +22 -0
- data/lib/eval_helper/each_do_code.rb +26 -0
- data/lib/eval_helper.rb +1 -0
- data/lib/tbpgr_utils/version.rb +1 -1
- data/spec/eval_helper/each_do_code_spec.rb +51 -0
- metadata +15 -12
data/README.md
CHANGED
@@ -58,6 +58,7 @@ Or install it yourself as:
|
|
58
58
|
|[AttributesInitializable::ClassMethods.attr_writer init](#attributesinitializableclassmethodsattr_writer_init) |generate attr_writer + initializer |
|
59
59
|
|[EndERB.apply](#enderbapply) |for single template script using __END__ and DATA |
|
60
60
|
|[EvalHelper Object](#evalhelper-object) |enable to use EvalHelper in Object |
|
61
|
+
|[EvalHelper#each_do_code](#evalhelpereach_do_code) |create each do code, for eval |
|
61
62
|
|[EvalHelper#each_brace_code](#evalhelpereach_brace_code) |create each brace single line code, for eval |
|
62
63
|
|[EvalHelper#if_code](#evalhelperif_code) |create if strings, for eval |
|
63
64
|
|[EvalHelper#if_code_after](#evalhelperif_code_after) |create after-if strings, for eval |
|
@@ -1380,6 +1381,26 @@ require_code("hoge") # => 'require "hoge"'
|
|
1380
1381
|
|
1381
1382
|
[back to list](#list)
|
1382
1383
|
|
1384
|
+
### EvalHelper#each_do_code
|
1385
|
+
~~~ruby
|
1386
|
+
require 'eval_helper'
|
1387
|
+
class EvalHelperEacjBraceTest
|
1388
|
+
include EvalHelper
|
1389
|
+
|
1390
|
+
def hoge(hash)
|
1391
|
+
each_do_code(hash[:target], hash[:proc])
|
1392
|
+
end
|
1393
|
+
end
|
1394
|
+
|
1395
|
+
hash = {
|
1396
|
+
target: '[:a, :b]',
|
1397
|
+
proc: "puts \"\#{v}1\"\nputs \"\#{v}2\"\n",
|
1398
|
+
}
|
1399
|
+
EvalHelperEacjBraceTest.new.hoge(hash) # => return "[:a, :b].each do |v|\n puts \"\#{v}1\"\n puts \"\#{v}2\"\nend"
|
1400
|
+
~~~
|
1401
|
+
|
1402
|
+
[back to list](#list)
|
1403
|
+
|
1383
1404
|
### EvalHelper#each_brace_code
|
1384
1405
|
~~~ruby
|
1385
1406
|
require 'eval_helper'
|
@@ -2413,6 +2434,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
|
|
2413
2434
|
https://github.com/tbpgr/tbpgr_utils_snippets
|
2414
2435
|
|
2415
2436
|
## History
|
2437
|
+
* version 0.0.64 : add EvalHelper#each_do_code
|
2416
2438
|
* version 0.0.63 : add EvalHelper#each_brace_code, String#hyphen_to_a, String#commma_to_a
|
2417
2439
|
* version 0.0.62 : add EvalHelper#set_variables_code
|
2418
2440
|
* version 0.0.61 : add EvalHelper#set_variable_code
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module EvalHelper
|
4
|
+
# create each do code, for eval
|
5
|
+
#
|
6
|
+
# ==== Examples
|
7
|
+
#
|
8
|
+
# class EvalHelperEacjBraceTest
|
9
|
+
# include EvalHelper
|
10
|
+
#
|
11
|
+
# def hoge(hash)
|
12
|
+
# each_do_code(hash[:target], hash[:proc])
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# hash = {
|
17
|
+
# target: '[:a, :b]',
|
18
|
+
# proc: "puts \"\#{v}1\"\nputs \"\#{v}2\"\n",
|
19
|
+
# }
|
20
|
+
# EvalHelperEacjBraceTest.new.hoge(hash) # => return "[:a, :b].each do |v|\n puts \"\#{v}1\"\n puts \"\#{v}2\"\nend"
|
21
|
+
#
|
22
|
+
def each_do_code(target, proc)
|
23
|
+
indented = proc.split("\n").reduce([]) { |ret, v|ret << " #{v}" ; ret }.join("\n")
|
24
|
+
"#{target}.each do |v|\n#{indented}\nend"
|
25
|
+
end
|
26
|
+
end
|
data/lib/eval_helper.rb
CHANGED
data/lib/tbpgr_utils/version.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'eval_helper'
|
4
|
+
|
5
|
+
describe 'EvalHelper' do
|
6
|
+
context :each_do_code do
|
7
|
+
class EvalHelperEachDoTest
|
8
|
+
include EvalHelper
|
9
|
+
|
10
|
+
def hoge(hash)
|
11
|
+
each_do_code(hash[:target], hash[:proc])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
cases = [
|
15
|
+
{
|
16
|
+
case_no: 1,
|
17
|
+
case_title: 'unless case',
|
18
|
+
target: '[:a, :b]',
|
19
|
+
proc: "puts \"\#{v}1\"\nputs \"\#{v}2\"\n",
|
20
|
+
expected: "[:a, :b].each do |v|\n puts \"\#{v}1\"\n puts \"\#{v}2\"\nend",
|
21
|
+
}
|
22
|
+
]
|
23
|
+
|
24
|
+
cases.each do |c|
|
25
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
26
|
+
begin
|
27
|
+
case_before c
|
28
|
+
|
29
|
+
# -- given --
|
30
|
+
eval_helper = EvalHelperEachDoTest.new
|
31
|
+
|
32
|
+
# -- when --
|
33
|
+
actual = eval_helper.hoge(c)
|
34
|
+
|
35
|
+
# -- then --
|
36
|
+
expect(actual).to eq(c[:expected])
|
37
|
+
ensure
|
38
|
+
case_after c
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def case_before(c)
|
43
|
+
# implement each case before
|
44
|
+
end
|
45
|
+
|
46
|
+
def case_after(c)
|
47
|
+
# implement each case after
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tbpgr_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.64
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &26135568 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 4.0.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *26135568
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &26135280 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '1.3'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *26135280
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &26135052 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *26135052
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &26134728 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 2.14.1
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *26134728
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: simplecov
|
60
|
-
requirement: &
|
60
|
+
requirement: &26134428 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: 0.8.2
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *26134428
|
69
69
|
description: Utilities
|
70
70
|
email:
|
71
71
|
- tbpgr@tbpgr.jp
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- lib/end_erb.rb
|
88
88
|
- lib/eval_helper.rb
|
89
89
|
- lib/eval_helper/each_brace_code.rb
|
90
|
+
- lib/eval_helper/each_do_code.rb
|
90
91
|
- lib/eval_helper/if_code.rb
|
91
92
|
- lib/eval_helper/if_code_after.rb
|
92
93
|
- lib/eval_helper/require_code.rb
|
@@ -162,6 +163,7 @@ files:
|
|
162
163
|
- spec/attributes_hashable_spec.rb
|
163
164
|
- spec/attributes_initializable_spec.rb
|
164
165
|
- spec/eval_helper/each_brace_code_spec.rb
|
166
|
+
- spec/eval_helper/each_do_code_spec.rb
|
165
167
|
- spec/eval_helper/if_code_after_spec.rb
|
166
168
|
- spec/eval_helper/if_code_spec.rb
|
167
169
|
- spec/eval_helper/require_code_spec.rb
|
@@ -256,6 +258,7 @@ test_files:
|
|
256
258
|
- spec/attributes_hashable_spec.rb
|
257
259
|
- spec/attributes_initializable_spec.rb
|
258
260
|
- spec/eval_helper/each_brace_code_spec.rb
|
261
|
+
- spec/eval_helper/each_do_code_spec.rb
|
259
262
|
- spec/eval_helper/if_code_after_spec.rb
|
260
263
|
- spec/eval_helper/if_code_spec.rb
|
261
264
|
- spec/eval_helper/require_code_spec.rb
|