Skip to content
Browse files

clean up unused methods

  • Loading branch information...
1 parent b474321 commit faa33e5c0f7d419dd10a13f2ad7aa7933fb201c4 @Jaym3s Jaym3s committed Jan 6, 2011
Showing with 22 additions and 323 deletions.
  1. +1 −1 Gemfile
  2. +15 −0 Gemfile.lock
  3. +3 −1 bin/bender
  4. +2 −73 lib/bender.rb
  5. +1 −1 lib/bender/dashboard.rb
  6. +0 −247 lib/bender/runner.rb
View
2 Gemfile
@@ -6,7 +6,7 @@ gem 'sinatra'
group :development, :test do
gem 'aruba'
- gem 'bundler'
+ gem 'ruby-debug19'
gem 'capybara'
gem 'cucumber-sinatra'
gem 'jeweler'
View
15 Gemfile.lock
@@ -1,6 +1,7 @@
GEM
remote: http://rubygems.org/
specs:
+ archive-tar-minitar (0.5.2)
aruba (0.3.2)
childprocess (~> 0.1.6)
cucumber (~> 0.10.0)
@@ -18,6 +19,7 @@ GEM
celerity (0.8.6)
childprocess (0.1.6)
ffi (~> 0.6.3)
+ columnize (0.3.2)
configuration (1.2.0)
cucumber (0.10.0)
builder (>= 2.1.2)
@@ -46,6 +48,8 @@ GEM
launchy (0.3.7)
configuration (>= 0.0.5)
rake (>= 0.8.1)
+ linecache19 (0.5.11)
+ ruby_core_source (>= 0.1.4)
mime-types (1.16)
nokogiri (1.4.4)
rack (1.2.1)
@@ -61,6 +65,16 @@ GEM
rspec-expectations (2.3.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.3.0)
+ ruby-debug-base19 (0.11.24)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby_core_source (>= 0.1.4)
+ ruby-debug19 (0.11.6)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby-debug-base19 (>= 0.11.19)
+ ruby_core_source (0.1.4)
+ archive-tar-minitar (>= 0.5.2)
rubyzip (0.9.4)
selenium-webdriver (0.1.2)
childprocess (~> 0.1.5)
@@ -93,4 +107,5 @@ DEPENDENCIES
launchy
rcov
rspec
+ ruby-debug19
sinatra
View
4 bin/bender
@@ -3,5 +3,7 @@
$:.unshift(File.join(File.dirname(File.dirname(__FILE__)),'lib'))
begin; require 'rubygems'; rescue LoadError; end
require 'bender'
+require 'bender/command'
-Bender.run(ARGV)
+include Bender::Command
+Bender::Command.run(ARGV)
View
75 lib/bender.rb
@@ -1,74 +1,3 @@
-require 'yaml'
+module Bender; end
-class Bender
-
- class Error < RuntimeError
- end
-
- autoload :Runner, 'bender/runner'
- autoload :Dashboard, 'bender/dashboard'
-
- def self.config
- @config ||= {}.merge(
- if File.exist?(path = File.expand_path('~/.tracker.yml'))
- YAML.load_file(path)
- end || {}
- )
- end
-
- def self.hash_to_xml(root, attributes)
- require 'cgi'
- xml = "<#{root}>"
- attributes.each do |k,v|
- if v.kind_of?(Hash)
- xml << hash_to_xml(k, v)
- else
- xml << "<#{k}>#{CGI.escapeHTML(v.to_s)}</#{k}>"
- end
- end
- xml << "</#{root}>"
- end
-
- def self.run(argv)
- Runner.new(argv).run
- end
-
- attr_reader :directory
-
- def initialize(path = '.')
- @lang = 'en'
- @directory = File.expand_path(path)
- until File.directory?(File.join(@directory,'doc/bender'))
- if @directory == File.dirname(@directory)
- raise Error, 'Project not found. Make sure you have a doc/bender/ directory.', caller
- end
- @directory = File.dirname(@directory)
- end
- end
-
- def project_path(*subdirs)
- File.join(@directory,*subdirs)
- end
-
- def config_file
- project_path('.bendrc') || project_path('config/.bendrc')
- end
-
- def config
- @config ||= File.exist?(config_file) && YAML.load_file(config_file) || {}
- self.class.config.merge(@config)
- end
-
- def real_name
- config["real_name"] || (require 'etc'; Etc.getpwuid.gecos.split(',').first)
- end
-
- def project
- @project ||= Dir.chdir(@directory) do
- end
- end
-
- def format
- (config['format'] || :tag).to_sym
- end
-end
+require 'bender/base'
View
2 lib/bender/dashboard.rb
@@ -2,7 +2,7 @@
require 'git'
require 'haml'
-class Bender
+module Bender
class Dashboard < Sinatra::Base
set :root, File.join(File.dirname(__FILE__), '../../')
get '/' do
View
247 lib/bender/runner.rb
@@ -1,247 +0,0 @@
-require 'optparse'
-
-class Bender
- class Runner
- class Base
- attr_reader :argv
-
- def initialize(argv)
- @argv = argv
- @tty = $stdout.tty?
- @opts = OptionParser.new
- @opts.version = "0.0.1"
- @opts.banner = "Usage: bender #{self.class.command_name} #{self.class.banner_arguments}"
- @opts.base.long["help"] = OptionParser::Switch::NoArgument.new do
- help = @opts.help.chomp.chomp + "\n"
- help += "\n#{self.class.description}" if self.class.description
- puts help
- @exit = 0
- end
- @opts.separator("")
- end
-
- def self.options
- @options ||= []
- end
-
- def self.on(*args, &block)
- options << args
- define_method("option_#{args.object_id}", &block)
- end
-
- def self.banner_arguments(value = nil)
- if value
- @banner_arguments = value
- else
- @banner_arguments || (arity.zero? ? "" : "...")
- end
- end
-
- def self.summary(value = nil)
- if value
- @summary = value
- else
- @summary
- end
- end
-
- def self.description(value = nil)
- if value
- @description = value
- else
- @description || "#@summary."
- end
- end
-
- def self.command_name
- name.split('::').last.gsub(/(.)([A-Z])/) {"#$1-#$2"}.downcase
- end
-
- def self.method_name
- command_name.gsub('-','_')
- end
-
- def self.process(&block)
- define_method(:process, &block)
- end
-
- def self.arity
- instance_method(:process).arity
- end
-
- def arity
- self.class.arity
- end
-
- def bender
- @bender ||= Bender.new(Dir.getwd)
- end
-
- def abort(message)
- raise Error, message
- end
-
- def too_many
- abort "too many arguments"
- end
-
- def run
- self.class.options.each do |arguments|
- @opts.on(*arguments, &method("option_#{arguments.object_id}"))
- end
- begin
- @opts.parse!(@argv)
- rescue OptionParser::InvalidOption
- abort $!.message
- end
- return @exit if @exit
- minimum = arity < 0 ? -1 - arity : arity
- if arity >= 0 && arity < @argv.size
- too_many
- elsif minimum > @argv.size
- abort "not enough arguments"
- end
- process(*@argv)
- end
-
- def process(*argv)
- bender.send(self.class.method_name,*argv)
- end
-
- def color?
- case bender.config["color"]
- when "always" then true
- when "never" then false
- else
- @tty && RUBY_PLATFORM !~ /mswin|mingw/
- end
- end
-
- def colorize(code, string)
- if color?
- "\e[#{code}m#{string}\e[00m"
- else
- string.to_s
- end
- end
-
- def paginated_output
- stdout = $stdout
- if @tty && pager = bender.config["pager"]
- # Modeled after git
- ENV["LESS"] ||= "FRSX"
- IO.popen(pager,"w") do |io|
- $stdout = io
- yield
- end
- else
- yield
- end
- rescue Errno::EPIPE
- ensure
- $stdout = stdout
- end
-
- end
-
- def self.[](command)
- klass_name = command.to_s.capitalize.gsub(/[-_](.)/) { $1.upcase }
- if klass_name =~ /^[A-Z]\w*$/ && const_defined?(klass_name)
- klass = const_get(klass_name)
- if Class === klass && klass < Base
- return klass
- end
- end
- end
-
- def self.commands
- constants.map {|c| Runner.const_get(c)}.select {|c| Class === c && c < Runner::Base}.sort_by {|r| r.command_name}.uniq
- end
-
- def self.command(name, &block)
- const_set(name.to_s.capitalize.gsub(/[-_](.)/) { $1.upcase },Class.new(Base,&block))
- end
-
- command :dashboard do
- process do |*args|
- Bender::Dashboard.run! :host => 'localhost', :port => 4567
- end
- end
-
- command :info do
- banner_arguments "[format]"
- summary "Show project info"
-
- on "--full", "default format" do |full|
- @format = :full
- end
-
- on "--summary", "summary view containing current statistics" do |raw|
- @format = :summary
- end
-
- process do |*args|
- case args.size
- when 0
- puts "Bender Project"
- else
- too_many
- end
- end
- end
-
- command :templates do
- summary "List config files with templates"
-
- process do |*args|
- case args.size
- when 0
- Dir.glob(File.join(bender.project_path, '**', '*.template')).each {|file| puts file}
- else
- too_many
- end
- end
- end
-
- def initialize(argv)
- @argv = argv
- end
-
- COLORS = {
- :black => 0,
- :red => 1,
- :green => 2,
- :yellow => 3,
- :blue => 4,
- :magenta => 5,
- :cyan => 6,
- :white => 7
- }
-
- def run
- command = @argv.shift
- if klass = self.class[command]
- result = klass.new(@argv).run
- exit result.respond_to?(:to_int) ? result.to_int : 0
- elsif ['help', '--help', '-h', '', nil].include?(command)
- puts "usage: bender <command> [options] [arguments]"
- puts
- puts "Commands:"
- self.class.commands.each do |command|
- puts " %-19s %s" % [command.command_name, command.summary]
- end
- puts
- puts "Run bender <command> --help for help with a given command"
- else
- raise Error, "Unknown bender command #{command}"
- end
- rescue Bender::Error
- $stderr.puts "#$!"
- exit 1
- rescue Interrupt
- $stderr.puts "Interrupted!"
- exit 130
- end
-
- end
-end

0 comments on commit faa33e5

Please sign in to comment.
Something went wrong with that request. Please try again.