pattern 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
data/DOCS/todolist.txt CHANGED
@@ -1,3 +1,11 @@
1
+
2
+ 2011-01-10
3
+ 1. refactoring the code OK
4
+ 2. Adding 2or3 template of ruby pattern code.
5
+ 3. when no parameter,get help OK
6
+ 4. lower_case replace OK
7
+ before
8
+
1
9
  1. 制作为rubygem
2
10
  1.1. 添加可执行文件 OK
3
11
  1.2. 添加环境路径 OK
@@ -12,6 +20,6 @@
12
20
  6.3. 删除一个
13
21
  7. 添加新的templates
14
22
  8. 列出可用的template OK
15
- 9. help功能
23
+ 9. help功能 Ok
24
+
16
25
 
17
- 发现一个问题,如果我的问题不能按我的想法来排列,我先做下面的,再做上面的,我会很不舒服
data/README CHANGED
@@ -16,12 +16,23 @@ complex model (not support now.)
16
16
 
17
17
  simple model:
18
18
  * pattern ruby.composite Task -d target
19
- * pattern -t ruby.composite -d target -c Task;compositeTask;AddDryIngredientsTask,MixTask;MakeBatterTask -op execute
19
+ * pattern -t ruby.composite -d target -c Task;CompositeTask;AddDryIngredientsTask,MixTask,AddLiquidsTask;MakeBatterTask,MakeCakeTask -op get_time_required
20
20
  complex model(pattern_file):
21
21
 
22
22
  == Future
23
23
  Sharing pattern templates on website.
24
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
+
25
36
  == Author
26
37
 
27
38
  Copyright 2010 @ weizhao
data/bin/pattern CHANGED
@@ -1,28 +1,27 @@
1
1
  #!/usr/bin/env ruby
2
2
  current_dir = File.dirname(__FILE__)
3
3
 
4
- if %w(--version -v).include? ARGV.first
5
- require current_dir + '/../lib/version'
4
+ require current_dir + '/../lib/version'
5
+ puts "#{Pattern::HELP::WELLCOME}"
6
+ if %w(--version -v).include? ARGV.first
6
7
  puts "pattern #{Pattern::VERSION::STRING}"
7
8
  exit(0)
8
9
  end
10
+ require current_dir + '/../lib/configuration'
9
11
 
10
12
  if %w(--set -s).include? ARGV.first
11
- require current_dir + '/../lib/configuration'
12
13
  configuration = Configuration.new
13
14
  configuration.execute(ARGV)
14
15
  exit(0)
15
16
  end
16
17
 
17
18
  if %w(--list -l).include? ARGV.first
18
- require current_dir + '/../lib/configuration'
19
19
  configuration = Configuration.new
20
20
  configuration.list
21
21
  exit(0)
22
22
  end
23
23
 
24
- if %w(--help -h).include? ARGV.first
25
- require current_dir + '/../lib/version'
24
+ if (ARGV.empty? || (%w(--help -h).include? ARGV.first))
26
25
  puts Pattern::HELP::STRING
27
26
  exit(0)
28
27
  end
data/lib/command.rb CHANGED
@@ -1,8 +1,12 @@
1
1
  # commad for send parameter to CompositeCode
2
- require "pathname"
2
+ # PathCommon is in common.rb
3
+
4
+ require File.dirname(__FILE__)+'/common'
3
5
 
4
6
  class Command
7
+ include PathCommon
5
8
  attr_accessor :template_dir,:target_dir,:classes,:operations,:base_name
9
+
6
10
  def initialize(params)
7
11
  @params = params
8
12
  get_template_dir
@@ -11,10 +15,14 @@ class Command
11
15
  get_operations
12
16
  end
13
17
  def get_template_dir
14
- get_templates_dirs(get_template_dir_from_params).each do |dir|
18
+ template = get_param("-t") || @params[0]
19
+ get_templates(template).each do |dir|
15
20
  @template_dir = dir if File.directory?(dir)
16
21
  end
17
22
  end
23
+ def get_target_dir
24
+ @target_dir = absolute_path(get_param("-d") || ".")
25
+ end
18
26
  def get_classes
19
27
  classes = get_param("-c")
20
28
  if classes
@@ -27,25 +35,13 @@ class Command
27
35
  def get_operations
28
36
  @operations = parse_string( operations = get_param("-op") || " " )
29
37
  end
30
- def get_templates_dirs(template)
31
- File.open("#{File.dirname(__FILE__)}/../etc/templates_path.conf").readlines.collect do |line|
32
- line = absolute_path(File.join(line.chomp,template),File.dirname(__FILE__))
33
- end
34
- end
35
- def get_target_dir
36
- @target_dir = absolute_path(get_param("-d") || ".")
37
- end
38
- def get_template_dir_from_params
39
- return get_param("-t") || @params[0]
38
+
39
+ private
40
+ def get_templates(template)
41
+ get_path.collect { |dir| dir = join(dir,template) }
40
42
  end
41
43
  def get_param(option)
42
44
  index = @params.index(option)
43
45
  return index ? @params[index+1] : nil
44
46
  end
45
- def absolute_path(path,dir=Dir.pwd)
46
- Pathname.new(path).relative? ? File.expand_path(path,dir) : path
47
- end
48
- def parse_string(string)
49
- string.split(';').collect { |classes| classes.split(',') }
50
- end
51
47
  end
data/lib/common.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'pathname'
2
+
3
+ module PathCommon
4
+ PROJECT_DIR = "#{File.dirname(__FILE__)}/../"
5
+ CONFIG_FILE = "#{PROJECT_DIR}etc/templates_path.conf"
6
+
7
+ def absolute_path(path,dir=Dir.pwd)
8
+ Pathname.new(path).relative? ? File.expand_path(path,dir) : path
9
+ end
10
+ def parse_string(string)
11
+ string.split(';').collect { |classes| classes.split(',') }
12
+ end
13
+ def get_path
14
+ File.open(CONFIG_FILE).readlines.collect do |path|
15
+ path = absolute_path(path.chomp,File.dirname(__FILE__))
16
+ end
17
+ end
18
+ def join(path,file=".")
19
+ File.join(path,file)
20
+ end
21
+ end
data/lib/compositecode.rb CHANGED
@@ -39,6 +39,7 @@ class CompositeCode < Code
39
39
  template_classes.each do |class_name|
40
40
  replace_values = default_replace_values.clone
41
41
  replace_values["#{key}"] = class_name
42
+ replace_values["lc_#{key}"] = class_name.downcase
42
43
  replace_values["operations"] = ""
43
44
  operations.each do |operation|
44
45
  replace_values["operations"] << operations_template.gsub("#operation#",operation) unless operation == " "
@@ -57,6 +58,7 @@ class CompositeCode < Code
57
58
  default_replace_values = Hash.new
58
59
  @template_replace_keys.each do |key|
59
60
  default_replace_values["#{key}"] = @classes[x+=1][0]
61
+ default_replace_values["lc_#{key}"] = @classes[x][0].downcase
60
62
  end
61
63
  return default_replace_values
62
64
  end
data/lib/configuration.rb CHANGED
@@ -1,36 +1,25 @@
1
1
  # config templates_path
2
+ # class Config is using
2
3
 
3
- require 'pathname'
4
+ require File.dirname(__FILE__)+'/common'
4
5
 
5
6
  class Configuration
7
+ include PathCommon
8
+
6
9
  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
10
+ end
14
11
  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
12
+ File.open(CONFIG_FILE,"a") do |file|
13
+ path.each { |p| file.puts absolute_path(p) }
19
14
  end
20
- puts "Now you get templates path:"
21
- puts get_path
15
+ list_templates_path
22
16
  end
23
17
  def remove_path(path)
24
- puts "Now you remove templates path:"
25
- puts path
26
18
  path_set = get_path - path.collect { |p| p= absolute_path(p) }
27
- File.open(@config_file,"w") do |file|
28
- path_set.each do |p|
29
- file.puts p
30
- end
19
+ File.open(CONFIG_FILE,"w") do |file|
20
+ path_set.each { |p| file.puts p }
31
21
  end
32
- puts "Now you get templates path:"
33
- puts get_path
22
+ list_templates_path
34
23
  end
35
24
  def list
36
25
  list = []
@@ -47,11 +36,12 @@ class Configuration
47
36
  get_default if action == "default"
48
37
  end
49
38
  def get_default
50
- File.open(@config_file,"w") do |file|
39
+ File.open(CONFIG_FILE,"w") do |file|
51
40
  file.puts "../templates"
52
41
  end
53
42
  end
54
- def absolute_path(path,dir=Dir.pwd)
55
- Pathname.new(path).relative? ? File.expand_path(path,dir) : path
43
+ def list_templates_path
44
+ puts "\nNow you get templates path:"
45
+ puts get_path
56
46
  end
57
47
  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 = 3
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -25,5 +25,8 @@ module Pattern
25
25
  Further information:
26
26
  https://github.com/azhao1981/pattern
27
27
  EOF
28
+ WELLCOME = <<-EOF
29
+ Thanks for using pattern beta.You get idea or Question.Mailto:azhao.1981@gmail.com
30
+ EOF
28
31
  end
29
32
  end
data/pattern-0.9.3.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.3'
7
+ spec.version = '0.9.4'
8
8
  spec.executables << 'pattern'
9
9
  spec.has_rdoc = true
10
10
  spec.rdoc_options << '--title' << 'Pattern' <<
@@ -2,8 +2,10 @@
2
2
  #
3
3
 
4
4
  class #class_name#
5
- def initialize
6
-
5
+ attr_accessor :name,:parent
6
+ def initialize(name)
7
+ @name = name
8
+ @parent = nil
7
9
  end
8
10
  # TODO: operations
9
11
  #operations#
@@ -1,9 +1,31 @@
1
1
  # This is code of composite pattern . Generated by easypattern.
2
2
  #
3
+ require "#lc_class_name#"
3
4
 
4
- class #composite_name#
5
- def initialize
6
-
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
7
29
  end
8
30
  # TODO: operations
9
31
  #operations#
@@ -1,9 +1,12 @@
1
1
  # This is code of composite pattern . Generated by easypattern.
2
2
  #
3
+ require "#lc_composite_name#"
3
4
 
4
- class #composite_object_name#
5
+ class #composite_object_name# < #composite_name#
5
6
  def initialize
6
-
7
+ super("#lc_composite_object_name#")
8
+ #ToDo :add sub class
9
+ add_sub_task(#sub_class)
7
10
  end
8
11
  # TODO: operations
9
12
  #operations#
@@ -1,9 +1,10 @@
1
1
  # This is code of composite pattern . Generated by easypattern.
2
2
  #
3
+ require "#lc_class_name#"
3
4
 
4
- class #leaf_name#
5
+ class #leaf_name# < #class_name#
5
6
  def initialize
6
-
7
+ super("#leaf_name#")
7
8
  end
8
9
  # TODO: operations
9
10
  #operations#
data/test/code_spec.rb CHANGED
@@ -2,11 +2,13 @@
2
2
  # Copyright (c) 2010 weizhao
3
3
  #
4
4
  require File.dirname(__FILE__) + '/../lib/code'
5
+ require File.dirname(__FILE__) + '/../lib/common'
6
+ include PathCommon
5
7
 
6
8
  describe Code do
7
9
  before(:each) do
8
- template_file_name = "E:/dev/easypattern/templates/ruby.composite/component.rb"
9
- target_file_name = "E:/dev/easypattern/temp/task.rb"
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__))
10
12
  @target_file_name_test = target_file_name
11
13
  replace_values = {"class_name"=>"Task","operations"=>" def execute\n \t\n end\n"}
12
14
  @component_code = Code.new(template_file_name,target_file_name,replace_values)
data/test/command_spec.rb CHANGED
@@ -5,21 +5,14 @@ describe Command do
5
5
  params = "-t ruby.composite -c Task;compositeTask;AddDryIngredientsTask,MixTask;MakeBatterTask -op execute".split(" ")
6
6
  @command = Command.new(params)
7
7
  end
8
- it "1. get_template_dir_from_params should return 'ruby.composite' " do
9
- @command.get_template_dir_from_params.should == "ruby.composite"
10
- end
11
- it "2. get_templates_dirs should return ['../templates','../templates2']" do
12
- @command.get_templates_dirs(@command.get_template_dir_from_params)[0].should ==
13
- 'E:/dev/pattern/templates/ruby.composite'
14
- end
15
- it "3. Command.new should get right parameter form param" do
8
+ it "1. Command.new should get right parameter form param" do
16
9
  @command.template_dir.should == "E:/dev/pattern/templates/ruby.composite"
17
10
  @command.classes.should == [["Task"],["compositeTask"],
18
11
  ["AddDryIngredientsTask","MixTask"],["MakeBatterTask"]]
19
12
  @command.operations.should == [['execute']]
20
13
  @command.target_dir.should == "E:/dev/pattern"
21
14
  end
22
- it "4. absolute_path should return absolute path " do
15
+ it "2. absolute_path should return absolute path " do
23
16
  @command.absolute_path("../templates/ruby.composite","./bin/../lib").should == "E:/dev/pattern/templates/ruby.composite"
24
17
  end
25
18
  end
@@ -16,6 +16,9 @@ describe CompositeCode do
16
16
  code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
17
17
  "leaf_name"=>"AddDryIngredientsTask",
18
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",
19
22
  "operations"=>" def execute\n \t\n end\n def test\n \t\n end\n"
20
23
  }
21
24
  code = @compositecode.codes[1]
@@ -24,6 +27,9 @@ describe CompositeCode do
24
27
  code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
25
28
  "leaf_name"=>"AddDryIngredientsTask",
26
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",
27
33
  "operations"=>" def execute\n \t\n end\n def test\n \t\n end\n"
28
34
  }
29
35
  code = @compositecode.codes[2]
@@ -32,6 +38,9 @@ describe CompositeCode do
32
38
  code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
33
39
  "leaf_name"=>"AddDryIngredientsTask",
34
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",
35
44
  "operations"=>" def execute\n \t\n end\n def test\n \t\n end\n"
36
45
  }
37
46
  code = @compositecode.codes[3]
@@ -40,6 +49,9 @@ describe CompositeCode do
40
49
  code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
41
50
  "leaf_name"=>"MixTask",
42
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",
43
55
  "operations"=>" def execute\n \t\n end\n def test\n \t\n end\n"
44
56
  }
45
57
  code = @compositecode.codes[4]
@@ -48,6 +60,9 @@ describe CompositeCode do
48
60
  code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
49
61
  "leaf_name"=>"AddDryIngredientsTask",
50
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",
51
66
  "operations"=>" def execute\n \t\n end\n def test\n \t\n end\n"
52
67
  }
53
68
  end
@@ -62,6 +77,9 @@ describe CompositeCode do
62
77
  code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
63
78
  "leaf_name"=>"LeafTask",
64
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",
65
83
  "operations"=>""
66
84
  }
67
85
  code = @compositecode.codes[1]
@@ -70,6 +88,9 @@ describe CompositeCode do
70
88
  code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
71
89
  "leaf_name"=>"LeafTask",
72
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",
73
94
  "operations"=>""
74
95
  }
75
96
  code = @compositecode.codes[2]
@@ -78,6 +99,9 @@ describe CompositeCode do
78
99
  code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
79
100
  "leaf_name"=>"LeafTask",
80
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",
81
105
  "operations"=>""
82
106
  }
83
107
  code = @compositecode.codes[3]
@@ -86,6 +110,9 @@ describe CompositeCode do
86
110
  code.replace_values.should == {"class_name"=>"Task","composite_name"=>"CompositeTask",
87
111
  "leaf_name"=>"LeafTask",
88
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",
89
116
  "operations"=>""
90
117
  }
91
118
  end
@@ -2,11 +2,13 @@
2
2
  # Copyright (c) 2010 weizhao
3
3
  #
4
4
  require File.dirname(__FILE__) + '/../lib/patterncode'
5
+ require File.dirname(__FILE__) + '/../lib/common'
6
+ include PathCommon
5
7
 
6
8
  describe PatternCode do
7
9
  before(:each) do
8
- template_file_name = "E:/dev/easypattern/templates/ruby.composite/component.rb"
9
- target_file_name = "E:/dev/easypattern/temp/task.rb"
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__))
10
12
  @target_file_name_test = target_file_name
11
13
  replace_values = {"class_name"=>"Task","operations"=>" def execute\n \t\n end\n"}
12
14
  @component_code = PatternCode.new(template_file_name,target_file_name,replace_values)
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: 61
4
+ hash: 51
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 3
10
- version: 0.9.3
9
+ - 4
10
+ version: 0.9.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - weizhao
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-07 00:00:00 +08:00
18
+ date: 2011-01-12 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -30,6 +30,7 @@ extra_rdoc_files: []
30
30
  files:
31
31
  - lib/code.rb
32
32
  - lib/command.rb
33
+ - lib/common.rb
33
34
  - lib/compositecode.rb
34
35
  - lib/configuration.rb
35
36
  - lib/patterncode.rb
@@ -39,6 +40,7 @@ files:
39
40
  - pattern-0.9.0.gem
40
41
  - pattern-0.9.1.gem
41
42
  - pattern-0.9.2.gem
43
+ - pattern-0.9.3.gem
42
44
  - pattern.gemspec
43
45
  - Rakefile
44
46
  - README