Permalink
Browse files

Implemented command system.Implemented experimental generator system …

…including an AS3ClassGenerator.
  • Loading branch information...
1 parent a6e76e4 commit 413539eb9f719e302fd05a2ed23fa1e7de4d9099 @devboy committed Jul 3, 2011
View
@@ -2,4 +2,3 @@
*.iml
Gemfile.lock
*.gem
-.gator
View
1 .rspec
@@ -0,0 +1 @@
+--color
View
@@ -8,7 +8,7 @@ gem "thor", "~>0.14.6"
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
- gem "shoulda", ">= 0"
+ gem "rspec", "~> 2.3.0"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.6.2"
gem "rcov", ">= 0"
View
@@ -25,22 +25,19 @@ Jeweler::Tasks.new do |gem|
end
Jeweler::RubygemsDotOrgTasks.new
-require 'rake/testtask'
-Rake::TestTask.new(:test) do |test|
- test.libs << 'lib' << 'test'
- test.pattern = 'test/**/test_*.rb'
- test.verbose = true
+require 'rspec/core'
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new(:spec) do |spec|
+ spec.pattern = FileList['spec/**/*_spec.rb']
end
-require 'rcov/rcovtask'
-Rcov::RcovTask.new do |test|
- test.libs << 'test'
- test.pattern = 'test/**/test_*.rb'
- test.verbose = true
- test.rcov_opts << '--exclude "gems/*"'
+RSpec::Core::RakeTask.new(:rcov) do |spec|
+ spec.pattern = 'spec/**/*_spec.rb'
+ spec.rcov = true
end
-task :default => :test
+task :test => :spec
+task :default => :spec
require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
View
@@ -39,8 +39,8 @@ Gem::Specification.new do |s|
"lib/core/project/layout.rb",
"lib/core/project/project.rb",
"lib/gator.rb",
- "test/helper.rb",
- "test/test_gator.rb"
+ "command/helper.rb",
+ "command/test_gator.rb"
]
s.homepage = %q{http://github.com/devboy/gator}
s.licenses = ["MIT"]
View
@@ -1,5 +1,4 @@
-require File.dirname(__FILE__) + '/core/cli'
require File.dirname(__FILE__) + '/core/command'
-require File.dirname(__FILE__) + '/core/plugin'
require File.dirname(__FILE__) + '/core/configuration'
-require File.dirname(__FILE__) + '/core/project'
+require File.dirname(__FILE__) + '/core/project'
+require File.dirname(__FILE__) + '/core/cli'
@@ -1,56 +1,46 @@
-module Gator
-
- class Application
+require File.dirname(__FILE__) + '/../../../lib/core/project'
+require File.dirname(__FILE__) + '/../../../lib/core/configuration'
- def initialize
- self
+module Gator
+ def self.set_argv(args)
+ ARGV.length.times do |i|
+ ARGV.delete_at i
end
-
- def execute( args )
- configuration.load_configuration
+ args.length.times do |i|
+ ARGV[i] = args[i]
end
+ end
- def configuration
- @configuration ||= Configuration.new
- end
+ module CLI
+ class Application
- def project
- @project
- end
+ def initialize
+ self
+ end
- def project=( proj )
- @project= proj
- end
+ def execute(args)
+ raise "No command specified." if args.empty?
+ command = args.shift
+ raise "Command: \"#{command}\" could not be found." unless Gator::Command.has?(command)
+ args << "--help" if args.empty?
+ Gator::Command.get(command).start args
+ end
- def shell
- @shell ||= Shell.new
- end
+ def shell
+ @shell ||= Shell.new
+ end
+ end
end
-
class << self
attr_accessor :application
- attr_accessor :base_dir
-
- def configuration
- application.configuration
- end
-
- def project
- application.project
- end
-
- def project=(proj)
- application.project= proj
- end
def shell
application.shell
end
end
- self.application= Application.new
-
+ self.application= Gator::CLI::Application.new
end
View
@@ -0,0 +1 @@
+require File.dirname(__FILE__) + '/command/command'
@@ -0,0 +1,50 @@
+module Gator
+ module Command
+
+ class << self
+
+ def add(command)
+ unless will_collide? command
+ commands.push(command)
+ return true
+ end
+ false
+ end
+
+ def remove(command)
+ commands.delete(command) != nil?
+ end
+
+ def has?(name_or_alias)
+ commands.any? { |command| command.command_name == name_or_alias || command.command_alias == name_or_alias }
+ end
+
+ def get(name_or_alias)
+ commands.detect { |command| command.command_name == name_or_alias || command.command_alias == name_or_alias }
+ end
+
+ protected
+
+ def commands
+ @commands ||= []
+ end
+
+ def will_collide?(command)
+ has?(command.command_name) || has?(command.command_alias)
+ end
+
+ end
+
+ class Base < Thor::Group
+
+ class << self
+ attr_reader :command_name, :command_alias
+
+ def specify( command_name, command_alias )
+ @command_name, @command_alias = command_name, command_alias
+ end
+ end
+
+ end
+ end
+end
@@ -1,78 +1,60 @@
module Gator
- class Configuration
+ module Configuration
- def initialize
- @values = {}
- self
- end
+ class Config
- def load_configuration
- load_global_configuration
- load_project_configuration
- end
+ attr_reader :options
- def method_missing( sym, *args )
- if sym.to_s.end_with? "="
- @values[sym.to_s.gsub("=","")] = args.first unless args.empty?
- else
- @values[sym.to_s]
+ def initialize
+ @options = {}
+ @loaded = false
+ self
end
- end
- protected
+ def loaded
+ @loaded
+ end
- def load_project_configuration
- config_file = File.find_file_upwards("gator_config.rb") || File.join( ".gator","gator_config.rb")
- ConfigurationGenerator.new.create_configuration config_file unless File.exists? config_file
- Gator.base_dir = File.expand_path( File.dirname( File.dirname( config_file ) ) )
- load config_file
- end
+ def load_config
+ config_file = File.join(File.expand_path("~"), ".gator", "configuration.rb")
+ ConfigurationGenerator.new.create_configuration config_file unless File.exists? config_file
+ @loaded = true
+ load config_file
+ end
- def load_global_configuration
- config_file = File.join( File.expand_path("~"),".gator","gator_config.rb")
- ConfigurationGenerator.new.create_configuration config_file, true unless File.exists? config_file
- load config_file
end
- end
-
- #TODO: Refactor into gator default plugin
- class ConfigurationGenerator < Thor
- include Thor::Actions
+ class << self
+ attr_accessor :config
+ end
+ self.config = Config.new
- no_tasks {
+ def configuration
+ config = Gator::Configuration.config
+ config.load_config unless config.loaded
+ config
+ end
- def create_configuration( config_file, global=false )
- Gator.shell.say "#{global ? "Global " : "Project "}configuration file not found in: #{config_file}!", :red
- Gator.shell.say "This is not a problem. Let's create one!", :green
- create_file config_file do
- render = ""
- render += "#This file has been generated by gator and wants to be edited by you!\n"
- if global
- render += "Gator.configuration.author=\"#{Gator.shell.ask "Author:"}\"\n"
- else
- render += "Gator.project = Gator::Project.new \"#{Gator.shell.ask "Project name:"}\"\n"
+ #TODO: Refactor into gator default plugin
+ class ConfigurationGenerator < Thor
+ include Thor::Actions
+
+ no_tasks {
+
+ def create_configuration(config_file)
+ Gator.shell.say "Configuration file not found at: #{config_file}!", :red
+ Gator.shell.say ""
+ Gator.shell.say "Let's create one!", :green
+ create_file config_file do
+ render = ""
+ render += "#This file has been generated by gator and wants to be edited by you!\n"
+ render += "configuration.options[:author] = \"#{Gator.shell.ask "\nAuthor:"}\"\n"
+ render
+ end
end
- render
- end
- end
-
- }
- end
-
-end
+ }
-class File
- def self.find_file_upwards( file )
- original_dir = here = Dir.pwd
- while ! (File.file?(File.join(here,file)))
- Dir.chdir("..")
- return nil if Dir.pwd == here
- here = Dir.pwd
- end
- File.join(here,file)
- ensure
- Dir.chdir(original_dir)
end
+ end
end
View
No changes.
Oops, something went wrong.

0 comments on commit 413539e

Please sign in to comment.