rplug 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Manifest.txt +7 -0
- data/README.txt +48 -0
- data/Rakefile +21 -0
- data/bin/rplug +6 -0
- data/lib/rplug.rb +130 -0
- data/test/test_rplug.rb +127 -0
- metadata +60 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
rplug
|
2
|
+
by FIX (your name)
|
3
|
+
FIX (url)
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
FIX (describe your package)
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* FIX (list of features or problems)
|
12
|
+
|
13
|
+
== SYNOPSYS:
|
14
|
+
|
15
|
+
FIX (code sample of usage)
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* FIX (list of requirements)
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* FIX (sudo gem install, anything else)
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) 2006 FIX
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/rplug.rb'
|
6
|
+
|
7
|
+
Hoe.new('rplug', Rplug::VERSION) do |p|
|
8
|
+
p.rubyforge_name = 'rplug'
|
9
|
+
# p.summary = 'FIX'
|
10
|
+
# p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
11
|
+
# p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
12
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Run rcov coverage report'
|
16
|
+
task :rcov do
|
17
|
+
system "rm -rf coverage"
|
18
|
+
system "rcov -Ilib test/test_*.rb"
|
19
|
+
end
|
20
|
+
|
21
|
+
# vim: syntax=Ruby
|
data/bin/rplug
ADDED
data/lib/rplug.rb
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'yaml'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'source_control'
|
5
|
+
|
6
|
+
class Rplug
|
7
|
+
VERSION = "0.0.1"
|
8
|
+
|
9
|
+
def initialize(path)
|
10
|
+
path_parts = path.split(File::SEPARATOR)
|
11
|
+
begin
|
12
|
+
file = (path_parts+['config','environment.rb']).join(File::SEPARATOR)
|
13
|
+
break if File.exist?(file)
|
14
|
+
end while path_parts.pop
|
15
|
+
raise "Could not find rails project directory" if path_parts.empty?
|
16
|
+
|
17
|
+
@rails_root = path_parts.join(File::SEPARATOR)
|
18
|
+
end
|
19
|
+
|
20
|
+
def do_install
|
21
|
+
name = args.shift
|
22
|
+
scm = args.shift
|
23
|
+
uri = args.shift
|
24
|
+
@config[name] = {'scm' => scm, 'uri' => uri, 'revision' => 0}
|
25
|
+
log "Recorded #{name}, run 'rplug update' to pull the latest revision"
|
26
|
+
end
|
27
|
+
|
28
|
+
def do_status
|
29
|
+
dirs = Dir.entries('.') - ['.', '..']
|
30
|
+
log "Managing the following plugins:"
|
31
|
+
@config.sort_by{|p|p.first}.each do |name, plugin|
|
32
|
+
dirs.delete name
|
33
|
+
log " #{name}, revision #{plugin['revision']}"
|
34
|
+
end
|
35
|
+
unless dirs.empty?
|
36
|
+
log "Not Managing the following plugins:"
|
37
|
+
dirs.each {|dir| log " #{dir}"}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def do_update(opts = {})
|
42
|
+
if opts[:plugin]
|
43
|
+
update_plugin(opts)
|
44
|
+
else
|
45
|
+
@config.each_key do |name|
|
46
|
+
update_plugin(:plugin => name)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def load_config
|
52
|
+
config_file = "#{@rails_root}/config/plugins.yml"
|
53
|
+
@config = if File.exist?(config_file)
|
54
|
+
YAML.load(File.read(config_file))
|
55
|
+
else
|
56
|
+
{}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def log(msg)
|
61
|
+
puts msg
|
62
|
+
end
|
63
|
+
|
64
|
+
def run(args)
|
65
|
+
log "Working in project dir #{@rails_root}"
|
66
|
+
load_config
|
67
|
+
|
68
|
+
Dir.chdir(([@rails_root,'vendor','plugins']).join(File::SEPARATOR))
|
69
|
+
|
70
|
+
case args.shift
|
71
|
+
when /^st(atus)?$/ :
|
72
|
+
do_status
|
73
|
+
when /^up(date)?$/ :
|
74
|
+
options = {}
|
75
|
+
OptionParser.new do |opts|
|
76
|
+
opts.on("-p", "--plugin NAME", "Operate on a single plugin") do |plugin|
|
77
|
+
options[:plugin] = plugin
|
78
|
+
opts.on("-r", "--revision REV", "Specify a specific revision") do |rev|
|
79
|
+
options[:revision] = rev.to_i
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end.parse!(args)
|
83
|
+
do_update(options)
|
84
|
+
when /^install$/ :
|
85
|
+
do_install(args)
|
86
|
+
end
|
87
|
+
|
88
|
+
save_config
|
89
|
+
end
|
90
|
+
|
91
|
+
def save_config
|
92
|
+
config_file = "#{@rails_root}/config/plugins.yml"
|
93
|
+
File.open(config_file, 'w') do |f|
|
94
|
+
f << YAML.dump(@config)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def update_plugin(opts)
|
99
|
+
name = opts[:plugin]
|
100
|
+
plugin = @config[name]
|
101
|
+
|
102
|
+
plugin_repository = SourceControl.find(plugin['scm']).new(:remote_uri => plugin['uri'])
|
103
|
+
working_copy = SourceControl.new(Dir.pwd)
|
104
|
+
|
105
|
+
log "Updating #{name}..."
|
106
|
+
|
107
|
+
if opts[:revision]
|
108
|
+
revision = opts[:revision]
|
109
|
+
else
|
110
|
+
revision = plugin_repository.last_changed_revision
|
111
|
+
revision = nil if revision <= plugin['revision']
|
112
|
+
end
|
113
|
+
if revision
|
114
|
+
log " upgrading to revision #{revision}"
|
115
|
+
system("rm -rf #{name}") # TODO: Refactor out
|
116
|
+
plugin_repository.export(:dir => name, :revision => revision)
|
117
|
+
plugin['revision'] = revision
|
118
|
+
|
119
|
+
log " updating local repository"
|
120
|
+
status = working_copy.status(Dir.pwd + File::Separator + name)
|
121
|
+
status[:unknown].each do |file|
|
122
|
+
working_copy.add(file)
|
123
|
+
end
|
124
|
+
status[:missing].each do |file|
|
125
|
+
working_copy.remove(file)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
log " Done."
|
129
|
+
end
|
130
|
+
end
|
data/test/test_rplug.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'rplug'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
class Rplug
|
7
|
+
attr_accessor :config, :rails_root
|
8
|
+
def log(msg); end # skip output of log messages for test
|
9
|
+
end
|
10
|
+
|
11
|
+
class TestRplug < Test::Unit::TestCase
|
12
|
+
def test_initialize_should_check_for_rails_root
|
13
|
+
File.expects(:exist?).
|
14
|
+
with('/foo/bar/baz/config/environment.rb').
|
15
|
+
returns(false)
|
16
|
+
File.expects(:exist?).
|
17
|
+
with('/foo/bar/config/environment.rb').
|
18
|
+
returns(true).
|
19
|
+
times(2)
|
20
|
+
|
21
|
+
r = Rplug.new('/foo/bar')
|
22
|
+
assert_equal '/foo/bar', r.rails_root
|
23
|
+
r2 = Rplug.new('/foo/bar/baz')
|
24
|
+
assert_equal '/foo/bar', r.rails_root
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_initialize_should_raise_exception_if_no_rails_found
|
28
|
+
File.expects(:exist?).with('/foo/config/environment.rb').returns(false)
|
29
|
+
File.expects(:exist?).with('/config/environment.rb').returns(false)
|
30
|
+
File.expects(:exist?).with('config/environment.rb').returns(false)
|
31
|
+
assert_raise RuntimeError do
|
32
|
+
Rplug.new('/foo')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class TestRplugWithStubbedInit < Test::Unit::TestCase
|
38
|
+
def setup
|
39
|
+
File.stubs(:exist?).with('/foo/config/environment.rb').returns(true)
|
40
|
+
Dir.stubs(:chdir)
|
41
|
+
@r = Rplug.new('/foo')
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_run
|
45
|
+
@r.expects(:load_config)
|
46
|
+
@r.expects(:save_config)
|
47
|
+
@r.run ['']
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_load_config_returns_empty_hash_if_config_file_doesnt_exist
|
51
|
+
options = {}
|
52
|
+
File.expects(:exist?).with('/foo/config/plugins.yml').returns(false)
|
53
|
+
@r.load_config
|
54
|
+
assert_equal options, @r.config
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_load_config_returns_config_if_config_file_exists
|
58
|
+
options = {:a => :b}
|
59
|
+
File.expects(:exist?).with('/foo/config/plugins.yml').returns(true)
|
60
|
+
File.expects(:read).with('/foo/config/plugins.yml').returns(YAML.dump(options))
|
61
|
+
@r.load_config
|
62
|
+
assert_equal options, @r.config
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_save_config_writes_yamlized_config
|
66
|
+
config = {:a => :b}
|
67
|
+
output = ""
|
68
|
+
output.expects(:<<).with(YAML.dump(config))
|
69
|
+
File.expects(:open).with('/foo/config/plugins.yml', 'w').yields(output)
|
70
|
+
@r.config = config
|
71
|
+
@r.save_config
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class TestRplugWithStubbedInitAndConfigs < Test::Unit::TestCase
|
76
|
+
def setup
|
77
|
+
File.stubs(:exist?).with('/foo/config/environment.rb').returns(true)
|
78
|
+
Dir.stubs(:chdir)
|
79
|
+
@r = Rplug.new('/foo')
|
80
|
+
@r.stubs(:load_config)
|
81
|
+
@r.stubs(:save_config)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_unit_needs_tests; end
|
85
|
+
end
|
86
|
+
|
87
|
+
class TestRplugRun < TestRplugWithStubbedInitAndConfigs
|
88
|
+
def test_run_calls_do_methods
|
89
|
+
@r.expects(:do_status)
|
90
|
+
@r.run %w(status)
|
91
|
+
|
92
|
+
@r.expects(:do_update)
|
93
|
+
@r.run %w(update)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_run_calls_do_methods_with_options
|
97
|
+
@r.expects(:do_update).with(:plugin => 'arts')
|
98
|
+
@r.run %w(update -p arts)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_run_calls_do_methods_with_many_options
|
102
|
+
@r.expects(:do_update).with(:plugin => 'arts', :revision => 5)
|
103
|
+
@r.run %w(update -p arts -r 5)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class TestRplugDoUpdate < TestRplugWithStubbedInitAndConfigs
|
108
|
+
def test_do_update_calls_multiple_update_plugin
|
109
|
+
@r.config = {'arts' => {}, 'mocha' => {}}
|
110
|
+
@r.expects(:update_plugin).with(:plugin => 'arts')
|
111
|
+
@r.expects(:update_plugin).with(:plugin => 'mocha')
|
112
|
+
@r.do_update
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_do_update_with_plugin_calls_one_update_plugin
|
116
|
+
opts = {:plugin => 'arts'}
|
117
|
+
@r.expects(:update_plugin).with(opts)
|
118
|
+
@r.do_update(opts)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_do_update_with_plugin_calls_update_plugin_with_revision
|
122
|
+
opts = {:plugin => 'arts', :revision => 5}
|
123
|
+
@r.expects(:update_plugin).with(opts)
|
124
|
+
@r.do_update(opts)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.2
|
3
|
+
specification_version: 1
|
4
|
+
name: rplug
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2007-02-17 00:00:00 -08:00
|
8
|
+
summary: The author was too lazy to write a summary
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: ryand-ruby@zenspider.com
|
12
|
+
homepage: http://www.zenspider.com/ZSS/Products/rplug/
|
13
|
+
rubyforge_project: rplug
|
14
|
+
description: The author was too lazy to write a description
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Ryan Davis
|
31
|
+
files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
- Rakefile
|
36
|
+
- bin/rplug
|
37
|
+
- lib/rplug.rb
|
38
|
+
- test/test_rplug.rb
|
39
|
+
test_files:
|
40
|
+
- test/test_rplug.rb
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
executables:
|
46
|
+
- rplug
|
47
|
+
extensions: []
|
48
|
+
|
49
|
+
requirements: []
|
50
|
+
|
51
|
+
dependencies:
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: hoe
|
54
|
+
version_requirement:
|
55
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 1.2.0
|
60
|
+
version:
|