pattern 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/patterncode.rb CHANGED
@@ -1,7 +1,7 @@
1
- #--
2
- # Copyright (c) 2010 weizhao
3
- #
4
- require 'code'
5
- class PatternCode < Code
6
-
1
+ #--
2
+ # Copyright (c) 2010 weizhao
3
+ #
4
+ require 'code'
5
+ class PatternCode < Code
6
+
7
7
  end
data/lib/version.rb CHANGED
@@ -1,32 +1,32 @@
1
- module Pattern
2
- module VERSION #:nodoc:
3
- MAJOR = 0
4
- MINOR = 9
5
- TINY = 4
6
-
7
- STRING = [MAJOR, MINOR, TINY].join('.')
8
- end
9
- module HELP
10
- STRING = <<-EOF
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
- EOF
28
- WELLCOME = <<-EOF
29
- Thanks for using pattern beta.You get idea or Question.Mailto:azhao.1981@gmail.com
30
- EOF
31
- end
32
- end
1
+ module Pattern
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 9
5
+ TINY = 5
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ module HELP
10
+ STRING = <<-EOF
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
+ EOF
28
+ WELLCOME = <<-EOF
29
+ Thanks for using pattern beta.You get idea or Question.Mailto:azhao.1981@gmail.com
30
+ EOF
31
+ end
32
+ end
@@ -1,12 +1,12 @@
1
- # This is code of composite pattern . Generated by easypattern.
2
- #
3
-
4
- class #class_name#
5
- attr_accessor :name,:parent
6
- def initialize(name)
7
- @name = name
8
- @parent = nil
9
- end
10
- # TODO: operations
11
- #operations#
12
- end
1
+ # This is code of composite pattern . Generated by pattern.
2
+ #
3
+
4
+ class #class_name#
5
+ attr_accessor :name,:parent
6
+ def initialize(name)
7
+ @name = name
8
+ @parent = nil
9
+ end
10
+ # TODO: operations
11
+ #operations#
12
+ end
@@ -1,32 +1,32 @@
1
- # This is code of composite pattern . Generated by easypattern.
2
- #
3
- require "#lc_class_name#"
4
-
5
- class #composite_name# < #class_name#
6
- def initialize(name)
7
- super(name)
8
- @sub_#lc_class_name#s = []
9
- end
10
- def add_sub_#lc_class_name#(#lc_class_name#)
11
- @sub_#lc_class_name#s << #lc_class_name#
12
- #lc_class_name#.parent = self
13
- end
14
- def remove_sub_#lc_class_name#(#lc_class_name#)
15
- @sub_#lc_class_name#s.delete(#lc_class_name#)
16
- #lc_class_name#.parent = nil
17
- end
18
- def << (#lc_class_name#)
19
- @sub_#lc_class_name#s << #lc_class_name#
20
- #lc_class_name#.parent = self
21
- end
22
- def [](index)
23
- @sub_#lc_class_name#s[index]
24
- end
25
- def []=(index,new_value)
26
- @sub_#lc_class_name#s[index].parent = nil
27
- @sub_#lc_class_name#s[index] = new_value
28
- @sub_#lc_class_name#s[index].parent = self
29
- end
30
- # TODO: operations
31
- #operations#
32
- end
1
+ # This is code of composite pattern . Generated by pattern.
2
+ #
3
+ require "#lc_class_name#"
4
+
5
+ class #composite_name# < #class_name#
6
+ def initialize(name)
7
+ super(name)
8
+ @sub_#lc_class_name#s = []
9
+ end
10
+ def add_sub_#lc_class_name#(#lc_class_name#)
11
+ @sub_#lc_class_name#s << #lc_class_name#
12
+ #lc_class_name#.parent = self
13
+ end
14
+ def remove_sub_#lc_class_name#(#lc_class_name#)
15
+ @sub_#lc_class_name#s.delete(#lc_class_name#)
16
+ #lc_class_name#.parent = nil
17
+ end
18
+ def << (#lc_class_name#)
19
+ @sub_#lc_class_name#s << #lc_class_name#
20
+ #lc_class_name#.parent = self
21
+ end
22
+ def [](index)
23
+ @sub_#lc_class_name#s[index]
24
+ end
25
+ def []=(index,new_value)
26
+ @sub_#lc_class_name#s[index].parent = nil
27
+ @sub_#lc_class_name#s[index] = new_value
28
+ @sub_#lc_class_name#s[index].parent = self
29
+ end
30
+ # TODO: operations
31
+ #operations#
32
+ end
@@ -1,13 +1,13 @@
1
- # This is code of composite pattern . Generated by easypattern.
2
- #
3
- require "#lc_composite_name#"
4
-
5
- class #composite_object_name# < #composite_name#
6
- def initialize
7
- super("#lc_composite_object_name#")
8
- #ToDo :add sub class
9
- add_sub_task(#sub_class)
10
- end
11
- # TODO: operations
12
- #operations#
13
- end
1
+ # This is code of composite pattern . Generated by pattern.
2
+ #
3
+ require "#lc_composite_name#"
4
+
5
+ class #composite_object_name# < #composite_name#
6
+ def initialize
7
+ super("#lc_composite_object_name#")
8
+ #ToDo :add sub class
9
+ add_sub_task(#sub_class)
10
+ end
11
+ # TODO: operations
12
+ #operations#
13
+ end
@@ -1,11 +1,11 @@
1
- # This is code of composite pattern . Generated by easypattern.
2
- #
3
- require "#lc_class_name#"
4
-
5
- class #leaf_name# < #class_name#
6
- def initialize
7
- super("#leaf_name#")
8
- end
9
- # TODO: operations
10
- #operations#
11
- end
1
+ # This is code of composite pattern . Generated by pattern.
2
+ #
3
+ require "#lc_class_name#"
4
+
5
+ class #leaf_name# < #class_name#
6
+ def initialize
7
+ super("#leaf_name#")
8
+ end
9
+ # TODO: operations
10
+ #operations#
11
+ end
@@ -1,3 +1,3 @@
1
- def #operation#
2
-
3
- end
1
+ def #operation#
2
+
3
+ end
@@ -1,5 +1,5 @@
1
- template "component.rb","class_name"
2
- template "composite.rb","composite_name"
3
- template "leaf.rb","leaf_name"
4
- template "compositeobject.rb","composite_object_name"
1
+ template "component.rb","class_name"
2
+ template "composite.rb","composite_name"
3
+ template "leaf.rb","leaf_name"
4
+ template "compositeobject.rb","composite_object_name"
5
5
  default @base_name,"Composite#{@base_name}","Leaf#{@base_name}","CompositeObject#{@base_name}"
@@ -0,0 +1,8 @@
1
+ # class #class_name# :abstractclass of template pattern
2
+
3
+ class #class_name#
4
+ def initialize
5
+
6
+ end
7
+ #operations#
8
+ end
@@ -0,0 +1,9 @@
1
+ # class #class_name# :abstractclass of template pattern
2
+ require "#lc_class_name#"
3
+
4
+ class #concrete_name# < #class_name#
5
+ def initialize
6
+
7
+ end
8
+ #operations#
9
+ end
@@ -0,0 +1,3 @@
1
+ def #operation#
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ default @base_name,"#{@base_name}Concrete"
2
+ template "abstractclass.rb","class_name"
3
+ template "concreteclass.rb","concrete_name"
data/test/code_spec.rb CHANGED
@@ -1,35 +1,35 @@
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
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
35
  end
data/test/command_spec.rb CHANGED
@@ -1,19 +1,19 @@
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
-
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
+