project 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg/*
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Josh Nesbitt <josh@josh-nesbitt.net>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "project"
8
+ gem.summary = "A streamlined approach to working with multiple projects and tasks."
9
+ gem.description = ""
10
+ gem.email = "josh@josh-nesbitt.net"
11
+ gem.homepage = "http://github.com/joshnesbitt/project"
12
+ gem.authors = ["Josh Nesbitt"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.executables << 'project'
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+ task :default => :spec
35
+
36
+ require 'rake/rdoctask'
37
+ Rake::RDocTask.new do |rdoc|
38
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
39
+
40
+ rdoc.rdoc_dir = 'rdoc'
41
+ rdoc.title = "configurable #{version}"
42
+ rdoc.rdoc_files.include('README*')
43
+ rdoc.rdoc_files.include('lib/**/*.rb')
44
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.8.0
data/bin/project ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/ruby
2
+ require 'project'
3
+
4
+ runner = Project::Runner.new(ARGV[0])
5
+ runner.run!
@@ -0,0 +1,8 @@
1
+ # Core extensions
2
+
3
+ class OpenStruct
4
+
5
+ def [](key)
6
+ self.send key
7
+ end
8
+ end
@@ -0,0 +1,18 @@
1
+ module Project
2
+
3
+ class ProjectError < StandardError
4
+ attr_accessor :data
5
+
6
+ def initialize(data)
7
+ self.data = data
8
+ super
9
+ end
10
+ end
11
+
12
+ class AbstractClassError < ProjectError; end
13
+ class MissingProjectKeyError < ProjectError; end
14
+ class MissingProjectError < ProjectError; end
15
+ class MissingWorkflowError < ProjectError; end
16
+ class MissingTemplateVariable < ProjectError; end
17
+
18
+ end
@@ -0,0 +1,24 @@
1
+ require 'fileutils'
2
+ module Project
3
+ require 'yaml'
4
+
5
+ class Loader
6
+ class << self
7
+ def config_path(path=nil)
8
+ path ? (@config_path = path) : @config_path
9
+ end
10
+ end
11
+
12
+ def load!
13
+ if File.exists?(self.class.config_path)
14
+ config = YAML.load_file(self.class.config_path)
15
+ Project.load_from_hash(config[:projects]) unless config[:projects].nil?
16
+ Workflow.load_from_hash(config[:workflows]) unless config[:workflows].nil?
17
+ else
18
+ FileUtils.cp(ROOT + "/templates/example.yml", self.class.config_path, { :verbose => true })
19
+ $stdout.puts "* No YAML file found at #{self.class.config_path}. One has been created for you, please edit it to your liking and try again."
20
+ Kernel.exit(1)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,32 @@
1
+ module Project
2
+ class Lookup
3
+ class << self
4
+
5
+ def store
6
+ @store = {} unless @store
7
+ @store
8
+ end
9
+
10
+ def set(key, data)
11
+ store[key.to_sym] = data
12
+ end
13
+ alias :register :set
14
+
15
+ def get(key)
16
+ store[key.to_sym] ? return_object(store[key.to_sym]) : nil
17
+ end
18
+ alias :find :get
19
+
20
+ def load_from_hash(hash)
21
+ hash.each_pair do |key, data|
22
+ store[key] = data
23
+ end
24
+ end
25
+
26
+ protected
27
+ def return_object(data)
28
+ raise AbstractClassError, "this is an abstract class method and should not be called directly."
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,13 @@
1
+ module Project
2
+ require 'ostruct'
3
+
4
+ class Project < Lookup
5
+ class << self
6
+
7
+ protected
8
+ def return_object(data)
9
+ OpenStruct.new(data)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,34 @@
1
+ module Project
2
+ class Runner
3
+ attr_accessor :key, :project, :workflow
4
+
5
+ def initialize(key)
6
+ exit_with "No project key given" if key.nil?
7
+ self.key = key.chomp.to_sym
8
+
9
+ Loader.new.load!
10
+
11
+ self.project = Project.find(self.key)
12
+ exit_with "No project found using key '#{self.key}'" if self.project.nil?
13
+
14
+ self.workflow = Workflow.find(project.workflow)
15
+ exit_with "No workflow found using key '#{self.project.workflow}'" if self.project.nil?
16
+ end
17
+
18
+ def run!
19
+ $stdout.puts "* Opening project '#{self.key}' using workflow '#{self.project.workflow}'"
20
+
21
+ self.workflow.each do |command|
22
+ command = Template.new(command, self.project).parse
23
+
24
+ %x[ #{command} ]
25
+ end
26
+ end
27
+
28
+ private
29
+ def exit_with(message, code=1)
30
+ $stdout.puts message
31
+ Kernel.exit(code)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ module Project
2
+ class Template
3
+ attr_accessor :subject, :replacements
4
+ REGEX = /%([a-z|A-Z]*)?/
5
+
6
+ def initialize(subject, replacements)
7
+ self.subject = subject
8
+ self.replacements = replacements
9
+ end
10
+
11
+ def parse
12
+ matches = self.subject.scan(REGEX)
13
+ matches.flatten!
14
+
15
+ matches.each do |match|
16
+ raise MissingTemplateVariable, "No variable named %#{match} was specified in the project #{self.key}" if replacements[match].nil?
17
+ self.subject.gsub!("%#{match}", replacements[match])
18
+ end
19
+
20
+ self.subject
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ module Project
2
+ class Workflow < Lookup
3
+ class << self
4
+
5
+ protected
6
+ def return_object(data)
7
+ data
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/project.rb ADDED
@@ -0,0 +1,17 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ $:.unshift File.join(File.dirname(__FILE__), "project")
3
+
4
+ module Project
5
+ ROOT = File.expand_path(File.dirname(__FILE__) + "/..")
6
+ end
7
+
8
+ require 'core_ext'
9
+ require 'errors'
10
+ require 'template'
11
+ require 'lookup'
12
+ require 'workflow'
13
+ require 'project'
14
+ require 'loader'
15
+ require 'runner'
16
+
17
+ Project::Loader.config_path(ENV["HOME"] + "/.project")
data/project.gemspec ADDED
@@ -0,0 +1,65 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{project}
8
+ s.version = "0.8.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Josh Nesbitt"]
12
+ s.date = %q{2010-08-19}
13
+ s.description = %q{}
14
+ s.email = %q{josh@josh-nesbitt.net}
15
+ s.executables = ["project", "project"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "LICENSE",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "bin/project",
25
+ "lib/project.rb",
26
+ "lib/project/core_ext.rb",
27
+ "lib/project/errors.rb",
28
+ "lib/project/loader.rb",
29
+ "lib/project/lookup.rb",
30
+ "lib/project/project.rb",
31
+ "lib/project/runner.rb",
32
+ "lib/project/template.rb",
33
+ "lib/project/workflow.rb",
34
+ "project.gemspec",
35
+ "readme.rdoc",
36
+ "spec/lib/lookup_spec.rb",
37
+ "spec/spec_helper.rb",
38
+ "spec/watch.rb",
39
+ "templates/example.yml"
40
+ ]
41
+ s.homepage = %q{http://github.com/joshnesbitt/project}
42
+ s.rdoc_options = ["--charset=UTF-8"]
43
+ s.require_paths = ["lib"]
44
+ s.rubygems_version = %q{1.3.7}
45
+ s.summary = %q{A streamlined approach to working with multiple projects and tasks.}
46
+ s.test_files = [
47
+ "spec/lib/lookup_spec.rb",
48
+ "spec/spec_helper.rb",
49
+ "spec/watch.rb"
50
+ ]
51
+
52
+ if s.respond_to? :specification_version then
53
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
+ s.specification_version = 3
55
+
56
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
58
+ else
59
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
63
+ end
64
+ end
65
+
data/readme.rdoc ADDED
@@ -0,0 +1,46 @@
1
+ = Project
2
+
3
+ * Overview
4
+ * Installation
5
+ * Usage
6
+ * Bugs
7
+ * Note on Patches/Pull Requests
8
+
9
+
10
+ == Overview
11
+
12
+
13
+
14
+ == Installation
15
+
16
+ The project is hosted on rubygems.org. Getting it is simple:
17
+
18
+ gem install project
19
+
20
+ # Install notes
21
+
22
+ == Usage
23
+
24
+
25
+
26
+ == Bugs
27
+
28
+ If you have any problems with Project, please file an issue at http://github.com/joshnesbitt/project/issues.
29
+
30
+
31
+
32
+ == Note on Patches/Pull Requests
33
+
34
+ * Fork the project.
35
+ * Make your feature addition or bug fix.
36
+ * Add tests for it. This is important so I don't break it in a
37
+ future version unintentionally.
38
+ * Commit, do not mess with rakefile, version, or history.
39
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
40
+ * Send me a pull request. Bonus points for topic branches.
41
+
42
+
43
+
44
+ == Copyright
45
+
46
+ Copyright (c) 2010 Josh Nesbitt <josh@josh-nesbitt.net>. See LICENSE for details.
@@ -0,0 +1,23 @@
1
+ module Project
2
+ describe Lookup do
3
+
4
+ before do
5
+ @data = { :age => 20 }
6
+ end
7
+
8
+ it "should use a hash as a lookup object" do
9
+ Lookup.store.class.should == Hash
10
+ end
11
+
12
+ it "should set a lookup key correctly" do
13
+
14
+ Lookup.set(:bob, @data)
15
+ Lookup.store[:bob].should == @data
16
+ end
17
+
18
+ it "raise an abstract class error on trying to get a key" do
19
+ Lookup.set(:bob, @data)
20
+ lambda { Lookup.get(:bob) }.should raise_error(AbstractClassError)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'project'
4
+ require 'spec'
data/spec/watch.rb ADDED
@@ -0,0 +1,28 @@
1
+ # A simple alternative to autotest that isnt as painful
2
+
3
+ options = {
4
+ :options => "--require '#{File.expand_path(File.dirname(__FILE__)) + "/spec_helper"}' --format nested --color",
5
+ :binary => "spec"
6
+ }
7
+
8
+ watch("(lib|spec)/(.*)\.rb") do |match|
9
+ puts %x[ clear ]
10
+
11
+ file = match[match.size - 1]
12
+ opts = options[:options]
13
+ binary = options[:binary]
14
+
15
+ files = []
16
+
17
+ ["spec/lib/*.rb", "spec/lib/*/*.rb"].each do |glob|
18
+ Dir.glob(glob).each { |f| files << f }
19
+ end
20
+
21
+ puts "Found:"
22
+ files.each { |f| puts "+ #{f}" }
23
+ puts ""
24
+ command = "#{binary} #{files.collect! { |f| File.expand_path(f) }.join(" ")} #{opts}"
25
+
26
+ system(command)
27
+
28
+ end
@@ -0,0 +1,7 @@
1
+ :workflows:
2
+ :default:
3
+ - mate %path
4
+ :projects:
5
+ :example:
6
+ :path: /a/path
7
+ :workflow: default
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: project
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 8
8
+ - 0
9
+ version: 0.8.0
10
+ platform: ruby
11
+ authors:
12
+ - Josh Nesbitt
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-19 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 2
31
+ - 9
32
+ version: 1.2.9
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: ""
36
+ email: josh@josh-nesbitt.net
37
+ executables:
38
+ - project
39
+ - project
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - LICENSE
44
+ files:
45
+ - .gitignore
46
+ - LICENSE
47
+ - Rakefile
48
+ - VERSION
49
+ - bin/project
50
+ - lib/project.rb
51
+ - lib/project/core_ext.rb
52
+ - lib/project/errors.rb
53
+ - lib/project/loader.rb
54
+ - lib/project/lookup.rb
55
+ - lib/project/project.rb
56
+ - lib/project/runner.rb
57
+ - lib/project/template.rb
58
+ - lib/project/workflow.rb
59
+ - project.gemspec
60
+ - readme.rdoc
61
+ - spec/lib/lookup_spec.rb
62
+ - spec/spec_helper.rb
63
+ - spec/watch.rb
64
+ - templates/example.yml
65
+ has_rdoc: true
66
+ homepage: http://github.com/joshnesbitt/project
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --charset=UTF-8
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ requirements: []
91
+
92
+ rubyforge_project:
93
+ rubygems_version: 1.3.7
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: A streamlined approach to working with multiple projects and tasks.
97
+ test_files:
98
+ - spec/lib/lookup_spec.rb
99
+ - spec/spec_helper.rb
100
+ - spec/watch.rb