pattern 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/DOCS/todolist.txt CHANGED
@@ -7,4 +7,11 @@
7
7
  4. 支持建立文件夹 X
8
8
  5. 支持默认模式 OK
9
9
  6. 支持添加template目录
10
- 7.
10
+ 6.1. config类来处理
11
+ 6.2. 添加一个
12
+ 6.3. 删除一个
13
+ 7. 添加新的templates
14
+ 8. 列出可用的template
15
+ 9. help功能
16
+
17
+ 发现一个问题,如果我的问题不能按我的想法来排列,我先做下面的,再做上面的,我会很不舒服
data/bin/pattern CHANGED
@@ -1,12 +1,19 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  current_dir = File.dirname(__FILE__)
4
3
 
5
- require current_dir + '/../lib/version'
6
4
  if %w(--version -v).include? ARGV.first
5
+ require current_dir + '/../lib/version'
7
6
  puts "pattern #{Pattern::VERSION::STRING}"
8
7
  exit(0)
9
8
  end
9
+
10
+ if %w(--set -s).include? ARGV.first
11
+ require current_dir + '/../lib/configuration'
12
+ configuration = Configuration.new
13
+ configuration.execute(ARGV)
14
+ exit(0)
15
+ end
16
+
10
17
  require current_dir + '/../lib/compositecode'
11
18
  pattern = CompositeCode.new(Command.new(ARGV))
12
19
  pattern.execute
@@ -1,2 +1,2 @@
1
1
  ../templates
2
- E:/dev/easypattern/templates2
2
+ E:/dev/pattern/templates2
@@ -0,0 +1,44 @@
1
+ # config templates_path
2
+
3
+ require 'pathname'
4
+
5
+ class Configuration
6
+ def initialize
7
+ @config_file = "#{File.dirname(__FILE__)}/../etc/templates_path.conf"
8
+ end
9
+ def get_path
10
+ File.open(@config_file).readlines.collect do |path|
11
+ path = absolute_path(path.chomp,File.dirname(__FILE__))
12
+ end
13
+ end
14
+ def add_path(path)
15
+ File.open(@config_file,"a") do |file|
16
+ path.each do |p|
17
+ file.puts absolute_path(p)
18
+ end
19
+ end
20
+ end
21
+ def remove_path(path)
22
+ path_set = get_path - path.collect { |p| p= absolute_path(p) }
23
+ File.open(@config_file,"w") do |file|
24
+ path_set.each do |p|
25
+ file.puts p
26
+ end
27
+ end
28
+ end
29
+ def execute(argv)
30
+ parameters = argv[2..100] || [Dir.pwd]
31
+ action = argv[1]
32
+ add_path(parameters) if action=="add"
33
+ remove_path(parameters) if action == "remove"
34
+ get_default if action == "default"
35
+ end
36
+ def get_default
37
+ File.open(@config_file,"w") do |file|
38
+ file.puts "../templates"
39
+ end
40
+ end
41
+ def absolute_path(path,dir=Dir.pwd)
42
+ Pathname.new(path).relative? ? File.expand_path(path,dir) : path
43
+ end
44
+ end
data/lib/version.rb CHANGED
@@ -2,7 +2,7 @@ module Pattern
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 9
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/pattern-0.9.1.gem ADDED
Binary file
data/pattern.gemspec CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |spec|
4
4
  # Package information
5
5
  #-----------------------------
6
6
  spec.name = 'pattern'
7
- spec.version = '0.9.1'
7
+ spec.version = '0.9.2'
8
8
  spec.executables << 'pattern'
9
9
  spec.has_rdoc = true
10
10
  spec.rdoc_options << '--title' << 'Pattern' <<
data/test/command_spec.rb CHANGED
@@ -9,19 +9,18 @@ describe Command do
9
9
  @command.get_template_dir_from_params.should == "ruby.composite"
10
10
  end
11
11
  it "2. get_templates_dirs should return ['../templates','../templates2']" do
12
- @command.get_templates_dirs(@command.get_template_dir_from_params).should ==
13
- ['E:/dev/easypattern/templates/ruby.composite',
14
- 'E:/dev/easypattern/templates2/ruby.composite']
12
+ @command.get_templates_dirs(@command.get_template_dir_from_params)[0].should ==
13
+ 'E:/dev/pattern/templates/ruby.composite'
15
14
  end
16
15
  it "3. Command.new should get right parameter form param" do
17
- @command.template_dir.should == "E:/dev/easypattern/templates/ruby.composite"
16
+ @command.template_dir.should == "E:/dev/pattern/templates/ruby.composite"
18
17
  @command.classes.should == [["Task"],["compositeTask"],
19
18
  ["AddDryIngredientsTask","MixTask"],["MakeBatterTask"]]
20
19
  @command.operations.should == [['execute']]
21
- @command.target_dir.should == "E:/dev/easypattern"
20
+ @command.target_dir.should == "E:/dev/pattern"
22
21
  end
23
22
  it "4. absolute_path should return absolute path " do
24
- @command.absolute_path("../templates/ruby.composite","./bin/../lib").should == "E:/dev/easypattern/templates/ruby.composite"
23
+ @command.absolute_path("../templates/ruby.composite","./bin/../lib").should == "E:/dev/pattern/templates/ruby.composite"
25
24
  end
26
25
  end
27
26
 
@@ -2,49 +2,49 @@ require File.dirname(__FILE__) + '/../lib/compositecode'
2
2
 
3
3
  describe CompositeCode do
4
4
  before(:each) do
5
- params = "-t ruby.composite -d E:/dev/easypattern/target -c Task;CompositeTask;AddDryIngredientsTask,MixTask;MakeBatterTask -op execute,test".split(" ")
5
+ params = "-t ruby.composite -d E:/dev/pattern/target -c Task;CompositeTask;AddDryIngredientsTask,MixTask;MakeBatterTask -op execute,test".split(" ")
6
6
  @command = Command.new(params)
7
- @target_dir = "E:/dev/easypattern/target"
7
+ @target_dir = "E:/dev/pattern/target"
8
8
  @compositecode = CompositeCode.new(@command)
9
9
  end
10
10
  it "1. classes_to_codes should return codes " do
11
11
  @compositecode.load_readme
12
12
  @compositecode.classes_to_codes.length.should == 5
13
13
  code = @compositecode.codes[0]
14
- code.template_file_name.should == "E:/dev/easypattern/templates/ruby.composite/component.rb"
15
- code.target_file_name.should == "E:/dev/easypattern/target/task.rb"
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
16
  code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
17
17
  "leaf_name"=>"AddDryIngredientsTask",
18
18
  "composite_object_name"=>"MakeBatterTask",
19
19
  "operations"=>" def execute\n \t\n end\n def test\n \t\n end\n"
20
20
  }
21
21
  code = @compositecode.codes[1]
22
- code.template_file_name.should == "E:/dev/easypattern/templates/ruby.composite/composite.rb"
23
- code.target_file_name.should == "E:/dev/easypattern/target/compositetask.rb"
22
+ code.template_file_name.should == "E:/dev/pattern/templates/ruby.composite/composite.rb"
23
+ code.target_file_name.should == "E:/dev/pattern/target/compositetask.rb"
24
24
  code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
25
25
  "leaf_name"=>"AddDryIngredientsTask",
26
26
  "composite_object_name"=>"MakeBatterTask",
27
27
  "operations"=>" def execute\n \t\n end\n def test\n \t\n end\n"
28
28
  }
29
29
  code = @compositecode.codes[2]
30
- code.template_file_name.should == "E:/dev/easypattern/templates/ruby.composite/leaf.rb"
31
- code.target_file_name.should == "E:/dev/easypattern/target/adddryingredientstask.rb"
30
+ code.template_file_name.should == "E:/dev/pattern/templates/ruby.composite/leaf.rb"
31
+ code.target_file_name.should == "E:/dev/pattern/target/adddryingredientstask.rb"
32
32
  code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
33
33
  "leaf_name"=>"AddDryIngredientsTask",
34
34
  "composite_object_name"=>"MakeBatterTask",
35
35
  "operations"=>" def execute\n \t\n end\n def test\n \t\n end\n"
36
36
  }
37
37
  code = @compositecode.codes[3]
38
- code.template_file_name.should == "E:/dev/easypattern/templates/ruby.composite/leaf.rb"
39
- code.target_file_name.should == "E:/dev/easypattern/target/mixtask.rb"
38
+ code.template_file_name.should == "E:/dev/pattern/templates/ruby.composite/leaf.rb"
39
+ code.target_file_name.should == "E:/dev/pattern/target/mixtask.rb"
40
40
  code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
41
41
  "leaf_name"=>"MixTask",
42
42
  "composite_object_name"=>"MakeBatterTask",
43
43
  "operations"=>" def execute\n \t\n end\n def test\n \t\n end\n"
44
44
  }
45
45
  code = @compositecode.codes[4]
46
- code.template_file_name.should == "E:/dev/easypattern/templates/ruby.composite/compositeobject.rb"
47
- code.target_file_name.should == "E:/dev/easypattern/target/makebattertask.rb"
46
+ code.template_file_name.should == "E:/dev/pattern/templates/ruby.composite/compositeobject.rb"
47
+ code.target_file_name.should == "E:/dev/pattern/target/makebattertask.rb"
48
48
  code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
49
49
  "leaf_name"=>"AddDryIngredientsTask",
50
50
  "composite_object_name"=>"MakeBatterTask",
@@ -52,37 +52,37 @@ describe CompositeCode do
52
52
  }
53
53
  end
54
54
  it "2. default params should return base_name and default_classes " do
55
- params = "ruby.composite Task -d E:/dev/easypattern/target".split(" ")
55
+ params = "ruby.composite Task -d E:/dev/pattern/target".split(" ")
56
56
  @compositecode = CompositeCode.new(Command.new(params))
57
57
  @compositecode.load_readme
58
58
  @compositecode.classes_to_codes.length.should == 4
59
59
  code = @compositecode.codes[0]
60
- code.template_file_name.should == "E:/dev/easypattern/templates/ruby.composite/component.rb"
61
- code.target_file_name.should == "E:/dev/easypattern/target/task.rb"
60
+ code.template_file_name.should == "E:/dev/pattern/templates/ruby.composite/component.rb"
61
+ code.target_file_name.should == "E:/dev/pattern/target/task.rb"
62
62
  code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
63
63
  "leaf_name"=>"LeafTask",
64
64
  "composite_object_name"=>"CompositeObjectTask",
65
65
  "operations"=>""
66
66
  }
67
67
  code = @compositecode.codes[1]
68
- code.template_file_name.should == "E:/dev/easypattern/templates/ruby.composite/composite.rb"
69
- code.target_file_name.should == "E:/dev/easypattern/target/compositetask.rb"
68
+ code.template_file_name.should == "E:/dev/pattern/templates/ruby.composite/composite.rb"
69
+ code.target_file_name.should == "E:/dev/pattern/target/compositetask.rb"
70
70
  code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
71
71
  "leaf_name"=>"LeafTask",
72
72
  "composite_object_name"=>"CompositeObjectTask",
73
73
  "operations"=>""
74
74
  }
75
75
  code = @compositecode.codes[2]
76
- code.template_file_name.should == "E:/dev/easypattern/templates/ruby.composite/leaf.rb"
77
- code.target_file_name.should == "E:/dev/easypattern/target/leaftask.rb"
76
+ code.template_file_name.should == "E:/dev/pattern/templates/ruby.composite/leaf.rb"
77
+ code.target_file_name.should == "E:/dev/pattern/target/leaftask.rb"
78
78
  code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
79
79
  "leaf_name"=>"LeafTask",
80
80
  "composite_object_name"=>"CompositeObjectTask",
81
81
  "operations"=>""
82
82
  }
83
83
  code = @compositecode.codes[3]
84
- code.template_file_name.should == "E:/dev/easypattern/templates/ruby.composite/compositeobject.rb"
85
- code.target_file_name.should == "E:/dev/easypattern/target/compositeobjecttask.rb"
84
+ code.template_file_name.should == "E:/dev/pattern/templates/ruby.composite/compositeobject.rb"
85
+ code.target_file_name.should == "E:/dev/pattern/target/compositeobjecttask.rb"
86
86
  code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
87
87
  "leaf_name"=>"LeafTask",
88
88
  "composite_object_name"=>"CompositeObjectTask",
@@ -0,0 +1,28 @@
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
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pattern
3
3
  version: !ruby/object:Gem::Version
4
- hash: 57
4
+ hash: 63
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 1
10
- version: 0.9.1
9
+ - 2
10
+ version: 0.9.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - weizhao
@@ -31,11 +31,14 @@ files:
31
31
  - lib/code.rb
32
32
  - lib/command.rb
33
33
  - lib/compositecode.rb
34
+ - lib/configuration.rb
34
35
  - lib/patterncode.rb
35
36
  - lib/version.rb
36
37
  - bin/pattern
37
38
  - LICENSE
38
39
  - pattern-0.9.0.gem
40
+ - pattern-0.9.1.gem
41
+ - pattern-0.9.2.gem
39
42
  - pattern.gemspec
40
43
  - Rakefile
41
44
  - README
@@ -43,6 +46,7 @@ files:
43
46
  - test/code_spec.rb
44
47
  - test/command_spec.rb
45
48
  - test/compositecode_spec.rb
49
+ - test/configuration_spec.rb
46
50
  - test/patterncode_spec.rb
47
51
  - templates/ruby.composite/component.rb
48
52
  - templates/ruby.composite/composite.rb
@@ -92,4 +96,5 @@ test_files:
92
96
  - test/code_spec.rb
93
97
  - test/command_spec.rb
94
98
  - test/compositecode_spec.rb
99
+ - test/configuration_spec.rb
95
100
  - test/patterncode_spec.rb