gator 0.0.21.pre → 0.0.22.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/Gemfile +3 -1
  2. data/Rakefile +3 -6
  3. data/VERSION +1 -1
  4. data/bin/gator +2 -3
  5. data/gator.gemspec +52 -30
  6. data/lib/gator.rb +6 -8
  7. data/lib/gator/core.rb +19 -0
  8. data/lib/gator/core/application/application.rb +41 -0
  9. data/lib/gator/core/application/application_configuration.rb +11 -0
  10. data/lib/gator/core/command/act_as_command.rb +40 -0
  11. data/lib/gator/core/command/act_as_command_collection.rb +63 -0
  12. data/lib/gator/core/command/command.rb +20 -0
  13. data/lib/gator/{task.rb → core/command/task.rb} +1 -4
  14. data/lib/gator/core/configuration/act_as_configuration.rb +30 -0
  15. data/lib/gator/core/configuration/configuration.rb +5 -0
  16. data/lib/gator/core/io/paths.rb +21 -0
  17. data/lib/gator/core/io/project_file_locator.rb +28 -0
  18. data/lib/gator/core/io/ruby_file_loader.rb +21 -0
  19. data/lib/gator/core/io/sandbox.rb +9 -0
  20. data/lib/gator/{project.rb → core/project/layout.rb} +3 -44
  21. data/lib/gator/core/project/project.rb +21 -0
  22. data/lib/gator/plugins/generators.rb +5 -0
  23. data/lib/gator/{generators/generator.rb → plugins/generators/act_as_template_generator.rb} +1 -5
  24. data/lib/gator/{commands/generate.rb → plugins/generators/generate_command.rb} +1 -1
  25. data/lib/gator/plugins/generators/generator.rb +6 -0
  26. data/lib/gator/plugins/scaffolding.rb +4 -0
  27. data/lib/gator/plugins/scaffolding/scaffold_command.rb +62 -0
  28. data/lib/gator/plugins/scaffolding/scaffolding_file_utils.rb +58 -0
  29. data/rake/jeweler.rb +17 -0
  30. data/rake/jeweler_prerelease_tasks.rb +50 -0
  31. data/rake/pre_release_gemspec.rb +80 -0
  32. data/rake/pre_release_to_git.rb +59 -0
  33. data/spec/core/application/application_configuration_spec.rb +21 -0
  34. data/spec/core/application/application_spec.rb +15 -0
  35. data/spec/core/command/command_spec.rb +117 -0
  36. data/spec/core/command/task_spec.rb +95 -0
  37. data/spec/core/configuration/configuration_spec.rb +55 -0
  38. data/spec/core/io/paths_spec.rb +44 -0
  39. data/spec/core/io/sandbox_spec.rb +11 -0
  40. data/spec/core/project/layout_spec.rb +64 -0
  41. data/spec/core/project/project_spec.rb +51 -0
  42. data/spec/fixtures/empty_gator_project/gator.rb +4 -0
  43. data/spec/fixtures/no_gator_file/.empty_directory +0 -0
  44. data/spec/plugins/scaffolding/scaffold_command_spec.rb +75 -0
  45. data/spec/spec_helper.rb +14 -9
  46. metadata +65 -36
  47. data/lib/gator/command.rb +0 -109
  48. data/lib/gator/commands.rb +0 -5
  49. data/lib/gator/commands/project.rb +0 -87
  50. data/lib/gator/config.rb +0 -23
  51. data/lib/gator/generators.rb +0 -1
  52. data/lib/gator/runner.rb +0 -21
  53. data/lib/gator/util.rb +0 -91
  54. data/spec/command_spec.rb +0 -84
  55. data/spec/config_spec.rb +0 -14
  56. data/spec/project_spec.rb +0 -15
  57. data/spec/runner_spec.rb +0 -9
  58. data/spec/task_spec.rb +0 -8
  59. data/spec/util_spec.rb +0 -60
@@ -1,5 +0,0 @@
1
- require File.dirname(__FILE__) + '/commands/project'
2
- require File.dirname(__FILE__) + '/commands/generate'
3
-
4
- Gator::Runner.register_subcommand Gator::ProjectCommand
5
- Gator::Runner.register_subcommand Gator::GenerateCommand
@@ -1,87 +0,0 @@
1
- require "thor"
2
- require "thor/actions"
3
- require "fileutils"
4
-
5
- module Gator
6
- class ProjectCommand < Command
7
- include Thor::Actions
8
- include Gator::Configuration
9
-
10
- define :command => "project", :short => "p",
11
- :usage => "project TASK", :description => "Set of tasks to manage project templates."
12
-
13
- def self.source_root
14
- Gator::Util.project_template_root
15
- end
16
-
17
- desc "project install NAME TEMPLATE_NAME", "Install a project template."
18
- def install( dir, template=nil )
19
- entries = directory_entries dir
20
- template ||= File.expand_path( File.dirname(entries.first) ).split(File::SEPARATOR).last
21
- empty_directory template_dir(template)
22
- FileUtils.cp_r entries, template_dir(template)
23
- create_empty_directory_files template_dir(template)
24
- end
25
-
26
- desc "project uninstall TEMPLATE_NAME", "Uninstall a project template."
27
- def uninstall( template )
28
- FileUtils.rm_r template_dir(template)
29
- end
30
-
31
- desc "project new NAME TEMPLATE_NAME", "Create a new project by template."
32
- def new( name, template )
33
- @project_name = name
34
- directory template_dir(template), File.expand_path( name )
35
- end
36
-
37
- desc "project wipe", "Delete all project templates."
38
- def wipe
39
- template_root_entries(true).each { |e| FileUtils.rm_r e }
40
- end
41
-
42
- desc "project list [SEARCH]", "Lists project templates."
43
- def list(search=nil)
44
- entries = template_root_entries
45
- entries = entries.select { |e| e.include?(search) } unless search.nil?
46
- entries.each {|e| say " #{e}" }
47
- say "No templates found.", :blue if entries.empty?
48
- end
49
-
50
- no_tasks {
51
-
52
- def project_name
53
- @project_name
54
- end
55
-
56
- def configuration
57
- config
58
- end
59
-
60
- }
61
-
62
- private
63
-
64
- def create_empty_directory_files( dir )
65
- Dir.glob( File.join( dir, "**", "*" ) ).each {|f|
66
- create_file File.join(f,".empty_directory"), ".empty_directory" if File.directory?(f) && Dir.entries(f).length == 2
67
- }
68
- end
69
-
70
- def template_dir( template )
71
- File.join( Gator::Util.project_template_root, template )
72
- end
73
-
74
- def directory_entries( dir, join_with_dir=true )
75
- entries = Dir.entries(dir)
76
- entries.delete(".")
77
- entries.delete("..")
78
- entries.collect! { |e| File.join(dir, e) } if join_with_dir
79
- entries
80
- end
81
-
82
- def template_root_entries( join_with_dir=false )
83
- directory_entries Gator::Util.project_template_root, join_with_dir
84
- end
85
-
86
- end
87
- end
@@ -1,23 +0,0 @@
1
- module Gator
2
- module Configuration
3
-
4
- def self.config
5
- @configuration ||= GatorConfiguration.new
6
- end
7
-
8
- def config
9
- Configuration.config
10
- end
11
- alias_method :configuration, :config
12
-
13
- end
14
- class GatorConfiguration
15
-
16
- attr_accessor :user
17
-
18
- def options
19
- @options ||= {}
20
- end
21
-
22
- end
23
- end
@@ -1 +0,0 @@
1
- require File.dirname(__FILE__) + '/generators/generator'
@@ -1,21 +0,0 @@
1
- require 'thor'
2
- require 'thor/group'
3
- require 'thor/actions'
4
-
5
- module Gator
6
- class Runner < Command
7
- include Thor::Actions
8
-
9
- def self.start
10
- Gator::Util.initialize_files
11
- super
12
- end
13
-
14
- desc "version", "Show Gator version"
15
- def version
16
- version_file = File.dirname(__FILE__) + '/../../VERSION'
17
- say File.exist?(version_file) ? File.read(version_file) : ""
18
- end
19
-
20
- end
21
- end
@@ -1,91 +0,0 @@
1
- require "thor"
2
- require "thor/util"
3
- require "thor/actions"
4
- require "pathname"
5
-
6
- module Gator
7
- module Sandbox
8
- extend Gator::Configuration
9
- extend Gator::Project
10
- end
11
- class Util
12
- def self.gator_files
13
- ["gator", "gator.rb"]
14
- end
15
-
16
- def self.gator_files_for(dir)
17
- gator_files.collect { |f| File.join(dir, f) }
18
- end
19
-
20
- def self.gator_config
21
- File.join(gator_root, "configuration.rb")
22
- end
23
-
24
- def self.gator_root
25
- File.join(Thor::Util.user_home, ".gator").gsub(/\\/, '/')
26
- end
27
-
28
- def self.project_template_root
29
- File.join(gator_root, "templates", "projects")
30
- end
31
-
32
- def self.generator_template_root
33
- File.join(gator_root, "templates", "generators" )
34
- end
35
-
36
- def self.load_rubyfile(path, content=nil, debug=false)
37
- content ||= File.binread(path)
38
-
39
- begin
40
- Gator::Sandbox.module_eval(content, path)
41
- rescue Exception => e
42
- $stderr.puts "WARNING: unable to load file #{path.inspect}: #{e.message}"
43
- if debug
44
- $stderr.puts *e.backtrace
45
- else
46
- $stderr.puts e.backtrace.first
47
- end
48
- end
49
- end
50
-
51
- def self.find_gator_project_file(path= Dir.getwd)
52
- gatorfile = nil
53
- Pathname.new(path).ascend do |dir|
54
- gatorfile = gator_files_for(dir).map { |g| Dir[g] }.flatten.first
55
- break unless gatorfile.nil? || File.directory?(gatorfile)
56
- end
57
- gatorfile
58
- end
59
-
60
- def self.find_gator_project(path= Dir.getwd)
61
- file = find_gator_project_file path
62
- File.dirname file unless file.nil?
63
- end
64
-
65
- def self.initialize_files
66
-
67
- if File.exists? gator_config
68
- load_rubyfile gator_config
69
- else
70
- ConfigFileCreator.new.config_file
71
- end
72
-
73
- p_file = find_gator_project_file
74
- load_rubyfile p_file unless p_file.nil?
75
-
76
- end
77
-
78
- class ConfigFileCreator < Thor
79
- include Thor::Actions
80
-
81
- no_tasks {
82
- def config_file
83
- file = Gator::Util.gator_config
84
- user = ask "Username:"
85
- create_file file, "config.user='#{user}'"
86
- end
87
- }
88
- end
89
-
90
- end
91
- end
@@ -1,84 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- class CommandA < Gator::Command
4
- define :command => "a", :short => "a",
5
- :usage => "a", :description => "a"
6
- end
7
-
8
- class CommandB < Gator::Command
9
- define :command => "b", :short => "b",
10
- :usage => "b", :description => "b"
11
- end
12
-
13
- class CommandC < Gator::Command
14
- define :command => "c", :short => "c",
15
- :usage => "c", :description => "c"
16
- end
17
-
18
- class SpecCollection < Gator::Command
19
- define :command => "collection", :short => "c",
20
- :usage => "collection", :description => "collection"
21
-
22
- register_subcommand CommandA
23
- CommandA.register_subcommand CommandB
24
- register_subcommand CommandC
25
- end
26
-
27
- describe Gator::ActAsCommand do
28
-
29
- it "should contain the correct definition" do
30
- CommandA.definition[:command].should == "a"
31
- CommandA.definition[:short].should == "a"
32
- CommandA.definition[:usage].should == "a"
33
- CommandA.definition[:description].should == "a"
34
- end
35
-
36
- it "should have the correct parent" do
37
- CommandB.parent.should == CommandA
38
- CommandA.parent.should == SpecCollection
39
- CommandC.parent.should == SpecCollection
40
- SpecCollection.parent.should == nil
41
- end
42
-
43
- end
44
-
45
- describe Gator::ActAsCommandCollection do
46
-
47
- it "should provide the correct subcommands" do
48
- SpecCollection.get_subcommand("a").should == CommandA
49
- SpecCollection.get_subcommand("c").should == CommandC
50
- end
51
-
52
- it "should provide the correct nested subcommands" do
53
- SpecCollection.get_subcommand("a","b").should == CommandB
54
- end
55
-
56
- it "should return nil if a command cannot be found" do
57
- SpecCollection.get_subcommand("d").should == nil
58
- end
59
-
60
- it "should resolve the correct subcommand on a parent" do
61
- CommandB.resolve_subcommand(["a"]).should == CommandA
62
- CommandB.resolve_subcommand(["c"]).should == CommandC
63
- end
64
-
65
- it "should resolve the correct nested subcommand on a parent" do
66
- CommandC.resolve_subcommand(["a","b"]).should == CommandB
67
- end
68
-
69
- it "should fall back to CommandB" do
70
- CommandC.resolve_subcommand(["a","d"],["a","b"]).should == CommandB
71
- end
72
-
73
- it "should return nil if a command cannot be resolved" do
74
- CommandC.resolve_subcommand("d").should == nil
75
- end
76
-
77
- end
78
-
79
- describe Gator::Command do
80
-
81
- it "should be covered by Gator::ActAsCommandCollection & Gator::ActAsCommand" do
82
- end
83
-
84
- end
@@ -1,14 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
-
4
- describe Gator::Configuration do
5
-
6
- it "should have some tests"
7
-
8
- end
9
-
10
- describe Gator::GatorConfiguration do
11
-
12
- it "should have some tests"
13
-
14
- end
@@ -1,15 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
-
4
- describe Gator::Project do
5
-
6
- it "should have some tests"
7
-
8
- end
9
-
10
- describe Gator::Project::Layout do
11
-
12
- it "should have some tests"
13
- it "could be the tests from the buildr project"
14
-
15
- end
@@ -1,9 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
-
4
- describe Gator::Runner do
5
-
6
- it "should return the correct version" do
7
- end
8
-
9
- end
@@ -1,8 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
-
4
- describe Gator::Task do
5
-
6
- it "should really have some tests"
7
-
8
- end
@@ -1,60 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
-
4
- describe Gator::Util do
5
-
6
- it "should contain the correct filenames" do
7
- Gator::Util.gator_files.include?("gator").should == true
8
- Gator::Util.gator_files.include?("gator.rb").should == true
9
- end
10
-
11
- it "should contain the correct filenames for directory" do
12
- Gator::Util.gator_files_for("testdir").include?("testdir/gator").should == true
13
- Gator::Util.gator_files_for("testdir").include?("testdir/gator.rb").should == true
14
- end
15
-
16
- it "should provide the correct gator root directory" do
17
- Gator::Util.gator_root.should == File.join(File.expand_path("~"), ".gator")
18
- end
19
-
20
- it "should provide the correct project template directory" do
21
- Gator::Util.project_template_root.should == File.join(Gator::Util.gator_root, "templates", "projects")
22
- end
23
-
24
- it "should load a rubyfile correctly"
25
-
26
- it "should find the gator project directory from project base directory" do
27
- project_dir = File.expand_path(File.dirname(__FILE__) + '/fixtures/empty_gator_project')
28
- Gator::Util.find_gator_project(project_dir).should == project_dir
29
- end
30
-
31
- it "should find the gator project directory from a project subdirectory" do
32
- project_dir = File.expand_path(File.dirname(__FILE__) + '/fixtures/empty_gator_project')
33
- sub_dir = File.expand_path(File.dirname(__FILE__) + '/fixtures/empty_gator_project/sub_dir')
34
- Gator::Util.find_gator_project(sub_dir).should == project_dir
35
- end
36
-
37
- it "should find the gator.rb file from project base directory" do
38
- project_dir = File.expand_path(File.dirname(__FILE__) + '/fixtures/empty_gator_project')
39
- file = File.join(project_dir, "gator.rb")
40
- Gator::Util.find_gator_project_file(project_dir).should == file
41
- end
42
-
43
- it "should find the gator.rb file from a project subdirectory" do
44
- project_dir = File.expand_path(File.dirname(__FILE__) + '/fixtures/empty_gator_project')
45
- sub_dir = File.expand_path(File.dirname(__FILE__) + '/fixtures/empty_gator_project/sub_dir')
46
- file = File.join(project_dir, "gator.rb")
47
- Gator::Util.find_gator_project_file(sub_dir).should == file
48
- end
49
-
50
- it "should not find a gator project in a project without gator.rb from the its base directory" do
51
- project_dir = File.expand_path(File.dirname(__FILE__) + '/fixtures/no_gator_file')
52
- Gator::Util.find_gator_project(project_dir).should == nil
53
- end
54
-
55
- it "should not find a gator project in a project without gator.rb from the a subdirectory" do
56
- project_dir = File.expand_path(File.dirname(__FILE__) + '/fixtures/no_gator_file/subdir')
57
- Gator::Util.find_gator_project(project_dir).should == nil
58
- end
59
-
60
- end