pattern 0.9.5 → 0.9.7
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.
- data/README.md +135 -0
- data/bin/pattern +34 -18
- data/lib/code.rb +3 -0
- data/lib/common.rb +4 -0
- data/lib/configuration.rb +2 -2
- data/lib/patternrobot.rb +7 -0
- data/lib/version.rb +18 -18
- metadata +18 -28
- data/README +0 -43
- data/Rakefile +0 -8
- data/test/code_spec.rb +0 -35
- data/test/command_spec.rb +0 -19
- data/test/compositecode_spec.rb +0 -130
- data/test/configuration_spec.rb +0 -28
- data/test/patterncode_spec.rb +0 -35
data/README.md
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
# EasyPattern
|
2
|
+
=====
|
3
|
+
|
4
|
+
Rubygem for building Pattern/Data Structure .
|
5
|
+
Supports custom templates by any language.
|
6
|
+
Good tools for learning Pattern/Data Structure.
|
7
|
+
|
8
|
+
## Useage
|
9
|
+
======
|
10
|
+
|
11
|
+
```
|
12
|
+
gem install pattern
|
13
|
+
```
|
14
|
+
|
15
|
+
simple model
|
16
|
+
|
17
|
+
```
|
18
|
+
pattern [tempate_dir] [main_class_name] [-d target_dir]
|
19
|
+
|
20
|
+
pattern [-t tempate_dir] [-d target_dir("." is default)]
|
21
|
+
[-c classes_name] [-op operations_name]
|
22
|
+
|
23
|
+
```
|
24
|
+
|
25
|
+
complex model (not support now.)
|
26
|
+
|
27
|
+
```
|
28
|
+
pattern -f pattern_file
|
29
|
+
|
30
|
+
```
|
31
|
+
## example:
|
32
|
+
======
|
33
|
+
|
34
|
+
simple model:
|
35
|
+
|
36
|
+
```
|
37
|
+
pattern ruby.composite Task -d target
|
38
|
+
pattern -t ruby.composite -d target -c Task;CompositeTask;AddDryIngredientsTask,MixTask,AddLiquidsTask;MakeBatterTask,MakeCakeTask -op get_time_required
|
39
|
+
|
40
|
+
```
|
41
|
+
|
42
|
+
|
43
|
+
complex model(pattern_file):
|
44
|
+
|
45
|
+
### Create you Own Pattern
|
46
|
+
|
47
|
+
Eg. composite
|
48
|
+
|
49
|
+
1. Create a directry as template_dir
|
50
|
+
2. Create dir ruby.composite
|
51
|
+
3. tree like this:
|
52
|
+
|
53
|
+
```
|
54
|
+
├── ruby.composite
|
55
|
+
│ ├── component.rb
|
56
|
+
│ ├── composite.rb
|
57
|
+
│ ├── compositeobject.rb
|
58
|
+
│ ├── leaf.rb
|
59
|
+
│ ├── operations
|
60
|
+
│ └── readme
|
61
|
+
```
|
62
|
+
4. readme
|
63
|
+
|
64
|
+
```
|
65
|
+
template "component.rb","class_name"
|
66
|
+
template "composite.rb","composite_name"
|
67
|
+
template "leaf.rb","leaf_name"
|
68
|
+
template "compositeobject.rb","composite_object_name"
|
69
|
+
default @base_name,"Composite#{@base_name}","Leaf#{@base_name}","CompositeObject#{@base_name}"
|
70
|
+
```
|
71
|
+
template [template_name],[target_file_name_1]
|
72
|
+
|
73
|
+
template [template_name],[target_file_name_2]
|
74
|
+
|
75
|
+
default [target_file_name_1],[target_file_name_2]
|
76
|
+
|
77
|
+
5. operations
|
78
|
+
|
79
|
+
```
|
80
|
+
def #operation#
|
81
|
+
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
85
|
+
6. component.rb
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
# This is code of composite pattern . Generated by pattern.
|
92
|
+
#
|
93
|
+
|
94
|
+
class #class_name#
|
95
|
+
attr_accessor :name,:parent
|
96
|
+
def initialize(name)
|
97
|
+
@name = name
|
98
|
+
@parent = nil
|
99
|
+
end
|
100
|
+
# TODO: operations
|
101
|
+
#operations#
|
102
|
+
end
|
103
|
+
|
104
|
+
```
|
105
|
+
|
106
|
+
See ./templates for detail.
|
107
|
+
|
108
|
+
7. Set dir as search path
|
109
|
+
|
110
|
+
```
|
111
|
+
pattern -t tempate_dir]
|
112
|
+
```
|
113
|
+
|
114
|
+
## Future
|
115
|
+
Sharing pattern templates on website.
|
116
|
+
|
117
|
+
## Version
|
118
|
+
0.9.4
|
119
|
+
1. Refactoring the code
|
120
|
+
2. Template of ruby.composite work
|
121
|
+
3. Getting help with no parameter
|
122
|
+
4. Replacing lower_case name . Example: class_name:Task lc_class_name:task
|
123
|
+
|
124
|
+
|
125
|
+
== Question
|
126
|
+
If you get some Questions. Mailto :azhao.1981@gmail.com
|
127
|
+
|
128
|
+
== Author
|
129
|
+
|
130
|
+
Copyright 2010 @ weizhao
|
131
|
+
mailto: azhao.1981@gmail.com
|
132
|
+
|
133
|
+
== licese
|
134
|
+
|
135
|
+
This library and all associated materials are releassse under the terms of version 2 of the GNU Public License(http://www.gnu.org/copyleft/gpl.html).
|
data/bin/pattern
CHANGED
@@ -1,31 +1,47 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
#for require file relative.in ruby 1.9.3 use require_relative
|
5
|
+
def require_r(path) require(File.expand_path(path.to_s, File.dirname(__FILE__))) end
|
6
|
+
|
7
|
+
require 'optparse'
|
8
|
+
require_r '../lib/version'
|
9
|
+
require_r '../lib/configuration'
|
3
10
|
|
4
|
-
require current_dir + '/../lib/version'
|
5
11
|
puts "#{Pattern::HELP::WELLCOME}"
|
6
|
-
if %w(--version -v).include? ARGV.first
|
7
|
-
puts "pattern #{Pattern::VERSION::STRING}"
|
8
|
-
exit(0)
|
9
|
-
end
|
10
|
-
require current_dir + '/../lib/configuration'
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
options = {}
|
14
|
+
option_parser = OptionParser.new do |opts|
|
15
|
+
opts.banner = "Usage:"
|
16
|
+
|
17
|
+
opts.on('-v','--version','Show Version') do
|
18
|
+
puts "pattern #{Pattern::VERSION::STRING}"
|
19
|
+
exit(0)
|
20
|
+
end
|
21
|
+
|
22
|
+
opts.on('-s','--set','Set template dir' ) do
|
23
|
+
configuration = Configuration.new
|
24
|
+
configuration.execute(ARGV)
|
25
|
+
exit(0)
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on('-l','--list','list template dirs') do
|
29
|
+
configuration = Configuration.new
|
30
|
+
configuration.list
|
31
|
+
exit(0)
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on('-f','--file','Specify pattern file') do |file|
|
35
|
+
|
36
|
+
end
|
17
37
|
|
18
|
-
|
19
|
-
configuration = Configuration.new
|
20
|
-
configuration.list
|
21
|
-
exit(0)
|
22
|
-
end
|
38
|
+
end.parse!
|
23
39
|
|
24
40
|
if (ARGV.empty? || (%w(--help -h).include? ARGV.first))
|
25
41
|
puts Pattern::HELP::STRING
|
26
42
|
exit(0)
|
27
43
|
end
|
28
44
|
|
29
|
-
|
45
|
+
require_r '../lib/compositecode'
|
30
46
|
pattern = CompositeCode.new(Command.new(ARGV))
|
31
47
|
pattern.execute
|
data/lib/code.rb
CHANGED
data/lib/common.rb
CHANGED
data/lib/configuration.rb
CHANGED
@@ -29,8 +29,8 @@ class Configuration
|
|
29
29
|
puts list-[".",".."]
|
30
30
|
end
|
31
31
|
def execute(argv)
|
32
|
-
parameters = argv[
|
33
|
-
action = argv[
|
32
|
+
parameters = argv[1..100] || [Dir.pwd]
|
33
|
+
action = argv[0]
|
34
34
|
add_path(parameters) if action=="add"
|
35
35
|
remove_path(parameters) if action == "remove"
|
36
36
|
get_default if action == "default"
|
data/lib/patternrobot.rb
ADDED
data/lib/version.rb
CHANGED
@@ -2,31 +2,31 @@ module Pattern
|
|
2
2
|
module VERSION #:nodoc:
|
3
3
|
MAJOR = 0
|
4
4
|
MINOR = 9
|
5
|
-
TINY =
|
5
|
+
TINY = 7
|
6
6
|
|
7
7
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
8
8
|
end
|
9
9
|
module HELP
|
10
10
|
STRING = <<-EOF
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
11
|
+
pattern is a tool for coding/learning pattern/data structure.
|
12
|
+
Usage:
|
13
|
+
pattern -h/--help
|
14
|
+
pattern -v/--version
|
15
|
+
pattern -l/--list
|
16
|
+
pattern -s/--set [add/remove/default] [template_dir]
|
17
|
+
pattern [tempate_dir] [main_class_name] [-d target_dir]
|
18
|
+
pattern [-t tempate_dir] [-d target_dir("." is default)] [-c classes_name] [-op operations_name]
|
19
|
+
Examples:
|
20
|
+
pattern -l List template you get
|
21
|
+
pattern -s add . Add current dir as templates path
|
22
|
+
pattern ruby.composite Task Generate a composite pattern ,which base class name as Task
|
23
|
+
pattern -t ruby.composite -d E:/dev/pattern/target -c Task;CompositeTask;AddDryIngredientsTask,MixTask;MakeBatterTask -op execute,test
|
24
|
+
Further Help:
|
25
|
+
Further information:
|
26
|
+
https://github.com/azhao1981/pattern
|
27
27
|
EOF
|
28
28
|
WELLCOME = <<-EOF
|
29
|
-
|
29
|
+
Thanks for using pattern beta.Q&Ideas Mailto:azhao.1981@gmail.com
|
30
30
|
EOF
|
31
31
|
end
|
32
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pattern
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-18 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! "\t Tool for coding/learning pattern/data structure\n"
|
15
15
|
email: azhao.1981@gmail.com
|
@@ -18,33 +18,28 @@ executables:
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
-
- lib/
|
22
|
-
- lib/version.rb
|
21
|
+
- lib/code.rb
|
23
22
|
- lib/command.rb
|
24
|
-
- lib/patterncode.rb
|
25
|
-
- lib/configuration.rb
|
26
23
|
- lib/common.rb
|
27
|
-
- lib/
|
24
|
+
- lib/compositecode.rb
|
25
|
+
- lib/configuration.rb
|
26
|
+
- lib/patterncode.rb
|
27
|
+
- lib/patternrobot.rb
|
28
|
+
- lib/version.rb
|
28
29
|
- bin/pattern
|
29
30
|
- LICENSE
|
30
|
-
- README
|
31
|
-
- Rakefile
|
32
31
|
- README.cn
|
33
|
-
-
|
34
|
-
- test/compositecode_spec.rb
|
35
|
-
- test/code_spec.rb
|
36
|
-
- test/command_spec.rb
|
37
|
-
- test/configuration_spec.rb
|
38
|
-
- templates/ruby.template/concreteclass.rb
|
39
|
-
- templates/ruby.template/abstractclass.rb
|
40
|
-
- templates/ruby.template/readme
|
41
|
-
- templates/ruby.template/operations
|
42
|
-
- templates/ruby.composite/leaf.rb
|
32
|
+
- README.md
|
43
33
|
- templates/ruby.composite/component.rb
|
44
|
-
- templates/ruby.composite/compositeobject.rb
|
45
34
|
- templates/ruby.composite/composite.rb
|
46
|
-
- templates/ruby.composite/
|
35
|
+
- templates/ruby.composite/compositeobject.rb
|
36
|
+
- templates/ruby.composite/leaf.rb
|
47
37
|
- templates/ruby.composite/operations
|
38
|
+
- templates/ruby.composite/readme
|
39
|
+
- templates/ruby.template/abstractclass.rb
|
40
|
+
- templates/ruby.template/concreteclass.rb
|
41
|
+
- templates/ruby.template/operations
|
42
|
+
- templates/ruby.template/readme
|
48
43
|
- etc/templates_path.conf
|
49
44
|
- docs/todolist.txt
|
50
45
|
homepage: https://github.com/azhao1981/pattern
|
@@ -70,13 +65,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
65
|
version: '0'
|
71
66
|
requirements: []
|
72
67
|
rubyforge_project: pattern
|
73
|
-
rubygems_version: 1.8.
|
68
|
+
rubygems_version: 1.8.24
|
74
69
|
signing_key:
|
75
70
|
specification_version: 3
|
76
71
|
summary: auto code tools.
|
77
|
-
test_files:
|
78
|
-
- test/patterncode_spec.rb
|
79
|
-
- test/compositecode_spec.rb
|
80
|
-
- test/code_spec.rb
|
81
|
-
- test/command_spec.rb
|
82
|
-
- test/configuration_spec.rb
|
72
|
+
test_files: []
|
data/README
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
== EasyPattern
|
2
|
-
|
3
|
-
Rubygem for building Pattern/Data Structure .
|
4
|
-
Supports custom templates by any language.
|
5
|
-
Good tools for learning Pattern/Data Structure.
|
6
|
-
|
7
|
-
== Useage
|
8
|
-
|
9
|
-
simple model
|
10
|
-
*pattern [tempate_dir] [main_class_name] [-d target_dir]
|
11
|
-
*pattern [-t tempate_dir] [-d target_dir("." is default)] [-c classes_name] [-op operations_name]
|
12
|
-
complex model (not support now.)
|
13
|
-
*pattern -f pattern_file
|
14
|
-
|
15
|
-
== example:
|
16
|
-
|
17
|
-
simple model:
|
18
|
-
* pattern ruby.composite Task -d target
|
19
|
-
* pattern -t ruby.composite -d target -c Task;CompositeTask;AddDryIngredientsTask,MixTask,AddLiquidsTask;MakeBatterTask,MakeCakeTask -op get_time_required
|
20
|
-
complex model(pattern_file):
|
21
|
-
|
22
|
-
== Future
|
23
|
-
Sharing pattern templates on website.
|
24
|
-
|
25
|
-
== Version
|
26
|
-
0.9.4
|
27
|
-
1. Refactoring the code
|
28
|
-
2. Template of ruby.composite work
|
29
|
-
3. Getting help with no parameter
|
30
|
-
4. Replacing lower_case name . Example: class_name:Task lc_class_name:task
|
31
|
-
|
32
|
-
|
33
|
-
== Question
|
34
|
-
If you get some Questions. Mailto :azhao.1981@gmail.com
|
35
|
-
|
36
|
-
== Author
|
37
|
-
|
38
|
-
Copyright 2010 @ weizhao
|
39
|
-
mailto: azhao.1981@gmail.com
|
40
|
-
|
41
|
-
== licese
|
42
|
-
|
43
|
-
This library and all associated materials are releassse under the terms of version 2 of the GNU Public License(http://www.gnu.org/copyleft/gpl.html).
|
data/Rakefile
DELETED
data/test/code_spec.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2010 weizhao
|
3
|
-
#
|
4
|
-
require File.dirname(__FILE__) + '/../lib/code'
|
5
|
-
require File.dirname(__FILE__) + '/../lib/common'
|
6
|
-
include PathCommon
|
7
|
-
|
8
|
-
describe Code do
|
9
|
-
before(:each) do
|
10
|
-
template_file_name = absolute_path("../templates/ruby.composite/component.rb",File.dirname(__FILE__))
|
11
|
-
target_file_name = absolute_path("../temp/task",File.dirname(__FILE__))
|
12
|
-
@target_file_name_test = target_file_name
|
13
|
-
replace_values = {"class_name"=>"Task","operations"=>" def execute\n \t\n end\n"}
|
14
|
-
@component_code = Code.new(template_file_name,target_file_name,replace_values)
|
15
|
-
end
|
16
|
-
it "1. replace_template should return template contain 'Task' & 'execute' " do
|
17
|
-
template = @component_code.replace_template
|
18
|
-
(/Task/ =~ template).should > 0
|
19
|
-
(/execute/ =~ template).should > 0
|
20
|
-
end
|
21
|
-
|
22
|
-
it "2. generate_code should create a new file" do
|
23
|
-
@component_code.generate_code
|
24
|
-
template = File.open(@target_file_name_test).readlines.join
|
25
|
-
(/Task/ =~ template).should be > 0
|
26
|
-
(/execute/ =~ template).should be > 0
|
27
|
-
end
|
28
|
-
|
29
|
-
it "3. execute will do generate_code " do
|
30
|
-
@component_code.execute
|
31
|
-
template = File.open(@target_file_name_test).readlines.join
|
32
|
-
(/Task/ =~ template).should be > 0
|
33
|
-
(/execute/ =~ template).should be > 0
|
34
|
-
end
|
35
|
-
end
|
data/test/command_spec.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../lib/command'
|
2
|
-
|
3
|
-
describe Command do
|
4
|
-
before(:each) do
|
5
|
-
params = "-t ruby.composite -c Task;compositeTask;AddDryIngredientsTask,MixTask;MakeBatterTask -op execute".split(" ")
|
6
|
-
@command = Command.new(params)
|
7
|
-
end
|
8
|
-
it "1. Command.new should get right parameter form param" do
|
9
|
-
@command.template_dir.should == "E:/dev/pattern/templates/ruby.composite"
|
10
|
-
@command.classes.should == [["Task"],["compositeTask"],
|
11
|
-
["AddDryIngredientsTask","MixTask"],["MakeBatterTask"]]
|
12
|
-
@command.operations.should == [['execute']]
|
13
|
-
@command.target_dir.should == "E:/dev/pattern"
|
14
|
-
end
|
15
|
-
it "2. absolute_path should return absolute path " do
|
16
|
-
@command.absolute_path("../templates/ruby.composite","./bin/../lib").should == "E:/dev/pattern/templates/ruby.composite"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
data/test/compositecode_spec.rb
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../lib/compositecode'
|
2
|
-
|
3
|
-
describe CompositeCode do
|
4
|
-
before(:each) do
|
5
|
-
params = "-t ruby.composite -d E:/dev/pattern/target -c Task;CompositeTask;AddDryIngredientsTask,MixTask;MakeBatterTask -op execute,test".split(" ")
|
6
|
-
@command = Command.new(params)
|
7
|
-
@target_dir = "E:/dev/pattern/target"
|
8
|
-
@compositecode = CompositeCode.new(@command)
|
9
|
-
end
|
10
|
-
it "1. classes_to_codes should return codes " do
|
11
|
-
@compositecode.load_readme
|
12
|
-
@compositecode.classes_to_codes.length.should == 5
|
13
|
-
code = @compositecode.codes[0]
|
14
|
-
code.template_file_name.should == "E:/dev/pattern/templates/ruby.composite/component.rb"
|
15
|
-
code.target_file_name.should == "E:/dev/pattern/target/task.rb"
|
16
|
-
code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
|
17
|
-
"leaf_name"=>"AddDryIngredientsTask",
|
18
|
-
"composite_object_name"=>"MakeBatterTask",
|
19
|
-
"lc_class_name"=>"task","lc_composite_name"=>"compositetask",
|
20
|
-
"lc_leaf_name"=>"adddryingredientstask",
|
21
|
-
"lc_composite_object_name"=>"makebattertask",
|
22
|
-
"operations"=>" def execute\n \t\n end\n def test\n \t\n end\n"
|
23
|
-
}
|
24
|
-
code = @compositecode.codes[1]
|
25
|
-
code.template_file_name.should == "E:/dev/pattern/templates/ruby.composite/composite.rb"
|
26
|
-
code.target_file_name.should == "E:/dev/pattern/target/compositetask.rb"
|
27
|
-
code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
|
28
|
-
"leaf_name"=>"AddDryIngredientsTask",
|
29
|
-
"composite_object_name"=>"MakeBatterTask",
|
30
|
-
"lc_class_name"=>"task","lc_composite_name"=>"compositetask",
|
31
|
-
"lc_leaf_name"=>"adddryingredientstask",
|
32
|
-
"lc_composite_object_name"=>"makebattertask",
|
33
|
-
"operations"=>" def execute\n \t\n end\n def test\n \t\n end\n"
|
34
|
-
}
|
35
|
-
code = @compositecode.codes[2]
|
36
|
-
code.template_file_name.should == "E:/dev/pattern/templates/ruby.composite/leaf.rb"
|
37
|
-
code.target_file_name.should == "E:/dev/pattern/target/adddryingredientstask.rb"
|
38
|
-
code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
|
39
|
-
"leaf_name"=>"AddDryIngredientsTask",
|
40
|
-
"composite_object_name"=>"MakeBatterTask",
|
41
|
-
"lc_class_name"=>"task","lc_composite_name"=>"compositetask",
|
42
|
-
"lc_leaf_name"=>"adddryingredientstask",
|
43
|
-
"lc_composite_object_name"=>"makebattertask",
|
44
|
-
"operations"=>" def execute\n \t\n end\n def test\n \t\n end\n"
|
45
|
-
}
|
46
|
-
code = @compositecode.codes[3]
|
47
|
-
code.template_file_name.should == "E:/dev/pattern/templates/ruby.composite/leaf.rb"
|
48
|
-
code.target_file_name.should == "E:/dev/pattern/target/mixtask.rb"
|
49
|
-
code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
|
50
|
-
"leaf_name"=>"MixTask",
|
51
|
-
"composite_object_name"=>"MakeBatterTask",
|
52
|
-
"lc_class_name"=>"task","lc_composite_name"=>"compositetask",
|
53
|
-
"lc_leaf_name"=>"mixtask",
|
54
|
-
"lc_composite_object_name"=>"makebattertask",
|
55
|
-
"operations"=>" def execute\n \t\n end\n def test\n \t\n end\n"
|
56
|
-
}
|
57
|
-
code = @compositecode.codes[4]
|
58
|
-
code.template_file_name.should == "E:/dev/pattern/templates/ruby.composite/compositeobject.rb"
|
59
|
-
code.target_file_name.should == "E:/dev/pattern/target/makebattertask.rb"
|
60
|
-
code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
|
61
|
-
"leaf_name"=>"AddDryIngredientsTask",
|
62
|
-
"composite_object_name"=>"MakeBatterTask",
|
63
|
-
"lc_class_name"=>"task","lc_composite_name"=>"compositetask",
|
64
|
-
"lc_leaf_name"=>"adddryingredientstask",
|
65
|
-
"lc_composite_object_name"=>"makebattertask",
|
66
|
-
"operations"=>" def execute\n \t\n end\n def test\n \t\n end\n"
|
67
|
-
}
|
68
|
-
end
|
69
|
-
it "2. default params should return base_name and default_classes " do
|
70
|
-
params = "ruby.composite Task -d E:/dev/pattern/target".split(" ")
|
71
|
-
@compositecode = CompositeCode.new(Command.new(params))
|
72
|
-
@compositecode.load_readme
|
73
|
-
@compositecode.classes_to_codes.length.should == 4
|
74
|
-
code = @compositecode.codes[0]
|
75
|
-
code.template_file_name.should == "E:/dev/pattern/templates/ruby.composite/component.rb"
|
76
|
-
code.target_file_name.should == "E:/dev/pattern/target/task.rb"
|
77
|
-
code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
|
78
|
-
"leaf_name"=>"LeafTask",
|
79
|
-
"composite_object_name"=>"CompositeObjectTask",
|
80
|
-
"lc_class_name"=>"task","lc_composite_name"=>"compositetask",
|
81
|
-
"lc_leaf_name"=>"leaftask",
|
82
|
-
"lc_composite_object_name"=>"compositeobjecttask",
|
83
|
-
"operations"=>""
|
84
|
-
}
|
85
|
-
code = @compositecode.codes[1]
|
86
|
-
code.template_file_name.should == "E:/dev/pattern/templates/ruby.composite/composite.rb"
|
87
|
-
code.target_file_name.should == "E:/dev/pattern/target/compositetask.rb"
|
88
|
-
code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
|
89
|
-
"leaf_name"=>"LeafTask",
|
90
|
-
"composite_object_name"=>"CompositeObjectTask",
|
91
|
-
"lc_class_name"=>"task","lc_composite_name"=>"compositetask",
|
92
|
-
"lc_leaf_name"=>"leaftask",
|
93
|
-
"lc_composite_object_name"=>"compositeobjecttask",
|
94
|
-
"operations"=>""
|
95
|
-
}
|
96
|
-
code = @compositecode.codes[2]
|
97
|
-
code.template_file_name.should == "E:/dev/pattern/templates/ruby.composite/leaf.rb"
|
98
|
-
code.target_file_name.should == "E:/dev/pattern/target/leaftask.rb"
|
99
|
-
code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
|
100
|
-
"leaf_name"=>"LeafTask",
|
101
|
-
"composite_object_name"=>"CompositeObjectTask",
|
102
|
-
"lc_class_name"=>"task","lc_composite_name"=>"compositetask",
|
103
|
-
"lc_leaf_name"=>"leaftask",
|
104
|
-
"lc_composite_object_name"=>"compositeobjecttask",
|
105
|
-
"operations"=>""
|
106
|
-
}
|
107
|
-
code = @compositecode.codes[3]
|
108
|
-
code.template_file_name.should == "E:/dev/pattern/templates/ruby.composite/compositeobject.rb"
|
109
|
-
code.target_file_name.should == "E:/dev/pattern/target/compositeobjecttask.rb"
|
110
|
-
code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
|
111
|
-
"leaf_name"=>"LeafTask",
|
112
|
-
"composite_object_name"=>"CompositeObjectTask",
|
113
|
-
"lc_class_name"=>"task","lc_composite_name"=>"compositetask",
|
114
|
-
"lc_leaf_name"=>"leaftask",
|
115
|
-
"lc_composite_object_name"=>"compositeobjecttask",
|
116
|
-
"operations"=>""
|
117
|
-
}
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
data/test/configuration_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../lib/configuration'
|
2
|
-
|
3
|
-
describe Configuration do
|
4
|
-
before(:each) do
|
5
|
-
@configuration = Configuration.new
|
6
|
-
@configuration.get_default
|
7
|
-
end
|
8
|
-
after(:each) do
|
9
|
-
@configuration.get_default
|
10
|
-
end
|
11
|
-
it "1. get_path should return current path " do
|
12
|
-
@configuration.get_path[0].should == "E:/dev/pattern/templates"
|
13
|
-
@configuration.get_path.length == 1
|
14
|
-
end
|
15
|
-
it "2. add_path should add a path into configuration" do
|
16
|
-
@configuration.add_path(["E:/dev/pattern/templates2","E:/dev/pattern/templates3"])
|
17
|
-
@configuration.get_path[0].should == "E:/dev/pattern/templates"
|
18
|
-
@configuration.get_path[1].should == "E:/dev/pattern/templates2"
|
19
|
-
@configuration.get_path[2].should == "E:/dev/pattern/templates3"
|
20
|
-
@configuration.get_path.length == 3
|
21
|
-
end
|
22
|
-
it "3. remove_path should remove a path form configuration" do
|
23
|
-
@configuration.add_path(["E:/dev/pattern/templates2","E:/dev/pattern/templates3"])
|
24
|
-
@configuration.remove_path(["E:/dev/pattern/templates2"])
|
25
|
-
@configuration.get_path[1].should == "E:/dev/pattern/templates3"
|
26
|
-
@configuration.get_path.length == 2
|
27
|
-
end
|
28
|
-
end
|
data/test/patterncode_spec.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2010 weizhao
|
3
|
-
#
|
4
|
-
require File.dirname(__FILE__) + '/../lib/patterncode'
|
5
|
-
require File.dirname(__FILE__) + '/../lib/common'
|
6
|
-
include PathCommon
|
7
|
-
|
8
|
-
describe PatternCode do
|
9
|
-
before(:each) do
|
10
|
-
template_file_name = absolute_path("../templates/ruby.composite/component.rb",File.dirname(__FILE__))
|
11
|
-
target_file_name = absolute_path("../temp/task",File.dirname(__FILE__))
|
12
|
-
@target_file_name_test = target_file_name
|
13
|
-
replace_values = {"class_name"=>"Task","operations"=>" def execute\n \t\n end\n"}
|
14
|
-
@component_code = PatternCode.new(template_file_name,target_file_name,replace_values)
|
15
|
-
end
|
16
|
-
it "1. replace_template should return template contain 'Task' & 'execute' " do
|
17
|
-
template = @component_code.replace_template
|
18
|
-
(/Task/ =~ template).should be > 0
|
19
|
-
(/execute/ =~ template).should be > 0
|
20
|
-
end
|
21
|
-
|
22
|
-
it "2. generate_code should create a new file" do
|
23
|
-
@component_code.generate_code
|
24
|
-
template = File.open(@target_file_name_test).readlines.join
|
25
|
-
(/Task/ =~ template).should be > 0
|
26
|
-
(/execute/ =~ template).should be > 0
|
27
|
-
end
|
28
|
-
|
29
|
-
it "3. execute will do generate_code " do
|
30
|
-
@component_code.execute
|
31
|
-
template = File.open(@target_file_name_test).readlines.join
|
32
|
-
(/Task/ =~ template).should be > 0
|
33
|
-
(/execute/ =~ template).should be > 0
|
34
|
-
end
|
35
|
-
end
|