engage 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -15,15 +15,21 @@ Engage aims to provide a single command to run all those tasks. All you need to
15
15
  ### Usage
16
16
  First, you can set your common git servers - the default list include only `git@github.com`.
17
17
 
18
- engage --sources git@git.acme.com
18
+ engage add git@git.acme.com
19
19
 
20
20
  After that you can start a project by just running:
21
21
 
22
- engage some_project
22
+ engage init some_project
23
23
 
24
- Behind the curtains, engage will:
24
+ Behind the curtains, engage will:
25
25
 
26
26
  * Prompt the git server to use - either "github.com" or "acme.com";
27
27
  * Clone the some_project repository form the selected server - `git@git.acme.com/some_project.git`;
28
28
  * Create a gemset name `some_project` and a .rvmrc file;
29
- * Run bundler to install all the dependencies.
29
+ * Run bundler to install all the dependencies.
30
+
31
+ ### Available Commands
32
+
33
+ engage init [PROJECT] # init a new project from one of the registered sources
34
+ engage add [SOURCE] # register the given source to `~/.engage.sources`
35
+ engage list # list all the registered sources
data/lib/engage.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  require 'yaml'
2
2
  require 'thor'
3
- require 'thor/group'
4
3
 
5
- require 'engage/core_ext/blank'
6
4
  require 'engage/runner'
@@ -0,0 +1,52 @@
1
+ module Engage
2
+ module Actions
3
+ include Thor::Actions
4
+
5
+ def clone_repo
6
+ source = ask_for_source
7
+ run "git clone #{source}:#{project}.git"
8
+ end
9
+
10
+ def setup_rvm
11
+ create_gemset
12
+ create_rvmrc
13
+ trust_rvmrc
14
+ end
15
+
16
+ def create_gemset
17
+ run "rvm gemset create #{folder_name}"
18
+ end
19
+
20
+ def create_rvmrc
21
+ create_file "#{folder_name}/.rvmrc", rvm_env
22
+ end
23
+
24
+ def trust_rvmrc
25
+ run "rvm rvmrc trust #{folder_name}"
26
+ end
27
+
28
+ def run_bundler
29
+ run "cd #{folder_name} && #{rvm_env} exec bundle"
30
+ end
31
+
32
+ protected
33
+
34
+ def ask_for_source
35
+ return sources.first if sources.size == 1
36
+ list
37
+ sources[ask("Select the git source of '#{folder_name}':").to_i]
38
+ end
39
+
40
+ def rvm_env
41
+ "rvm #{current_ruby}@#{folder_name}"
42
+ end
43
+
44
+ def current_ruby
45
+ `rvm-prompt v`.strip
46
+ end
47
+
48
+ def using_bundler?
49
+ File.exists?(File.join(folder_name, "Gemfile"))
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,31 @@
1
+ module Engage
2
+ module Helpers
3
+
4
+ def folder_name
5
+ project.split("/").last
6
+ end
7
+
8
+ def file_path
9
+ File.join(ENV["HOME"], ".engage.sources")
10
+ end
11
+
12
+ def sources
13
+ File.exists?(file_path) ? YAML.load_file(file_path) : default_sources
14
+ end
15
+
16
+ def sources_table
17
+ sources.each_with_index.map { |line| line.reverse }
18
+ end
19
+
20
+ def default_sources
21
+ ["git@github.com"]
22
+ end
23
+
24
+ def store(source)
25
+ list = sources
26
+ return false if list.include?(source)
27
+ list << source
28
+ File.open(file_path, 'w') { |f| f.write(YAML.dump(list.compact)) }
29
+ end
30
+ end
31
+ end
data/lib/engage/runner.rb CHANGED
@@ -1,88 +1,36 @@
1
+ require 'engage/helpers'
2
+ require 'engage/actions'
3
+
1
4
  module Engage
2
- class Runner < Thor::Group
3
- include Thor::Actions
4
-
5
- argument :name, :optional => true, :desc => "The targeted project name"
6
- class_option :source, :type => :string, :desc => "Adds the given source to the user list."
5
+ class Runner < Thor
6
+ include Engage::Actions
7
+ include Engage::Helpers
7
8
 
8
- def self.banner
9
- "USAGE: engage [project] [--source SOURCE]"
10
- end
11
-
12
- def check_parameters
13
- if name.blank? && options.source.blank?
14
- say self.class.banner
15
- say_status 'quitting...', 'no arguments given.', :red
16
- raise SystemExit
17
- end
18
- end
19
-
20
- def clone_repo
21
- return if adding_source?
22
- source = ask_for_source
23
- run "git clone #{source}:#{name}.git"
24
- end
25
-
26
- def generate_gemset
27
- return if adding_source?
28
- run "rvm gemset create #{project_name}"
29
- create_file "#{project_name}/.rvmrc", selected_ruby
30
- end
31
-
32
- def run_bundler
33
- return if adding_source?
34
- run "cd #{project_name} && #{selected_ruby} exec bundle" if using_bundler?
9
+ attr_accessor :project
10
+
11
+ desc "init [PROJECT]", "init a new project from one of the registered sources"
12
+ def init(project)
13
+ self.project = project
14
+ clone_repo
15
+ setup_rvm
16
+ run_bundler if using_bundler?
35
17
  end
36
-
37
- def store
38
- return unless adding_source?
39
- list = sources
40
- list << options.source
41
- File.open(file_path, 'w') { |f| f.write(YAML.dump(list.uniq.compact)) }
18
+
19
+ desc "list", "list all the registered sources"
20
+ def list
21
+ table = sources_table
22
+ say "Available sources:"
23
+ print_table(table, :colwidth => table.last.first.to_s.size, :ident => 3)
42
24
  end
43
-
44
- no_tasks do
45
- def file_path
46
- File.join(ENV["HOME"], ".engage.sources")
47
- end
48
-
49
- def ask_for_source
50
- return sources.first if sources.size == 1
51
- say "Available git servers:"
52
- sources.each_with_index do |source, index|
53
- say "#{index} => #{source}"
54
- end
55
- sources[ask("Select the server of '#{project_name}':").to_i]
56
- end
57
-
58
- def using_bundler?
59
- File.exists?(File.join(project_name, "Gemfile"))
60
- end
61
-
62
- def project_name
63
- @project_name ||= name.split("/").last
64
- end
65
-
66
- def sources
67
- File.exists?(file_path) ? YAML.load_file(file_path) : default_sources
68
- end
69
-
70
- def default_sources
71
- ["git@github.com"]
72
- end
73
-
74
- def adding_source?
75
- options.source.present?
76
- end
77
-
78
- def rubyversion
79
- `rvm-prompt v`.strip
80
- end
81
-
82
- def selected_ruby
83
- "rvm #{rubyversion}@#{project_name}"
25
+
26
+ desc "add [SOURCE]", "register the given source to `~/.engage.sources`"
27
+ def add(source)
28
+ if store(source)
29
+ say_status 'added source', source, :green
30
+ else
31
+ say_status 'duplicate', source, :red
84
32
  end
85
-
86
33
  end
34
+
87
35
  end
88
36
  end
@@ -1,3 +1,3 @@
1
1
  module Engage
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
data/spec/helpers.rb CHANGED
@@ -1,33 +1,26 @@
1
1
  module Helpers
2
2
 
3
- def run
4
- silenced(:stdout) { subject.invoke_all }
5
- end
6
-
7
3
  def stub_commands
8
4
  subject.stub(:system).and_return(true)
9
5
  end
10
-
11
- def expect(command)
6
+
7
+ def expect_command(command)
12
8
  subject.should_receive(:system).with(command)
13
9
  end
14
10
 
15
- def dont_expect(command)
11
+ def dont_expect_command(command)
16
12
  subject.should_not_receive(:system).with(command)
17
13
  end
18
14
 
19
-
20
15
  def silenced(stream)
21
- begin
22
- stream = stream.to_s
23
- eval "$#{stream} = StringIO.new"
24
- yield
25
- result = eval("$#{stream}").string
26
- ensure
27
- eval("$#{stream} = #{stream.upcase}")
28
- end
29
-
30
- result
16
+ begin
17
+ stream = stream.to_s
18
+ eval "$#{stream} = StringIO.new"
19
+ yield
20
+ result = eval("$#{stream}").string
21
+ ensure
22
+ eval("$#{stream} = #{stream.upcase}")
31
23
  end
32
-
24
+ result
25
+ end
33
26
  end
data/spec/runner_spec.rb CHANGED
@@ -1,104 +1,115 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Engage::Runner do
4
- subject { Engage::Runner.new(["lucasmazza/engage"]) }
5
4
  before { stub_commands }
6
-
7
- context "without parameters" do
8
- subject { Engage::Runner.new([""]) }
9
-
10
- it "outputs the script banner and quits" do
11
- subject.should_receive(:say).with(Engage::Runner.banner)
12
- subject.should_receive(:say_status).with('quitting...', 'no arguments given.', :red)
13
- lambda { run }.should raise_error SystemExit
14
- end
15
- end
16
-
17
- context "Starting projects" do
18
5
 
19
- context "a full featured project" do
6
+ describe "#init" do
7
+ context "with a full featured project" do
20
8
  before do
21
9
  subject.stub(:using_bundler?) { true }
22
10
  end
23
- it "clones the given github repository" do
24
- expect "git clone git@github.com:lucasmazza/engage.git"
25
- run
11
+
12
+ it "clones the git repository" do
13
+ expect_command "git clone git@github.com:lucasmazza/engage.git"
14
+ subject.init('lucasmazza/engage')
26
15
  end
27
-
28
- it "creates a gemset based on the project name" do
29
- expect "rvm gemset create engage"
30
- run
16
+
17
+ it "creates a gemset with the project name" do
18
+ expect_command "rvm gemset create engage"
19
+ subject.init('lucasmazza/engage')
31
20
  end
32
-
33
- it "creates a rvmrc file on the project directory" do
34
- run
35
- File.exists?("engage/.rvmrc").should be_true
21
+
22
+ it "creates a `.rvmrc` file" do
23
+ subject.init('cyberdyne/skynet')
24
+ File.exists?("skynet/.rvmrc").should be_true
36
25
  end
37
-
38
- it "runs bundler command" do
39
- expect "cd engage && #{subject.selected_ruby} exec bundle"
40
- run
26
+
27
+ it "trusts the created `.rvmrc` file" do
28
+ expect_command "rvm rvmrc trust skynet"
29
+ subject.init("cyberdyne/skynet")
41
30
  end
42
-
43
- it "doesn't ask for a git source" do
44
- subject.should_not_receive(:ask).with("Select the server of 'rails':")
45
- run
31
+
32
+ it "runs the `bundle` command" do
33
+ expect_command "cd skynet && rvm 1.8.7@skynet exec bundle"
34
+ subject.init("cyberdyne/skynet")
46
35
  end
47
36
  end
48
-
37
+
49
38
  context "a project without a gemfile" do
50
39
  before do
51
40
  subject.stub(:using_bundler?) { false }
52
41
  end
53
42
 
54
- it "doesn't run the bundler command" do
55
- dont_expect "cd engage && #{subject.selected_ruby} exec bundle"
56
- run
43
+ it "doesn't run the `bundle` command" do
44
+ dont_expect_command "cd oldapp && rvm 1.8.7@oldapp exec bundle"
45
+ subject.init('oldstuff/oldapp')
46
+ end
47
+ end
48
+
49
+ context "when there's only one available source" do
50
+ it "doesn't ask the user to select a source" do
51
+ subject.should_not_receive(:ask).with("Select the git source of 'rails':")
52
+ subject.init("rails/rails")
57
53
  end
58
54
  end
59
-
60
- context "a project from another git server" do
61
- subject { Engage::Runner.new(["random_company_project"]) }
62
55
 
56
+ context "when there's more than one available source" do
63
57
  before do
64
- subject.stub(:sources) { ["foo@bar.com", "git@acme.com"] }
65
- subject.stub(:ask) { "1" }
58
+ subject.add('git@omgwtfbbq.com')
59
+ subject.stub(:ask) { 1 }
66
60
  end
67
-
68
- it "asks for the selected git source" do
69
- subject.should_receive(:ask).with("Select the server of 'random_company_project':")
70
- run
61
+
62
+ it "outputs the available sources" do
63
+ subject.should_receive(:list)
64
+ subject.init('rails/rails')
65
+ end
66
+
67
+ it "asks the user to select one source" do
68
+ subject.should_receive(:ask).with("Select the git source of 'rails':")
69
+ subject.init('rails/rails')
71
70
  end
72
71
 
73
- it "clones the repo from the selected server" do
74
- expect "git clone git@acme.com:random_company_project.git"
75
- run
72
+ it "clones from the selected source" do
73
+ expect_command "git clone git@omgwtfbbq.com:rails/rails.git"
74
+ subject.init('rails/rails')
76
75
  end
77
76
  end
78
77
  end
79
- context "with the --source option" do
80
78
 
81
- context "when passing a new source" do
82
- subject { Engage::Runner.new(["wrong"], :source => "git@acme.com") }
79
+ describe "#list" do
80
+ it "prints a banner" do
81
+ subject.should_receive(:say).with('Available sources:')
82
+ subject.list
83
+ end
84
+
85
+ it "outputs all the registered sources" do
86
+ subject.should_receive(:print_table)
87
+ subject.list
88
+ end
89
+ end
83
90
 
84
- it "doesn't trigger any system call" do
85
- subject.should_not_receive(:system)
86
- run
91
+ describe "#add" do
92
+ context "when the source isn't registered" do
93
+ it "registers the given source" do
94
+ expect { subject.add("git@acme.com") }.to change(subject, :sources)
87
95
  end
88
- it "adds the given source to the list" do
89
- run
90
- subject.sources.should include("git@acme.com")
96
+
97
+ it "outputs a confirmation message" do
98
+ subject.should_receive(:say_status).with('added source', 'git@acme.com', :green)
99
+ subject.add("git@acme.com")
91
100
  end
92
101
  end
93
-
94
- context "when passing an already existent source" do
95
- subject { Engage::Runner.new([], :source => "git@github.com") }
96
102
 
97
- it "doesn't duplicate the sources" do
98
- run
99
- subject.should have(1).sources
103
+ context "when the source is duplicate" do
104
+ before { subject.add("git@mycompany.com") }
105
+ it "doesn't register the given source" do
106
+ expect { subject.add("git@mycompany.com") }.to_not change(subject, :sources)
107
+ end
108
+
109
+ it "outputs a warnning message" do
110
+ subject.should_receive(:say_status).with('duplicate', 'git@mycompany.com', :red)
111
+ subject.add("git@mycompany.com")
100
112
  end
101
113
  end
102
-
103
114
  end
104
115
  end
data/spec/spec_helper.rb CHANGED
@@ -7,5 +7,8 @@ require 'helpers'
7
7
  RSpec.configure do |config|
8
8
  config.include Helpers
9
9
  config.include FakeFS::SpecHelpers
10
- end
11
10
 
11
+ config.around(:each) do |example|
12
+ silenced(:stdout) { example.run }
13
+ end
14
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: engage
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
4
+ hash: 27
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 6
10
- version: 0.0.6
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Lucas Mazza
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-26 00:00:00 -02:00
18
+ date: 2011-01-16 00:00:00 -02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -94,7 +94,8 @@ files:
94
94
  - bin/engage
95
95
  - engage.gemspec
96
96
  - lib/engage.rb
97
- - lib/engage/core_ext/blank.rb
97
+ - lib/engage/actions.rb
98
+ - lib/engage/helpers.rb
98
99
  - lib/engage/runner.rb
99
100
  - lib/engage/version.rb
100
101
  - spec/helpers.rb
@@ -132,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
133
  requirements: []
133
134
 
134
135
  rubyforge_project: engage
135
- rubygems_version: 1.3.7
136
+ rubygems_version: 1.4.1
136
137
  signing_key:
137
138
  specification_version: 3
138
139
  summary: Quick setup for your ruby apps
@@ -1,50 +0,0 @@
1
- # https://github.com/rails/rails/blob/87ae85d5360ac8965f24/activesupport/lib/active_support/core_ext/object/blank.rb
2
- class Object #:nodoc:
3
- def blank?
4
- respond_to?(:empty?) ? empty? : !self
5
- end
6
- def present?
7
- !blank?
8
- end
9
- def presence
10
- self if present?
11
- end
12
- end
13
-
14
- class NilClass #:nodoc:
15
- def blank?
16
- true
17
- end
18
- end
19
-
20
- class FalseClass #:nodoc:
21
- def blank?
22
- true
23
- end
24
- end
25
-
26
- class TrueClass #:nodoc:
27
- def blank?
28
- false
29
- end
30
- end
31
-
32
- class Array #:nodoc:
33
- alias_method :blank?, :empty?
34
- end
35
-
36
- class Hash #:nodoc:
37
- alias_method :blank?, :empty?
38
- end
39
-
40
- class String #:nodoc:
41
- def blank?
42
- self !~ /\S/
43
- end
44
- end
45
-
46
- class Numeric #:nodoc:
47
- def blank?
48
- false
49
- end
50
- end