Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit ea2b38c95e15377506ac77d11332da52e1072f06 @mikew committed
4 .gitignore
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
1 .rvmrc
@@ -0,0 +1 @@
+rvm use ruby-1.9.2-p136@workon
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in workon.gemspec
+gemspec
2 Rakefile
@@ -0,0 +1,2 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
23 lib/workon.rb
@@ -0,0 +1,23 @@
+$:.push File.expand_path("../", __FILE__)
+require 'workon/actor'
+
+module Workon
+ WORK_DIRS = '/Users/mike/Work/*/*'
+
+ def self.all_directories
+ @_all_directories ||= Dir[WORK_DIRS]
+ end
+
+ def self.find(str)
+ candidate = all_directories.find { |d| d.end_with? "/#{str}" }
+ commit candidate unless candidate.nil?
+ end
+
+ def self.commit(path)
+ Workon::Actor.all.each do |klass|
+ klass.new(path).commit
+ end
+ end
+end
+
+Workon.find "workon" if __FILE__ == $0
13 lib/workon/actor.rb
@@ -0,0 +1,13 @@
+require 'workon/actor/base'
+require 'workon/actor/text_mate'
+require 'workon/actor/web_browser'
+require 'workon/actor/finder'
+require 'workon/actor/git'
+
+module Workon
+ module Actor
+ def self.all
+ Workon::Actor::Base.subclasses
+ end
+ end
+end
34 lib/workon/actor/base.rb
@@ -0,0 +1,34 @@
+module Workon
+ module Actor
+ class Base
+ attr_reader :path
+ attr_reader :project
+
+ def self.subclasses
+ @_subclasses
+ end
+
+ def self.inherited(base)
+ @_subclasses ||= []
+ @_subclasses << base
+ end
+
+ def initialize(path)
+ @path = path
+ end
+
+ def project
+ @project ||= @path.split('/').last
+ end
+
+ def commit
+ run command
+ end
+
+ def run(command)
+ puts "Running #{command}"
+ %x(#{command})
+ end
+ end
+ end
+end
9 lib/workon/actor/finder.rb
@@ -0,0 +1,9 @@
+module Workon
+ module Actor
+ class Finder < Base
+ def command
+ "open #{path}"
+ end
+ end
+ end
+end
13 lib/workon/actor/git.rb
@@ -0,0 +1,13 @@
+module Workon
+ module Actor
+ class Git < Base
+ def project_uses_git?
+ Dir.exists? %{#{path}/.git}
+ end
+
+ def commit
+ run "git log" if project_uses_git?
+ end
+ end
+ end
+end
9 lib/workon/actor/text_mate.rb
@@ -0,0 +1,9 @@
+module Workon
+ module Actor
+ class TextMate < Base
+ def command
+ "mate #{path}"
+ end
+ end
+ end
+end
10 lib/workon/actor/web_browser.rb
@@ -0,0 +1,10 @@
+module Workon
+ module Actor
+ class WebBrowser < Base
+ def command
+ host_name = %{#{project}.local}
+ %{ping -q -c 1 -t 1 #{host_name} && open http://#{host_name}}
+ end
+ end
+ end
+end
3 lib/workon/version.rb
@@ -0,0 +1,3 @@
+module Workon
+ VERSION = "0.0.1"
+end
24 workon.gemspec
@@ -0,0 +1,24 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "workon/version"
+
+Gem::Specification.new do |s|
+ s.name = "workon"
+ s.version = Workon::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Mike Wyatt"]
+ s.email = ["wyatt.mike@gmail.com"]
+ s.homepage = ""
+ s.summary = %q{TODO: Write a gem summary}
+ s.description = %q{TODO: Write a gem description}
+
+ s.add_dependency "activesupport"
+ s.add_development_dependency "rspec"
+
+ s.rubyforge_project = "workon"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+end

0 comments on commit ea2b38c

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