tbpgr_utils 0.0.56 → 0.0.57
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +35 -0
- data/lib/eval_helper/require_code.rb +38 -0
- data/lib/eval_helper.rb +1 -0
- data/lib/tbpgr_utils/version.rb +1 -1
- data/spec/eval_helper/require_code_spec.rb +56 -0
- metadata +15 -12
data/README.md
CHANGED
@@ -59,6 +59,7 @@ Or install it yourself as:
|
|
59
59
|
|[EndERB.apply](#enderbapply) |for single template script using __END__ and DATA |
|
60
60
|
|[EvalHelper#if_code](#evalhelperif_code) |create if strings, for eval |
|
61
61
|
|[EvalHelper#if_code_after](#evalhelperif_code_after) |create after-if strings, for eval |
|
62
|
+
|[EvalHelper#require_code](#evalhelperrequire_code) |create require strings, for eval |
|
62
63
|
|[EvalHelper#ternary_operator](#evalhelperternary_operator) |create ternary operator strings, for eval |
|
63
64
|
|[EvalHelper#unless_code](#evalhelperunless_code) |create unless strings, for eval |
|
64
65
|
|[EvalHelper#unless_code_after](#evalhelperunless_code_after) |create after-unless strings, for eval |
|
@@ -1462,6 +1463,39 @@ EvalHelperTest.new.hoge(hash) # => return 'default'
|
|
1462
1463
|
|
1463
1464
|
[back to list](#list)
|
1464
1465
|
|
1466
|
+
### EvalHelper#require_code
|
1467
|
+
single require case
|
1468
|
+
|
1469
|
+
~~~ruby
|
1470
|
+
class EvalHelperRequireTest
|
1471
|
+
include EvalHelper
|
1472
|
+
|
1473
|
+
def hoge(*args)
|
1474
|
+
require_code(args)
|
1475
|
+
end
|
1476
|
+
end
|
1477
|
+
|
1478
|
+
args = 'tbpgr_utils'
|
1479
|
+
EvalHelperRequireTest.new.hoge(args) # => return "require 'tbpgr_utils'\n"
|
1480
|
+
~~~
|
1481
|
+
|
1482
|
+
muiti require case
|
1483
|
+
|
1484
|
+
~~~ruby
|
1485
|
+
class EvalHelperRequireTest
|
1486
|
+
include EvalHelper
|
1487
|
+
|
1488
|
+
def hoge(*args)
|
1489
|
+
require_code(args)
|
1490
|
+
end
|
1491
|
+
end
|
1492
|
+
|
1493
|
+
args = ['tbpgr_utils', 'eval_helper']
|
1494
|
+
EvalHelperRequireTest.new.hoge(args) # => return "require 'tbpgr_utils'\nrequire 'eval_helper'\n"
|
1495
|
+
~~~
|
1496
|
+
|
1497
|
+
[back to list](#list)
|
1498
|
+
|
1465
1499
|
### EvalHelper#ternary_operator
|
1466
1500
|
true case
|
1467
1501
|
|
@@ -2133,6 +2167,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
|
|
2133
2167
|
https://github.com/tbpgr/tbpgr_utils_snippets
|
2134
2168
|
|
2135
2169
|
## History
|
2170
|
+
* version 0.0.57 : add EvalHelper#require_code
|
2136
2171
|
* version 0.0.56 : add EvalHelper#toternary_operator
|
2137
2172
|
* version 0.0.55 : add EvalHelper#unless_code_after
|
2138
2173
|
* version 0.0.54 : add EvalHelper#unless_code
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module EvalHelper
|
4
|
+
# create require strings, for eval
|
5
|
+
#
|
6
|
+
# ==== Examples
|
7
|
+
#
|
8
|
+
# single require case
|
9
|
+
#
|
10
|
+
# class EvalHelperRequireTest
|
11
|
+
# include EvalHelper
|
12
|
+
#
|
13
|
+
# def hoge(*args)
|
14
|
+
# require_code(args)
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# args = 'tbpgr_utils'
|
19
|
+
# EvalHelperRequireTest.new.hoge(args) # => return "require 'tbpgr_utils'\n"
|
20
|
+
#
|
21
|
+
# muiti require case
|
22
|
+
#
|
23
|
+
# class EvalHelperRequireTest
|
24
|
+
# include EvalHelper
|
25
|
+
#
|
26
|
+
# def hoge(*args)
|
27
|
+
# require_code(args)
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# args = ['tbpgr_utils', 'eval_helper']
|
32
|
+
# EvalHelperRequireTest.new.hoge(args) # => return "require 'tbpgr_utils'\nrequire 'eval_helper'\n"
|
33
|
+
#
|
34
|
+
def require_code(*args)
|
35
|
+
args = args.is_a?(Array) ? args.flatten : [args]
|
36
|
+
args.reduce([]) { |ret, v|ret << "require '#{v}'\n" }.join
|
37
|
+
end
|
38
|
+
end
|
data/lib/eval_helper.rb
CHANGED
data/lib/tbpgr_utils/version.rb
CHANGED
@@ -0,0 +1,56 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'eval_helper'
|
4
|
+
|
5
|
+
describe 'EvalHelper' do
|
6
|
+
context :require_code do
|
7
|
+
class EvalHelperRequireTest
|
8
|
+
include EvalHelper
|
9
|
+
|
10
|
+
def hoge(*args)
|
11
|
+
require_code(args)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
cases = [
|
15
|
+
{
|
16
|
+
case_no: 1,
|
17
|
+
case_title: 'single require case',
|
18
|
+
inputs: 'tbpgr_utils',
|
19
|
+
expected: "require 'tbpgr_utils'\n",
|
20
|
+
},
|
21
|
+
{
|
22
|
+
case_no: 2,
|
23
|
+
case_title: 'multi require case',
|
24
|
+
inputs: ['tbpgr_utils', 'eval_helper'],
|
25
|
+
expected: "require 'tbpgr_utils'\nrequire 'eval_helper'\n",
|
26
|
+
},
|
27
|
+
]
|
28
|
+
|
29
|
+
cases.each do |c|
|
30
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
31
|
+
begin
|
32
|
+
case_before c
|
33
|
+
|
34
|
+
# -- given --
|
35
|
+
eval_helper = EvalHelperRequireTest.new
|
36
|
+
|
37
|
+
# -- when --
|
38
|
+
actual = eval_helper.hoge(c[:inputs])
|
39
|
+
|
40
|
+
# -- then --
|
41
|
+
expect(actual).to eq(c[:expected])
|
42
|
+
ensure
|
43
|
+
case_after c
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def case_before(c)
|
48
|
+
# implement each case before
|
49
|
+
end
|
50
|
+
|
51
|
+
def case_after(c)
|
52
|
+
# implement each case after
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
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.57
|
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-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &20860728 !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: *20860728
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &20860440 !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: *20860440
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &20860212 !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: *20860212
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &20859888 !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: *20859888
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: simplecov
|
60
|
-
requirement: &
|
60
|
+
requirement: &20859588 !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: *20859588
|
69
69
|
description: Utilities
|
70
70
|
email:
|
71
71
|
- tbpgr@tbpgr.jp
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- lib/eval_helper.rb
|
89
89
|
- lib/eval_helper/if_code.rb
|
90
90
|
- lib/eval_helper/if_code_after.rb
|
91
|
+
- lib/eval_helper/require_code.rb
|
91
92
|
- lib/eval_helper/ternary_operator.rb
|
92
93
|
- lib/eval_helper/unless_code.rb
|
93
94
|
- lib/eval_helper/unless_code_after.rb
|
@@ -154,6 +155,7 @@ files:
|
|
154
155
|
- spec/attributes_initializable_spec.rb
|
155
156
|
- spec/eval_helper/if_code_after_spec.rb
|
156
157
|
- spec/eval_helper/if_code_spec.rb
|
158
|
+
- spec/eval_helper/require_code_spec.rb
|
157
159
|
- spec/eval_helper/ternary_operator_spec.rb
|
158
160
|
- spec/eval_helper/unless_code_after_spec.rb
|
159
161
|
- spec/eval_helper/unless_code_spec.rb
|
@@ -240,6 +242,7 @@ test_files:
|
|
240
242
|
- spec/attributes_initializable_spec.rb
|
241
243
|
- spec/eval_helper/if_code_after_spec.rb
|
242
244
|
- spec/eval_helper/if_code_spec.rb
|
245
|
+
- spec/eval_helper/require_code_spec.rb
|
243
246
|
- spec/eval_helper/ternary_operator_spec.rb
|
244
247
|
- spec/eval_helper/unless_code_after_spec.rb
|
245
248
|
- spec/eval_helper/unless_code_spec.rb
|