tbpgr_utils 0.0.61 → 0.0.62
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +29 -0
- data/lib/eval_helper/set_variables_code.rb +45 -0
- data/lib/eval_helper.rb +1 -0
- data/lib/tbpgr_utils/version.rb +1 -1
- data/spec/set_variables_code_spec.rb +99 -0
- metadata +15 -12
data/README.md
CHANGED
@@ -62,6 +62,8 @@ Or install it yourself as:
|
|
62
62
|
|[EvalHelper#if_code_after](#evalhelperif_code_after) |create after-if strings, for eval |
|
63
63
|
|[EvalHelper#require_code](#evalhelperrequire_code) |create require strings, for eval |
|
64
64
|
|[EvalHelper#require_relative_code](#evalhelperrequire_relative_code) |create require_relative strings, for eval |
|
65
|
+
|[EvalHelper#set_variable_code](#evalhelperset_variable_code) |create set_variable_code strings, for eval |
|
66
|
+
|[EvalHelper#set_variables_code](#evalhelperset_variables_code) |create set_variables_code strings, for eval |
|
65
67
|
|[EvalHelper#times_code](#evalhelpertimes_code) |create times_code strings, for eval |
|
66
68
|
|[EvalHelper#ternary_operator](#evalhelperternary_operator) |create ternary operator strings, for eval |
|
67
69
|
|[EvalHelper#unless_code](#evalhelperunless_code) |create unless strings, for eval |
|
@@ -1593,6 +1595,32 @@ hoge_num = 1
|
|
1593
1595
|
|
1594
1596
|
[back to list](#list)
|
1595
1597
|
|
1598
|
+
### EvalHelper#set_variables_code
|
1599
|
+
~~~ruby
|
1600
|
+
require 'eval_helper'
|
1601
|
+
class EvalHelperSetVariablesTest
|
1602
|
+
include EvalHelper
|
1603
|
+
|
1604
|
+
def hoge(variables)
|
1605
|
+
set_variables_code(variables)
|
1606
|
+
end
|
1607
|
+
end
|
1608
|
+
|
1609
|
+
variables = [
|
1610
|
+
{
|
1611
|
+
name: 'name1',
|
1612
|
+
value: '"value1"',
|
1613
|
+
},
|
1614
|
+
{
|
1615
|
+
name: 'name2',
|
1616
|
+
value: '"value2"',
|
1617
|
+
},
|
1618
|
+
]
|
1619
|
+
EvalHelperSetVariablesTest.new.hoge(variables)
|
1620
|
+
~~~
|
1621
|
+
|
1622
|
+
[back to list](#list)
|
1623
|
+
|
1596
1624
|
### EvalHelper#times_code
|
1597
1625
|
|
1598
1626
|
single_line_proc case
|
@@ -2320,6 +2348,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
|
|
2320
2348
|
https://github.com/tbpgr/tbpgr_utils_snippets
|
2321
2349
|
|
2322
2350
|
## History
|
2351
|
+
* version 0.0.62 : add EvalHelper#set_variables_code
|
2323
2352
|
* version 0.0.61 : add EvalHelper#set_variable_code
|
2324
2353
|
* version 0.0.60 : add EvalHelper#times_code
|
2325
2354
|
* version 0.0.59 : add EvalHelper Object
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module EvalHelper
|
4
|
+
# create set variables logic strings, for eval
|
5
|
+
#
|
6
|
+
# ==== Examples
|
7
|
+
#
|
8
|
+
# set string variables case
|
9
|
+
#
|
10
|
+
# class EvalHelperSetVariablesTest
|
11
|
+
# include EvalHelper
|
12
|
+
#
|
13
|
+
# def hoge(variables)
|
14
|
+
# set_variables_code(variables)
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# variables = [
|
19
|
+
# {
|
20
|
+
# name: 'name1',
|
21
|
+
# value: '"value1"',
|
22
|
+
# },
|
23
|
+
# {
|
24
|
+
# name: 'name2',
|
25
|
+
# value: '"value2"',
|
26
|
+
# },
|
27
|
+
# ]
|
28
|
+
# EvalHelperSetVariablesTest.new.hoge(variables)
|
29
|
+
#
|
30
|
+
# return
|
31
|
+
#
|
32
|
+
# name1 = "value1"
|
33
|
+
# name2 = "value2"
|
34
|
+
#
|
35
|
+
def set_variables_code(variables)
|
36
|
+
fail TypeError, "invalid type #{variables.class}. you have to use Array" unless variables.is_a? Array
|
37
|
+
variables.reduce([]) do |ret, variable|
|
38
|
+
fail TypeError, "invalid type #{variable.class}. you have to use Hash" unless variable.is_a? Hash
|
39
|
+
fail TypeError, 'invalid hash. you have to set Hash[:name]' if variable[:name].nil?
|
40
|
+
fail TypeError, 'invalid hash. you have to set Hash[:value]' if variable[:value].nil?
|
41
|
+
ret << "#{variable[:name]} = #{variable[:value]}"
|
42
|
+
ret
|
43
|
+
end.join("\n")
|
44
|
+
end
|
45
|
+
end
|
data/lib/eval_helper.rb
CHANGED
@@ -6,6 +6,7 @@ module EvalHelper
|
|
6
6
|
require 'eval_helper/require_code'
|
7
7
|
require 'eval_helper/require_relative_code'
|
8
8
|
require 'eval_helper/set_variable_code'
|
9
|
+
require 'eval_helper/set_variables_code'
|
9
10
|
require 'eval_helper/ternary_operator'
|
10
11
|
require 'eval_helper/times_code'
|
11
12
|
require 'eval_helper/unless_code'
|
data/lib/tbpgr_utils/version.rb
CHANGED
@@ -0,0 +1,99 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'eval_helper'
|
4
|
+
|
5
|
+
describe 'EvalHelper' do
|
6
|
+
context :set_variables_code do
|
7
|
+
class EvalHelperSetVariablesTest
|
8
|
+
include EvalHelper
|
9
|
+
|
10
|
+
def hoge(variables)
|
11
|
+
set_variables_code(variables)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
cases = [
|
15
|
+
{
|
16
|
+
case_no: 1,
|
17
|
+
case_title: 'set multi variables case',
|
18
|
+
variables: [
|
19
|
+
{
|
20
|
+
name: 'name1',
|
21
|
+
value: '"value1"',
|
22
|
+
},
|
23
|
+
{
|
24
|
+
name: 'name2',
|
25
|
+
value: '"value2"',
|
26
|
+
},
|
27
|
+
],
|
28
|
+
expected: %!name1 = "value1"\nname2 = "value2"!
|
29
|
+
},
|
30
|
+
{
|
31
|
+
case_no: 2,
|
32
|
+
case_title: 'not hash case',
|
33
|
+
variables: 'hoge',
|
34
|
+
expect_error: true,
|
35
|
+
},
|
36
|
+
{
|
37
|
+
case_no: 3,
|
38
|
+
case_title: 'not hash[:name] case',
|
39
|
+
variables: [
|
40
|
+
{
|
41
|
+
not_name: 'name1',
|
42
|
+
value: '"value1"',
|
43
|
+
},
|
44
|
+
{
|
45
|
+
not_name: 'name2',
|
46
|
+
value: '"value3"',
|
47
|
+
},
|
48
|
+
],
|
49
|
+
expect_error: true,
|
50
|
+
},
|
51
|
+
{
|
52
|
+
case_no: 4,
|
53
|
+
case_title: 'not hash[:value] case',
|
54
|
+
variables: [
|
55
|
+
{
|
56
|
+
name: 'name1',
|
57
|
+
not_value: '"value1"',
|
58
|
+
},
|
59
|
+
{
|
60
|
+
name: 'name2',
|
61
|
+
not_value: '"value3"',
|
62
|
+
},
|
63
|
+
],
|
64
|
+
expect_error: true,
|
65
|
+
},
|
66
|
+
]
|
67
|
+
|
68
|
+
cases.each do |c|
|
69
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
70
|
+
begin
|
71
|
+
case_before c
|
72
|
+
|
73
|
+
# -- given --
|
74
|
+
# nothing
|
75
|
+
|
76
|
+
# -- when --
|
77
|
+
if c[:expect_error]
|
78
|
+
lambda { EvalHelperSetVariablesTest.new.hoge c[:variables] }.should raise_error(StandardError)
|
79
|
+
next
|
80
|
+
end
|
81
|
+
actual = EvalHelperSetVariablesTest.new.hoge c[:variables]
|
82
|
+
|
83
|
+
# -- then --
|
84
|
+
expect(actual).to eq(c[:expected])
|
85
|
+
ensure
|
86
|
+
case_after c
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def case_before(c)
|
91
|
+
# implement each case before
|
92
|
+
end
|
93
|
+
|
94
|
+
def case_after(c)
|
95
|
+
# implement each case after
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
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.62
|
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-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &26240724 !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: *26240724
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &26240196 !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: *26240196
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &26239788 !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: *26239788
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &26239392 !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: *26239392
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: simplecov
|
60
|
-
requirement: &
|
60
|
+
requirement: &26238984 !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: *26238984
|
69
69
|
description: Utilities
|
70
70
|
email:
|
71
71
|
- tbpgr@tbpgr.jp
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- lib/eval_helper/require_code.rb
|
92
92
|
- lib/eval_helper/require_relative_code.rb
|
93
93
|
- lib/eval_helper/set_variable_code.rb
|
94
|
+
- lib/eval_helper/set_variables_code.rb
|
94
95
|
- lib/eval_helper/ternary_operator.rb
|
95
96
|
- lib/eval_helper/times_code.rb
|
96
97
|
- lib/eval_helper/unless_code.rb
|
@@ -214,6 +215,7 @@ files:
|
|
214
215
|
- spec/open_classes/string/to_space2_heading_spec.rb
|
215
216
|
- spec/open_classes/string/to_space4_heading_spec.rb
|
216
217
|
- spec/open_classes/string/to_tab_heading_spec.rb
|
218
|
+
- spec/set_variables_code_spec.rb
|
217
219
|
- spec/spec_helper.rb
|
218
220
|
- spec/templatable_spec.rb
|
219
221
|
- spec/template_methodable_spec.rb
|
@@ -304,6 +306,7 @@ test_files:
|
|
304
306
|
- spec/open_classes/string/to_space2_heading_spec.rb
|
305
307
|
- spec/open_classes/string/to_space4_heading_spec.rb
|
306
308
|
- spec/open_classes/string/to_tab_heading_spec.rb
|
309
|
+
- spec/set_variables_code_spec.rb
|
307
310
|
- spec/spec_helper.rb
|
308
311
|
- spec/templatable_spec.rb
|
309
312
|
- spec/template_methodable_spec.rb
|