Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mikew committed Jan 21, 2011
0 parents commit ea2b38c
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,4 @@
*.gem
.bundle
Gemfile.lock
pkg/*
1 change: 1 addition & 0 deletions .rvmrc
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
rvm use ruby-1.9.2-p136@workon
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in workon.gemspec
gemspec
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'bundler'
Bundler::GemHelper.install_tasks
23 changes: 23 additions & 0 deletions lib/workon.rb
Original file line number Original file line Diff line number Diff line change
@@ -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 changes: 13 additions & 0 deletions lib/workon/actor.rb
Original file line number Original file line Diff line number Diff line change
@@ -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 changes: 34 additions & 0 deletions lib/workon/actor/base.rb
Original file line number Original file line Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions lib/workon/actor/finder.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,9 @@
module Workon
module Actor
class Finder < Base
def command
"open #{path}"
end
end
end
end
13 changes: 13 additions & 0 deletions lib/workon/actor/git.rb
Original file line number Original file line Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions lib/workon/actor/text_mate.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,9 @@
module Workon
module Actor
class TextMate < Base
def command
"mate #{path}"
end
end
end
end
10 changes: 10 additions & 0 deletions lib/workon/actor/web_browser.rb
Original file line number Original file line Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions lib/workon/version.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
module Workon
VERSION = "0.0.1"
end
24 changes: 24 additions & 0 deletions workon.gemspec
Original file line number Original file line Diff line number Diff line change
@@ -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.