gator 0.0.4.pre → 0.0.5.pre

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/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile CHANGED
@@ -8,7 +8,7 @@ gem "thor", "~>0.14.6"
8
8
  # Add dependencies to develop your gem here.
9
9
  # Include everything needed to run rake, tests, features, etc.
10
10
  group :development do
11
- gem "shoulda", ">= 0"
11
+ gem "rspec", "~> 2.3.0"
12
12
  gem "bundler", "~> 1.0.0"
13
13
  gem "jeweler", "~> 1.6.2"
14
14
  gem "rcov", ">= 0"
data/Rakefile CHANGED
@@ -25,22 +25,19 @@ Jeweler::Tasks.new do |gem|
25
25
  end
26
26
  Jeweler::RubygemsDotOrgTasks.new
27
27
 
28
- require 'rake/testtask'
29
- Rake::TestTask.new(:test) do |test|
30
- test.libs << 'lib' << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
32
  end
34
33
 
35
- require 'rcov/rcovtask'
36
- Rcov::RcovTask.new do |test|
37
- test.libs << 'test'
38
- test.pattern = 'test/**/test_*.rb'
39
- test.verbose = true
40
- test.rcov_opts << '--exclude "gems/*"'
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
41
37
  end
42
38
 
43
- task :default => :test
39
+ task :test => :spec
40
+ task :default => :spec
44
41
 
45
42
  require 'rake/rdoctask'
46
43
  Rake::RDocTask.new do |rdoc|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4.pre
1
+ 0.0.5.pre
data/gator.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gator}
8
- s.version = "0.0.4.pre"
8
+ s.version = "0.0.5.pre"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dominic Graefen"]
12
- s.date = %q{2011-07-01}
12
+ s.date = %q{2011-07-03}
13
13
  s.default_executable = %q{gator}
14
14
  s.description = %q{gator - the friendly code-generator}
15
15
  s.email = %q{dominic.graefen@gmail.com}
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  ]
21
21
  s.files = [
22
22
  ".document",
23
+ ".rspec",
23
24
  "Gemfile",
24
25
  "LICENSE.txt",
25
26
  "README.rdoc",
@@ -32,15 +33,22 @@ Gem::Specification.new do |s|
32
33
  "lib/core/cli/application.rb",
33
34
  "lib/core/cli/shell.rb",
34
35
  "lib/core/command.rb",
36
+ "lib/core/command/command.rb",
35
37
  "lib/core/configuration.rb",
36
38
  "lib/core/configuration/configuration.rb",
37
- "lib/core/plugin.rb",
38
39
  "lib/core/project.rb",
39
40
  "lib/core/project/layout.rb",
40
41
  "lib/core/project/project.rb",
42
+ "lib/default.rb",
43
+ "lib/default/commands/generator_command.rb",
44
+ "lib/default/commands/new_command.rb",
45
+ "lib/default/commands/new_template/.gator/project.rb.tt",
46
+ "lib/default/generators/AS3ClassTemplate.as.tt",
47
+ "lib/default/generators/as3_class_generator.rb",
41
48
  "lib/gator.rb",
42
- "test/helper.rb",
43
- "test/test_gator.rb"
49
+ "spec/core/command/command_spec.rb",
50
+ "spec/core/project/project_spec.rb",
51
+ "spec/spec_helper.rb"
44
52
  ]
45
53
  s.homepage = %q{http://github.com/devboy/gator}
46
54
  s.licenses = ["MIT"]
@@ -53,20 +61,20 @@ Gem::Specification.new do |s|
53
61
 
54
62
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
63
  s.add_runtime_dependency(%q<thor>, ["~> 0.14.6"])
56
- s.add_development_dependency(%q<shoulda>, [">= 0"])
64
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
57
65
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
58
66
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
59
67
  s.add_development_dependency(%q<rcov>, [">= 0"])
60
68
  else
61
69
  s.add_dependency(%q<thor>, ["~> 0.14.6"])
62
- s.add_dependency(%q<shoulda>, [">= 0"])
70
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
63
71
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
72
  s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
65
73
  s.add_dependency(%q<rcov>, [">= 0"])
66
74
  end
67
75
  else
68
76
  s.add_dependency(%q<thor>, ["~> 0.14.6"])
69
- s.add_dependency(%q<shoulda>, [">= 0"])
77
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
70
78
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
71
79
  s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
72
80
  s.add_dependency(%q<rcov>, [">= 0"])
data/lib/core.rb CHANGED
@@ -1,5 +1,4 @@
1
- require File.dirname(__FILE__) + '/core/cli'
2
1
  require File.dirname(__FILE__) + '/core/command'
3
- require File.dirname(__FILE__) + '/core/plugin'
4
2
  require File.dirname(__FILE__) + '/core/configuration'
5
- require File.dirname(__FILE__) + '/core/project'
3
+ require File.dirname(__FILE__) + '/core/project'
4
+ require File.dirname(__FILE__) + '/core/cli'
@@ -1,49 +1,40 @@
1
- module Gator
2
-
3
- class Application
1
+ require File.dirname(__FILE__) + '/../../../lib/core/project'
2
+ require File.dirname(__FILE__) + '/../../../lib/core/configuration'
4
3
 
5
- def initialize
6
- self
4
+ module Gator
5
+ def self.set_argv(args)
6
+ ARGV.length.times do |i|
7
+ ARGV.delete_at i
7
8
  end
8
-
9
- def execute( args )
10
- configuration.load_configuration
9
+ args.length.times do |i|
10
+ ARGV[i] = args[i]
11
11
  end
12
+ end
12
13
 
13
- def configuration
14
- @configuration ||= Configuration.new
15
- end
14
+ module CLI
15
+ class Application
16
16
 
17
- def project
18
- @project
19
- end
17
+ def initialize
18
+ self
19
+ end
20
20
 
21
- def project=( proj )
22
- @project= proj
23
- end
21
+ def execute(args)
22
+ raise "No command specified." if args.empty?
23
+ command = args.shift
24
+ raise "Command: \"#{command}\" could not be found." unless Gator::Command.has?(command)
25
+ args << "--help" if args.empty?
26
+ Gator::Command.get(command).start args
27
+ end
24
28
 
25
- def shell
26
- @shell ||= Shell.new
27
- end
29
+ def shell
30
+ @shell ||= Shell.new
31
+ end
28
32
 
33
+ end
29
34
  end
30
-
31
35
  class << self
32
36
 
33
37
  attr_accessor :application
34
- attr_accessor :base_dir
35
-
36
- def configuration
37
- application.configuration
38
- end
39
-
40
- def project
41
- application.project
42
- end
43
-
44
- def project=(proj)
45
- application.project= proj
46
- end
47
38
 
48
39
  def shell
49
40
  application.shell
@@ -51,6 +42,5 @@ module Gator
51
42
 
52
43
  end
53
44
 
54
- self.application= Application.new
55
-
45
+ self.application= Gator::CLI::Application.new
56
46
  end
data/lib/core/command.rb CHANGED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + '/command/command'
@@ -0,0 +1,50 @@
1
+ module Gator
2
+ module Command
3
+
4
+ class << self
5
+
6
+ def add(command)
7
+ unless will_collide? command
8
+ commands.push(command)
9
+ return true
10
+ end
11
+ false
12
+ end
13
+
14
+ def remove(command)
15
+ commands.delete(command) != nil?
16
+ end
17
+
18
+ def has?(name_or_alias)
19
+ commands.any? { |command| command.command_name == name_or_alias || command.command_alias == name_or_alias }
20
+ end
21
+
22
+ def get(name_or_alias)
23
+ commands.detect { |command| command.command_name == name_or_alias || command.command_alias == name_or_alias }
24
+ end
25
+
26
+ protected
27
+
28
+ def commands
29
+ @commands ||= []
30
+ end
31
+
32
+ def will_collide?(command)
33
+ has?(command.command_name) || has?(command.command_alias)
34
+ end
35
+
36
+ end
37
+
38
+ class Base < Thor::Group
39
+
40
+ class << self
41
+ attr_reader :command_name, :command_alias
42
+
43
+ def specify( command_name, command_alias )
44
+ @command_name, @command_alias = command_name, command_alias
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -1,78 +1,60 @@
1
1
  module Gator
2
- class Configuration
2
+ module Configuration
3
3
 
4
- def initialize
5
- @values = {}
6
- self
7
- end
4
+ class Config
8
5
 
9
- def load_configuration
10
- load_global_configuration
11
- load_project_configuration
12
- end
6
+ attr_reader :options
13
7
 
14
- def method_missing( sym, *args )
15
- if sym.to_s.end_with? "="
16
- @values[sym.to_s.gsub("=","")] = args.first unless args.empty?
17
- else
18
- @values[sym.to_s]
8
+ def initialize
9
+ @options = {}
10
+ @loaded = false
11
+ self
19
12
  end
20
- end
21
13
 
22
- protected
14
+ def loaded
15
+ @loaded
16
+ end
23
17
 
24
- def load_project_configuration
25
- config_file = File.find_file_upwards("gator_config.rb") || File.join( ".gator","gator_config.rb")
26
- ConfigurationGenerator.new.create_configuration config_file unless File.exists? config_file
27
- Gator.base_dir = File.expand_path( File.dirname( File.dirname( config_file ) ) )
28
- load config_file
29
- end
18
+ def load_config
19
+ config_file = File.join(File.expand_path("~"), ".gator", "configuration.rb")
20
+ ConfigurationGenerator.new.create_configuration config_file unless File.exists? config_file
21
+ @loaded = true
22
+ load config_file
23
+ end
30
24
 
31
- def load_global_configuration
32
- config_file = File.join( File.expand_path("~"),".gator","gator_config.rb")
33
- ConfigurationGenerator.new.create_configuration config_file, true unless File.exists? config_file
34
- load config_file
35
25
  end
36
26
 
37
- end
38
-
39
- #TODO: Refactor into gator default plugin
40
- class ConfigurationGenerator < Thor
41
- include Thor::Actions
27
+ class << self
28
+ attr_accessor :config
29
+ end
30
+ self.config = Config.new
42
31
 
43
- no_tasks {
32
+ def configuration
33
+ config = Gator::Configuration.config
34
+ config.load_config unless config.loaded
35
+ config
36
+ end
44
37
 
45
- def create_configuration( config_file, global=false )
46
- Gator.shell.say "#{global ? "Global " : "Project "}configuration file not found in: #{config_file}!", :red
47
- Gator.shell.say "This is not a problem. Let's create one!", :green
48
- create_file config_file do
49
- render = ""
50
- render += "#This file has been generated by gator and wants to be edited by you!\n"
51
- if global
52
- render += "Gator.configuration.author=\"#{Gator.shell.ask "Author:"}\"\n"
53
- else
54
- render += "Gator.project = Gator::Project.new \"#{Gator.shell.ask "Project name:"}\"\n"
38
+ #TODO: Refactor into gator default plugin
39
+ class ConfigurationGenerator < Thor
40
+ include Thor::Actions
41
+
42
+ no_tasks {
43
+
44
+ def create_configuration(config_file)
45
+ Gator.shell.say "Configuration file not found at: #{config_file}!", :red
46
+ Gator.shell.say ""
47
+ Gator.shell.say "Let's create one!", :green
48
+ create_file config_file do
49
+ render = ""
50
+ render += "#This file has been generated by gator and wants to be edited by you!\n"
51
+ render += "configuration.options[:author] = \"#{Gator.shell.ask "\nAuthor:"}\"\n"
52
+ render
53
+ end
55
54
  end
56
- render
57
- end
58
- end
59
-
60
- }
61
55
 
62
- end
63
-
64
- end
56
+ }
65
57
 
66
- class File
67
- def self.find_file_upwards( file )
68
- original_dir = here = Dir.pwd
69
- while ! (File.file?(File.join(here,file)))
70
- Dir.chdir("..")
71
- return nil if Dir.pwd == here
72
- here = Dir.pwd
73
- end
74
- File.join(here,file)
75
- ensure
76
- Dir.chdir(original_dir)
77
58
  end
59
+ end
78
60
  end
@@ -1,89 +1,91 @@
1
1
  module Gator
2
- # THIS CLASS IS STOLEN FROM BUILDR
2
+ module Project
3
+ # THIS CLASS IS STOLEN FROM BUILDR
3
4
 
4
- # Symbolic mapping for directory layout. Used for both the default and custom layouts.
5
- #
6
- # For example, the default layout maps [:source, :main, :java] to 'src/main/java', and
7
- # [:target, :main, :classes] to 'target/classes'. You can use this to change the layout
8
- # of your projects.
9
- #
10
- # To map [:source, :main] into the 'sources' directory:
11
- # my_layout = Layout.new
12
- # my_layout[:source, :main] = 'sources'
13
- #
14
- # define 'foo', :layout=>my_layout do
15
- # ...
16
- # end
17
- #
18
- # To map [:source, :main, :java] to 'java/main':
19
- # class MainLast < Layout
20
- # def expand(*args)
21
- # if args[0..1] == [:source, :main]
22
- # super args[2], :main, *args[3,]
23
- # else
24
- # super
25
- # end
26
- # end
27
- # end
28
- #
29
- # define 'foo', :layout=>MainLast do
30
- # ...
31
- # end
32
- class Layout
5
+ # Symbolic mapping for directory layout. Used for both the default and custom layouts.
6
+ #
7
+ # For example, the default layout maps [:source, :main, :java] to 'src/main/java', and
8
+ # [:target, :main, :classes] to 'target/classes'. You can use this to change the layout
9
+ # of your projects.
10
+ #
11
+ # To map [:source, :main] into the 'sources' directory:
12
+ # my_layout = Layout.new_template
13
+ # my_layout[:source, :main] = 'sources'
14
+ #
15
+ # define 'foo', :layout=>my_layout do
16
+ # ...
17
+ # end
18
+ #
19
+ # To map [:source, :main, :java] to 'java/main':
20
+ # class MainLast < Layout
21
+ # def expand(*args)
22
+ # if args[0..1] == [:source, :main]
23
+ # super args[2], :main, *args[3,]
24
+ # else
25
+ # super
26
+ # end
27
+ # end
28
+ # end
29
+ #
30
+ # define 'foo', :layout=>MainLast do
31
+ # ...
32
+ # end
33
+ class Layout
33
34
 
34
- class << self
35
+ class << self
35
36
 
36
- # Default layout used by new projects.
37
- attr_accessor :default
37
+ # Default layout used by new_template projects.
38
+ attr_accessor :default
38
39
 
39
- end
40
+ end
40
41
 
41
- def initialize #:nodoc:
42
- @mapping = {}
43
- end
42
+ def initialize #:nodoc:
43
+ @mapping = {}
44
+ end
44
45
 
45
- # Expands list of symbols and path names into a full path, for example:
46
- # puts default.expand(:source, :main, :java)
47
- # => "src/main/java"
48
- def expand(*args)
49
- args = args.compact.reject { |s| s.to_s.empty? }.map(&:to_sym)
50
- return '' if args.empty?
51
- @mapping[args] ||= File.join(*[expand(*args[0..-2]), args.last.to_s].reject(&:empty?)) if args.size > 1
52
- return @mapping[args] || args.first.to_s
53
- end
46
+ # Expands list of symbols and path names into a full path, for example:
47
+ # puts default.expand(:source, :main, :java)
48
+ # => "src/main/java"
49
+ def expand(*args)
50
+ args = args.compact.reject { |s| s.to_s.empty? }.map(&:to_sym)
51
+ return '' if args.empty?
52
+ @mapping[args] ||= File.join(*[expand(*args[0..-2]), args.last.to_s].reject(&:empty?)) if args.size > 1
53
+ return @mapping[args] || args.first.to_s
54
+ end
54
55
 
55
- # Resolves a list of symbols into a path.
56
- def [](*args)
57
- @mapping[args.map(&:to_sym)]
58
- end
56
+ # Resolves a list of symbols into a path.
57
+ def [](*args)
58
+ @mapping[args.map(&:to_sym)]
59
+ end
59
60
 
60
- # Specifies the path resolved from a list of symbols.
61
- def []=(*args)
62
- @mapping[args[0...-1].map(&:to_sym)] = args.last
63
- end
61
+ # Specifies the path resolved from a list of symbols.
62
+ def []=(*args)
63
+ @mapping[args[0...-1].map(&:to_sym)] = args.last
64
+ end
64
65
 
65
- def initialize_copy(copy)
66
- copy.instance_variable_set :@mapping, @mapping.clone
67
- end
66
+ def initialize_copy(copy)
67
+ copy.instance_variable_set :@mapping, @mapping.clone
68
+ end
68
69
 
69
- # Default layout has the following properties:
70
- # * :source maps to the 'src' directory.
71
- # * Anything under :source maps verbatim (e.g. :source, :main becomes 'src/main')
72
- # * :target maps to the 'target' directory.
73
- # * :target, :main maps to the 'target' directory as well.
74
- # * Anything under :target, :main maps verbatim (e.g. :target, :main, :classes becomes 'target/classes')
75
- # * Anything else under :target also maps verbatim (e.g. :target, :test becomes 'target/test')
76
- class Default < Layout
70
+ # Default layout has the following properties:
71
+ # * :source maps to the 'src' directory.
72
+ # * Anything under :source maps verbatim (e.g. :source, :main becomes 'src/main')
73
+ # * :target maps to the 'target' directory.
74
+ # * :target, :main maps to the 'target' directory as well.
75
+ # * Anything under :target, :main maps verbatim (e.g. :target, :main, :classes becomes 'target/classes')
76
+ # * Anything else under :target also maps verbatim (e.g. :target, :command becomes 'target/command')
77
+ class Default < Layout
77
78
 
78
- def initialize
79
- super
80
- self[:source] = 'src'
81
- self[:target, :main] = 'target'
82
- end
79
+ def initialize
80
+ super
81
+ self[:source] = 'src'
82
+ self[:target, :main] = 'target'
83
+ end
83
84
 
84
- end
85
+ end
85
86
 
86
- self.default = Default.new
87
+ self.default = Default.new
87
88
 
89
+ end
88
90
  end
89
91
  end
@@ -1,24 +1,135 @@
1
1
  module Gator
2
- class Project
2
+ module Project
3
3
 
4
- attr_reader :name
4
+ class Base
5
+
6
+ attr_reader :name
7
+
8
+ def initialize(name)
9
+ @name = name
10
+ @layout = Layout.default
11
+ end
12
+
13
+ def path(*args)
14
+ File.join(Gator::Project.project_dir, layout.expand(*args))
15
+ end
16
+
17
+ def layout
18
+ @layout
19
+ end
20
+
21
+ def layout=(layout)
22
+ @layout= layout
23
+ end
5
24
 
6
- def initialize( name )
7
- @name = name
8
- @layout = Layout.default
9
25
  end
10
26
 
11
- def path(*args)
12
- File.join( Gator.base_dir, layout.expand(*args) )
27
+ class << self
28
+
29
+ def project=(project)
30
+ @project = project
31
+ end
32
+
33
+ def project
34
+ @project
35
+ end
36
+
37
+ def is_project_directory(path= Dir.getwd)
38
+ File.exists? File.join(path, relative_project_file)
39
+ end
40
+
41
+ def is_project_subdirectory(path= Dir.getwd)
42
+ !get_project_directory_of_subdirectory(path).nil?
43
+ end
44
+
45
+ def get_project_directory_of_subdirectory(path= Dir.getwd)
46
+ original_dir = Dir.getwd
47
+ here = path
48
+ Dir.chdir(here)
49
+ while !(is_project_directory(Dir.getwd))
50
+ Dir.chdir("..")
51
+ return nil if Dir.pwd == here
52
+ here = Dir.pwd
53
+ end
54
+ return here
55
+ ensure
56
+ Dir.chdir(original_dir)
57
+ end
58
+
59
+ def project_file(path= Dir.getwd)
60
+ if is_project_directory(path)
61
+ File.join(path, relative_project_file)
62
+ elsif is_project_subdirectory(path)
63
+ File.join(get_project_directory_of_subdirectory, relative_project_file)
64
+ else
65
+ nil
66
+ end
67
+ end
68
+
69
+ def project_dir(path= Dir.getwd)
70
+ File.dirname( File.dirname( project_file(path) ))
71
+ end
72
+
73
+ private
74
+
75
+ def relative_project_file
76
+ File.join(".gator", "project.rb")
77
+ end
13
78
  end
14
79
 
15
- def layout
16
- @layout
80
+ def project(project=nil)
81
+ Gator::Project.project= project unless project.nil?
82
+ load_project unless Gator::Project.project
83
+ if Gator::Project.project.nil?
84
+ Gator.shell.say "Project is not defined!\nMake sure to define a project in #{Gator::Project.project_file}",:red
85
+ raise "ProjectNotDefined"
86
+ end
87
+ Gator::Project.project
17
88
  end
18
89
 
19
- def layout=( l )
20
- @layout = l
90
+ # def define_project(project)
91
+ # Gator::Project.project= project
92
+ # end
93
+
94
+ def load_project
95
+ pfile = Gator::Project.project_file
96
+ if pfile.nil?
97
+ Gator.shell.say "This is not a project directory!\nPlease create a gator project first.", :red
98
+ raise "NotInsideProjectDirectory"
99
+ else
100
+ load pfile
101
+ end
21
102
  end
22
103
 
104
+ # def define_project( project )
105
+ # @project = project
106
+ # end
107
+
108
+ # def project
109
+ # p "project"
110
+ # load_project unless @project
111
+ # p " @project=#{@project}"
112
+ # if @project.nil?
113
+ # Gator.shell.say "Project is not defined!\nMake sure to define a project in #{Gator::Project.project_file}",:red
114
+ # raise "ProjectNotDefined"
115
+ # end
116
+ # p " @project=#{@project}"
117
+ # @project
118
+ # end
119
+
120
+ # private
121
+
122
+ # def load_project
123
+ # load File.join(".gator","project.rb")
124
+ # p 'load_project'
125
+ # pfile = Gator::Project.project_file
126
+ # if pfile.nil?
127
+ # Gator.shell.say "This is not a project directory!\nPlease create a gator project first.", :red
128
+ # raise "NotInsideProjectDirectory"
129
+ # else
130
+ # load pfile
131
+ # end
132
+ # end
133
+
23
134
  end
24
135
  end
data/lib/default.rb ADDED
@@ -0,0 +1,3 @@
1
+ require File.dirname(__FILE__) + '/default/commands/new_command'
2
+ require File.dirname(__FILE__) + '/default/commands/generator_command'
3
+ require File.dirname(__FILE__) + '/default/generators/as3_class_generator'
@@ -0,0 +1,74 @@
1
+ module Gator
2
+ module Generators
3
+ class << self
4
+
5
+ def add(generator)
6
+ unless will_collide? generator
7
+ generators.push(generator)
8
+ return true
9
+ end
10
+ false
11
+ end
12
+
13
+ def remove(generator)
14
+ generators.delete(generator) != nil?
15
+ end
16
+
17
+ def has?(name_or_alias)
18
+ generators.any? { |generator| generator.generator_name == name_or_alias || generator.generator_alias == name_or_alias }
19
+ end
20
+
21
+ def get(name_or_alias)
22
+ generators.detect { |generator| generator.generator_name == name_or_alias || generator.generator_alias == name_or_alias }
23
+ end
24
+
25
+ protected
26
+
27
+ def generators
28
+ @generators ||= []
29
+ end
30
+
31
+ def will_collide?(generator)
32
+ has?(generator.generator_name) || has?(generator.generator_alias)
33
+ end
34
+
35
+ end
36
+
37
+ class Base < Thor::Group
38
+
39
+ class << self
40
+ attr_reader :generator_name, :generator_alias
41
+
42
+ def specify( generator_name, generator_alias )
43
+ @generator_name, @generator_alias = generator_name, generator_alias
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ class GeneratorCommand < Gator::Command::Base
50
+ include Thor::Actions
51
+
52
+ specify "generate", "g"
53
+
54
+ def self.source_root
55
+ File.dirname(__FILE__)
56
+ end
57
+
58
+ argument :name, :type => :string, :desc => "The name of the generator."
59
+ # argument :args, :type => :array
60
+ desc "Finds and executes a generator."
61
+
62
+ def find_and_execute
63
+ raise "Generator: \"#{name}\" could not be found." unless Gator::Generators.has?(name)
64
+ ARGV.shift
65
+ ARGV << "--help" if ARGV.empty?
66
+
67
+ Gator::Generators.get(name).start
68
+ end
69
+
70
+ end
71
+
72
+ Gator::Command.add GeneratorCommand
73
+ end
74
+ end
@@ -0,0 +1,31 @@
1
+ require "thor/actions"
2
+
3
+ module Gator
4
+ module Default
5
+ module Commands
6
+
7
+ class NewCommand < Gator::Command::Base
8
+ include Thor::Actions
9
+
10
+ specify "new", "n"
11
+
12
+ def self.source_root
13
+ File.dirname(__FILE__)
14
+ end
15
+
16
+ argument :name, :type => :string, :desc => "The name of the project."
17
+ desc "Creates an empty gator project."
18
+
19
+ def create
20
+ directory "new_template", name
21
+ # we need to call directories starting with a . seperately
22
+ directory "new_template/.gator", "#{name}/.gator"
23
+ end
24
+
25
+ end
26
+
27
+ Gator::Command.add NewCommand
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1 @@
1
+ project Gator::Project::Base.new "<%= name %>"
@@ -0,0 +1,9 @@
1
+ package <%= package_name %>
2
+ {
3
+ public class <%= class_name %>
4
+ {
5
+ public function <%= class_name %>()
6
+ {
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,27 @@
1
+ require "thor/actions"
2
+ module Gator
3
+ module AS3
4
+ class AS3ClassGenerator < Gator::Generators::Base
5
+ include Gator::Project, Thor::Actions
6
+
7
+ specify "as3class", "as3c"
8
+
9
+ argument :package_name, :type => :string, :desc => "The name of the package."
10
+ argument :class_name, :type => :string, :desc => "The name of the class."
11
+ desc "Creates an ActionScript3 Class"
12
+
13
+ def self.source_root
14
+ File.dirname(__FILE__)
15
+ end
16
+
17
+ def create_class
18
+ src = project.path(:source, :main, :as3)
19
+ template "AS3ClassTemplate.as.tt", File.join(src, "#{class_name}.as" )
20
+ end
21
+
22
+ end
23
+
24
+ Gator::Generators.add AS3ClassGenerator
25
+ end
26
+ end
27
+
data/lib/gator.rb CHANGED
@@ -1,2 +1,13 @@
1
1
  require "thor"
2
- require File.dirname(__FILE__) + '/core'
2
+ require "thor/group"
3
+ require File.dirname(__FILE__) + '/core'
4
+ require File.dirname(__FILE__) + '/default'
5
+
6
+ # This makes gator module functions locally available in config & project files
7
+ module Gator
8
+ include Gator::Project
9
+ include Gator::Configuration
10
+ end
11
+ class << self;
12
+ include Gator
13
+ end
@@ -0,0 +1,65 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ class TestCommandA < Gator::Command::Base
4
+ specify "command_a", "a"
5
+ end
6
+
7
+ class TestCommandB < Gator::Command::Base
8
+ specify "command_b", "b"
9
+ end
10
+
11
+ describe Gator::Command::Base do
12
+
13
+ it "has the correct attributes" do
14
+ test_command_a = TestCommandA
15
+ test_command_a.command_name.should == "command_a"
16
+ test_command_a.command_alias.should == "a"
17
+ end
18
+
19
+ end
20
+
21
+ describe Gator::Command do
22
+
23
+ before(:all) do
24
+ @test_command_a = TestCommandA
25
+ @test_command_b = TestCommandB
26
+ end
27
+
28
+ after(:all) do
29
+ @test_command_a = nil
30
+ @test_command_b = nil
31
+ end
32
+
33
+ it "should add a command" do
34
+ Gator::Command.add(@test_command_a).should == true
35
+ end
36
+
37
+ it "should not add the same command again" do
38
+ Gator::Command.add(@test_command_a).should == false
39
+ end
40
+
41
+ it "should add another command though" do
42
+ Gator::Command.add(@test_command_b).should == true
43
+ end
44
+
45
+ it "should have a command with name" do
46
+ Gator::Command.has?(@test_command_a.command_name).should == true
47
+ end
48
+
49
+ it "should have a command with alias" do
50
+ Gator::Command.has?(@test_command_a.command_alias).should == true
51
+ end
52
+
53
+ it "should return instance of TestCommandA by name" do
54
+ Gator::Command.get(@test_command_a.command_name).should == @test_command_a
55
+ end
56
+
57
+ it "should return instance of TestCommandA by alias" do
58
+ Gator::Command.get(@test_command_a.command_alias).should == @test_command_a
59
+ end
60
+
61
+ it "should remove test_command_a" do
62
+ Gator::Command.remove(@test_command_a).should == true
63
+ end
64
+
65
+ end
@@ -0,0 +1,49 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ require "fileutils"
4
+
5
+ describe Gator::Project::Base do
6
+
7
+ it "has the correct attributes" do
8
+ test_project = Gator::Project::Base.new "test_project"
9
+ test_project.name.should == "test_project"
10
+ test_project.layout.should == Gator::Project::Layout.default
11
+ end
12
+
13
+ end
14
+
15
+ describe Gator::Project do
16
+
17
+ before(:all) do
18
+ @project_dir = File.expand_path("project_spec_directory_test")
19
+ FileUtils.mkdir_p File.join(@project_dir,".gator")
20
+ FileUtils.mkdir_p File.join(@project_dir,"sub")
21
+ File.open(File.join(@project_dir,".gator","project.rb"), 'w') {|f| f.write("-empty-") }
22
+ end
23
+
24
+ after(:all) do
25
+ FileUtils.rm_r @project_dir
26
+ @project_dir = nil
27
+ end
28
+
29
+ it "should detect being inside a project directory" do
30
+ Gator::Project.is_project_directory(@project_dir).should == true
31
+ end
32
+
33
+ it "should detect the correct project directory from within a project subdirectory" do
34
+ Gator::Project.get_project_directory_of_subdirectory(File.join(@project_dir,"sub")).should == @project_dir
35
+ end
36
+
37
+ it "should detect being inside a project subdirectory" do
38
+ Gator::Project.is_project_subdirectory(File.join(@project_dir,"sub")).should == true
39
+ end
40
+
41
+ it "should not detect being inside a project directory" do
42
+ Gator::Project.is_project_directory(File.join(@project_dir,"sub")).should == false
43
+ end
44
+
45
+ it "should not detect being inside a project subdirectory" do
46
+ Gator::Project.is_project_directory(File.expand_path("~")).should == false
47
+ end
48
+
49
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'gator'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata CHANGED
@@ -1,84 +1,83 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: gator
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5.pre
4
5
  prerelease: 6
5
- version: 0.0.4.pre
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Dominic Graefen
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-07-01 00:00:00 +02:00
12
+ date: 2011-07-03 00:00:00.000000000 +02:00
14
13
  default_executable: gator
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
17
16
  name: thor
18
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &2152279880 !ruby/object:Gem::Requirement
19
18
  none: false
20
- requirements:
19
+ requirements:
21
20
  - - ~>
22
- - !ruby/object:Gem::Version
21
+ - !ruby/object:Gem::Version
23
22
  version: 0.14.6
24
23
  type: :runtime
25
24
  prerelease: false
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: shoulda
29
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *2152279880
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &2152279400 !ruby/object:Gem::Requirement
30
29
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.0
35
34
  type: :development
36
35
  prerelease: false
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
36
+ version_requirements: *2152279400
37
+ - !ruby/object:Gem::Dependency
39
38
  name: bundler
40
- requirement: &id003 !ruby/object:Gem::Requirement
39
+ requirement: &2152278920 !ruby/object:Gem::Requirement
41
40
  none: false
42
- requirements:
41
+ requirements:
43
42
  - - ~>
44
- - !ruby/object:Gem::Version
43
+ - !ruby/object:Gem::Version
45
44
  version: 1.0.0
46
45
  type: :development
47
46
  prerelease: false
48
- version_requirements: *id003
49
- - !ruby/object:Gem::Dependency
47
+ version_requirements: *2152278920
48
+ - !ruby/object:Gem::Dependency
50
49
  name: jeweler
51
- requirement: &id004 !ruby/object:Gem::Requirement
50
+ requirement: &2152278440 !ruby/object:Gem::Requirement
52
51
  none: false
53
- requirements:
52
+ requirements:
54
53
  - - ~>
55
- - !ruby/object:Gem::Version
54
+ - !ruby/object:Gem::Version
56
55
  version: 1.6.2
57
56
  type: :development
58
57
  prerelease: false
59
- version_requirements: *id004
60
- - !ruby/object:Gem::Dependency
58
+ version_requirements: *2152278440
59
+ - !ruby/object:Gem::Dependency
61
60
  name: rcov
62
- requirement: &id005 !ruby/object:Gem::Requirement
61
+ requirement: &2152277960 !ruby/object:Gem::Requirement
63
62
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: "0"
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
68
67
  type: :development
69
68
  prerelease: false
70
- version_requirements: *id005
69
+ version_requirements: *2152277960
71
70
  description: gator - the friendly code-generator
72
71
  email: dominic.graefen@gmail.com
73
- executables:
72
+ executables:
74
73
  - gator
75
74
  extensions: []
76
-
77
- extra_rdoc_files:
75
+ extra_rdoc_files:
78
76
  - LICENSE.txt
79
77
  - README.rdoc
80
- files:
78
+ files:
81
79
  - .document
80
+ - .rspec
82
81
  - Gemfile
83
82
  - LICENSE.txt
84
83
  - README.rdoc
@@ -91,45 +90,49 @@ files:
91
90
  - lib/core/cli/application.rb
92
91
  - lib/core/cli/shell.rb
93
92
  - lib/core/command.rb
93
+ - lib/core/command/command.rb
94
94
  - lib/core/configuration.rb
95
95
  - lib/core/configuration/configuration.rb
96
- - lib/core/plugin.rb
97
96
  - lib/core/project.rb
98
97
  - lib/core/project/layout.rb
99
98
  - lib/core/project/project.rb
99
+ - lib/default.rb
100
+ - lib/default/commands/generator_command.rb
101
+ - lib/default/commands/new_command.rb
102
+ - lib/default/commands/new_template/.gator/project.rb.tt
103
+ - lib/default/generators/AS3ClassTemplate.as.tt
104
+ - lib/default/generators/as3_class_generator.rb
100
105
  - lib/gator.rb
101
- - test/helper.rb
102
- - test/test_gator.rb
106
+ - spec/core/command/command_spec.rb
107
+ - spec/core/project/project_spec.rb
108
+ - spec/spec_helper.rb
103
109
  has_rdoc: true
104
110
  homepage: http://github.com/devboy/gator
105
- licenses:
111
+ licenses:
106
112
  - MIT
107
113
  post_install_message:
108
114
  rdoc_options: []
109
-
110
- require_paths:
115
+ require_paths:
111
116
  - lib
112
- required_ruby_version: !ruby/object:Gem::Requirement
117
+ required_ruby_version: !ruby/object:Gem::Requirement
113
118
  none: false
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- hash: 1652915193245958756
118
- segments:
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ segments:
119
124
  - 0
120
- version: "0"
121
- required_rubygems_version: !ruby/object:Gem::Requirement
125
+ hash: -1055460137328960233
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
127
  none: false
123
- requirements:
124
- - - ">"
125
- - !ruby/object:Gem::Version
128
+ requirements:
129
+ - - ! '>'
130
+ - !ruby/object:Gem::Version
126
131
  version: 1.3.1
127
132
  requirements: []
128
-
129
133
  rubyforge_project:
130
134
  rubygems_version: 1.6.2
131
135
  signing_key:
132
136
  specification_version: 3
133
137
  summary: gator - the friendly code-generator
134
138
  test_files: []
135
-
data/lib/core/plugin.rb DELETED
File without changes
data/test/helper.rb DELETED
@@ -1,18 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'test/unit'
11
- require 'shoulda'
12
-
13
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
- $LOAD_PATH.unshift(File.dirname(__FILE__))
15
- require 'gator'
16
-
17
- class Test::Unit::TestCase
18
- end
data/test/test_gator.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestGator < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end