workon 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ruby-1.9.2-p136@workon
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in workon.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/workon ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ source_root = File.expand_path '../../lib', __FILE__
4
+ $LOAD_PATH.unshift source_root
5
+
6
+ require 'workon/cli'
7
+ Workon::CLI.execute
@@ -0,0 +1,76 @@
1
+ module Workon
2
+ module Actor
3
+ class Base
4
+ attr_reader :path
5
+ attr_reader :project
6
+
7
+ def self.inherited(base)
8
+ @_subclasses ||= []
9
+ @_subclasses << base
10
+ end
11
+
12
+ def self.option(*args, &block)
13
+ Workon::Configuration.instance.parser.on(*args) do |v|
14
+ block.call(v)
15
+ end
16
+ end
17
+
18
+ def self.options
19
+ Workon.config
20
+ end
21
+
22
+ def self.subclasses
23
+ @_subclasses
24
+ end
25
+
26
+ def initialize(path)
27
+ @path = path
28
+ end
29
+
30
+ def options
31
+ self.class.options
32
+ end
33
+
34
+ def has_option?(key)
35
+ key = key.to_sym
36
+
37
+ !options[key].nil? && !options[key].empty?
38
+ end
39
+
40
+ def fetch_option(key, default = nil)
41
+ has_option?(key) ? options[key] : default
42
+ end
43
+
44
+ def project
45
+ @project ||= Workon.project_name
46
+ end
47
+
48
+ def commit
49
+ run command
50
+ end
51
+
52
+ def system(command)
53
+ puts "Running #{command}"
54
+ Kernel.system command
55
+ end
56
+
57
+ def run(command)
58
+ puts "Running #{command}"
59
+ output = %x(#{command})
60
+ return output
61
+ end
62
+
63
+ def screen(command, scope = nil)
64
+ identifier = screen_scope scope
65
+
66
+ run %(screen -dmS #{identifier} #{command})
67
+ puts %(Reconnect with `screen -r #{identifier}')
68
+ end
69
+
70
+ def screen_scope(scope = nil)
71
+ scope ||= self.class.name.to_s.split('::').last
72
+ "#{project}.#{scope}".downcase
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,9 @@
1
+ module Workon
2
+ module Actor
3
+ class Finder < Base
4
+ def command
5
+ "open #{path}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module Workon
2
+ module Actor
3
+ class Git < Base
4
+ def project_uses_git?
5
+ Dir.exists? %{#{path}/.git}
6
+ end
7
+
8
+ def commit
9
+ output = %x(git log --oneline -n 10) if project_uses_git?
10
+ puts output
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ module Workon
2
+ module Actor
3
+ class Passenger < Base
4
+ def is_rack_app?
5
+ !Dir['config.ru'].empty?
6
+ end
7
+
8
+ def passenger_standalone_available?
9
+ !`which passenger`.empty?
10
+ end
11
+
12
+ def commit
13
+ screen "passenger start" if is_rack_app? && passenger_standalone_available?
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module Workon
2
+ module Actor
3
+ class TextMate < Base
4
+ def command
5
+ "mate #{path}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module Workon
2
+ module Actor
3
+ class Watchr < Base
4
+ def watchr_file_exists?
5
+ !Dir['*.watchr'].empty?
6
+ end
7
+
8
+ def commit
9
+ screen "watchr" if watchr_file_exists?
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module Workon
2
+ module Actor
3
+ class WebBrowser < Base
4
+ option('--host HOST', 'Ping this host') { |v| options[:host] = v}
5
+
6
+ def command
7
+ host_name = fetch_option :host, %{#{project}.local}
8
+ %{ping -q -c 1 -t 1 #{host_name} && open http://#{host_name}}
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ require 'workon/actor/base'
2
+ require 'workon/actor/text_mate'
3
+ require 'workon/actor/web_browser'
4
+ require 'workon/actor/finder'
5
+ require 'workon/actor/git'
6
+ require 'workon/actor/watchr'
7
+ require 'workon/actor/passenger'
8
+
9
+ module Workon
10
+ module Actor
11
+ include Enumerable
12
+
13
+ def self.each(&block)
14
+ Workon::Actor::Base.subclasses.each {|c| yield c }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,68 @@
1
+ module Workon
2
+ module CLI
3
+ module Commands
4
+ module InstallHelper
5
+ BASH_PROFILE_PATH = '~/.bash_profile'
6
+
7
+ def self.execute
8
+ install unless installed?
9
+ end
10
+
11
+ def self.install
12
+ puts "Installing bash helper function to #{bash_profile_path}"
13
+
14
+ begin
15
+ File.open(bash_profile_path, 'a') do |f|
16
+ f.write "\n\n"
17
+ f.write finder
18
+ f.write helper_function
19
+ end
20
+
21
+ puts "... Success!"
22
+ rescue => error
23
+ puts "... Failed!"
24
+ puts error
25
+ end
26
+ end
27
+
28
+ def self.bash_profile_path
29
+ BASH_PROFILE_PATH.sub '~', ENV['HOME']
30
+ end
31
+
32
+ def self.finder
33
+ "# Created by workon version #{Workon::VERSION}\n"
34
+ end
35
+
36
+ def self.installed?
37
+ !(File.read(bash_profile_path) =~ /#{finder}/).nil?
38
+ end
39
+
40
+ def self.helper_message(path)
41
+ lines = [ "This is for the bash helper function",
42
+ "cd #{path}" ]
43
+
44
+ lines.each {|l| puts l } if installed?
45
+ end
46
+
47
+ def self.helper_function
48
+ <<'BASH'
49
+ wo () {
50
+ OLDIFS=$IFS
51
+ IFS=$'\n'
52
+
53
+ workon_bin=$(which workon)
54
+ output=$($workon_bin $1)
55
+
56
+ for line in $output; do
57
+ echo $line
58
+ done
59
+
60
+ eval $line
61
+ IFS=$OLDIFS
62
+ }
63
+ BASH
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
data/lib/workon/cli.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'workon'
2
+ require 'workon/cli/commands'
3
+
4
+ module Workon
5
+ module CLI
6
+ def self.execute
7
+ config = Workon.config ARGV
8
+
9
+ if config[:show_help]
10
+ puts Workon::Configuration.instance.parser
11
+ exit
12
+ end
13
+
14
+ if config[:install_helper]
15
+ Workon::CLI::Commands::InstallHelper.execute
16
+ exit
17
+ end
18
+
19
+ raise OptionParser::MissingArgument unless Workon.has_project?
20
+
21
+ Workon.find_project
22
+
23
+ if config[:dump_configuration]
24
+ Workon::Configuration.instance.dump_to_project_rc
25
+ exit
26
+ end
27
+
28
+ Workon.commit!
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,88 @@
1
+ require 'optparse'
2
+ require 'yaml'
3
+
4
+ module Workon
5
+ class Configuration
6
+ attr_reader :options
7
+ attr_reader :parser
8
+
9
+ def self.instance(*args)
10
+ @_instance ||= new(*args)
11
+ end
12
+
13
+ def initialize(*args)
14
+ @options = { without: [], only: [], install_helper: false, dump_configuration: false, project: nil, show_help: false }
15
+ parse_options args.first unless args.empty?
16
+ end
17
+
18
+ def parse_options(args)
19
+ parser.parse! args
20
+ options[:project] = args.first unless args.empty?
21
+ end
22
+
23
+ def parser
24
+ @parser ||= OptionParser.new do |o|
25
+ o.banner = "Usage: #{File.basename($0)} [options] project"
26
+
27
+ o.on('-w', '--without ACTORS', Array, 'Exclude unwanted actors') do |v|
28
+ options[:without] = v
29
+ end
30
+
31
+ o.on('-o', '--only ACTORS', Array, 'Only use certain actors') do |v|
32
+ options[:only] = v
33
+ end
34
+
35
+ o.on('-d', '--dump-configuration', 'Dump workon configuration to project_path/.workon.yml') do
36
+ options[:dump_configuration] = true
37
+ end
38
+
39
+ o.on_tail('--install-helper', 'Install `wo` helper function to ~/.bash_profile') do
40
+ options[:install_helper] = true
41
+ end
42
+
43
+ o.on_tail('-v', '--version', 'Show version information') do
44
+ puts Workon::VERSION
45
+ exit
46
+ end
47
+
48
+ o.on_tail('-h', '--help', 'Show this help information') do
49
+ options[:show_help] = true
50
+ # exit
51
+ end
52
+ end
53
+ end
54
+
55
+ def project_rc_path
56
+ @project_rc_path ||= File.join Workon.project_path, '.workonrc'
57
+ end
58
+
59
+ def project_rc_exists?
60
+ File.exist? project_rc_path
61
+ end
62
+
63
+ def merge_project_rc
64
+ if project_rc_exists?
65
+ opts = YAML.load_file(project_rc_path)
66
+ @options.merge! opts
67
+ end
68
+ end
69
+
70
+ def dump_to_project_rc
71
+ o = options.dup
72
+ o.delete :install_helper
73
+ o.delete :dump_configuration
74
+ o.delete :project
75
+ o.delete :show_help
76
+
77
+ begin
78
+ File.open(project_rc_path, 'w') do |f|
79
+ YAML.dump o, f
80
+ end
81
+
82
+ puts %(Saved workon configuration to #{project_rc_path})
83
+ rescue
84
+ STDERR.puts %(Could not save workon configuration to #{project_rc_path})
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,3 @@
1
+ module Workon
2
+ VERSION = "0.0.6"
3
+ end
data/lib/workon.rb ADDED
@@ -0,0 +1,53 @@
1
+ $LOAD_PATH.unshift File.expand_path("../", __FILE__)
2
+
3
+ require 'workon/configuration'
4
+ require 'workon/actor'
5
+ require "workon/version"
6
+
7
+ module Workon
8
+ WORK_DIRS = '/Users/mike/Work/*/*'
9
+
10
+ def self.all_directories
11
+ @_all_directories ||= Dir[WORK_DIRS]
12
+ end
13
+
14
+ def self.project_name
15
+ config[:project]
16
+ end
17
+
18
+ def self.project_path
19
+ @_path
20
+ end
21
+
22
+ def self.has_project?
23
+ !project_name.nil? && 0 < project_name.to_s.length
24
+ end
25
+
26
+ def self.find_project(str = project_name)
27
+ candidate = all_directories.find { |d| d.end_with? "/#{str}" }
28
+
29
+ unless candidate.nil?
30
+ @_path = candidate
31
+ Workon::Configuration.instance.merge_project_rc
32
+ end
33
+ end
34
+
35
+ def self.commit!
36
+ Dir.chdir project_path
37
+
38
+ Workon::Actor.each do |klass|
39
+ klass.new(project_path).commit
40
+ end
41
+
42
+ Workon::CLI::Commands::InstallHelper.helper_message(project_path)
43
+ end
44
+
45
+ def self.load_configuration(args)
46
+ Workon::Configuration.instance.parse_options args
47
+ end
48
+
49
+ def self.config(args = [])
50
+ load_configuration args unless args.empty?
51
+ Workon::Configuration.instance.options
52
+ end
53
+ end
data/workon.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "workon/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "workon"
7
+ s.version = Workon::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Mike Wyatt"]
10
+ s.email = ["wyatt.mike@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Runs actions based on directories}
13
+ s.description = %q{Runs actions based on directories}
14
+
15
+ # s.add_dependency "activesupport"
16
+ # s.add_development_dependency "rspec"
17
+
18
+ s.rubyforge_project = "workon"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: workon
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.6
6
+ platform: ruby
7
+ authors:
8
+ - Mike Wyatt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-02-25 00:00:00 -03:30
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Runs actions based on directories
18
+ email:
19
+ - wyatt.mike@gmail.com
20
+ executables:
21
+ - workon
22
+ extensions: []
23
+
24
+ extra_rdoc_files: []
25
+
26
+ files:
27
+ - .gitignore
28
+ - .rvmrc
29
+ - Gemfile
30
+ - Rakefile
31
+ - bin/workon
32
+ - lib/workon.rb
33
+ - lib/workon/actor.rb
34
+ - lib/workon/actor/base.rb
35
+ - lib/workon/actor/finder.rb
36
+ - lib/workon/actor/git.rb
37
+ - lib/workon/actor/passenger.rb
38
+ - lib/workon/actor/text_mate.rb
39
+ - lib/workon/actor/watchr.rb
40
+ - lib/workon/actor/web_browser.rb
41
+ - lib/workon/cli.rb
42
+ - lib/workon/cli/commands.rb
43
+ - lib/workon/configuration.rb
44
+ - lib/workon/version.rb
45
+ - workon.gemspec
46
+ has_rdoc: true
47
+ homepage: ""
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options: []
52
+
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ requirements: []
68
+
69
+ rubyforge_project: workon
70
+ rubygems_version: 1.5.2
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Runs actions based on directories
74
+ test_files: []
75
+