aiwilliams-plugit 0.0.1 → 0.0.2
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/lib/plugit.rb +4 -1
- data/lib/plugit/descriptor.rb +16 -4
- data/lib/plugit/environment.rb +7 -11
- data/lib/plugit/library.rb +35 -12
- data/plugit.gemspec +1 -1
- metadata +2 -2
data/lib/plugit.rb
CHANGED
@@ -4,8 +4,11 @@ require File.dirname(__FILE__) + '/plugit/descriptor'
|
|
4
4
|
|
5
5
|
module Plugit
|
6
6
|
def self.describe(&block)
|
7
|
+
ENV['PLUGIT_ENV'] ||= 'default'
|
7
8
|
descriptor = Descriptor.new
|
8
9
|
block.call(descriptor)
|
9
|
-
descriptor.install_environment(ENV['PLUGIT_ENV']
|
10
|
+
descriptor.install_environment(ENV['PLUGIT_ENV'])
|
11
|
+
rescue UndefinedEnvironmentError
|
12
|
+
puts %Q{No environment named "#{ENV['PLUGIT_ENV']}". Use one of #{descriptor.environments.collect {|e| e.name.to_s}.inspect}.}
|
10
13
|
end
|
11
14
|
end
|
data/lib/plugit/descriptor.rb
CHANGED
@@ -1,19 +1,31 @@
|
|
1
1
|
module Plugit
|
2
|
+
class UndefinedEnvironmentError < StandardError; end
|
3
|
+
|
2
4
|
class Descriptor
|
3
|
-
attr_writer :
|
5
|
+
attr_writer :environments_root_path
|
4
6
|
|
5
7
|
def initialize
|
6
8
|
@environments = []
|
7
9
|
end
|
8
10
|
|
11
|
+
def [](env_name)
|
12
|
+
@environments.detect {|e|e.name == env_name}
|
13
|
+
end
|
14
|
+
|
9
15
|
def environment(*init_args, &block)
|
16
|
+
init_args << File.expand_path(@environments_root_path || 'environments')
|
10
17
|
@environments << (env = Environment.new(*init_args))
|
11
18
|
block.call(EnvironmentBuilder.new(env))
|
19
|
+
env
|
20
|
+
end
|
21
|
+
|
22
|
+
def environments
|
23
|
+
@environments.dup
|
12
24
|
end
|
13
25
|
|
14
26
|
def install_environment(name)
|
15
|
-
Environment.library_root_path = @library_root_path || File.expand_path('environments')
|
16
27
|
env = @environments.detect {|e| e.name == name.to_sym}
|
28
|
+
raise UndefinedEnvironmentError.new(name) unless env
|
17
29
|
env.libraries.each do |lib|
|
18
30
|
lib.update(env)
|
19
31
|
lib.install(env)
|
@@ -26,8 +38,8 @@ module Plugit
|
|
26
38
|
@env = env
|
27
39
|
end
|
28
40
|
|
29
|
-
def library(*init_args)
|
30
|
-
@env.add_library(Library.new(*init_args))
|
41
|
+
def library(*init_args, &block)
|
42
|
+
@env.add_library(Library.new(*init_args, &block))
|
31
43
|
end
|
32
44
|
end
|
33
45
|
end
|
data/lib/plugit/environment.rb
CHANGED
@@ -1,18 +1,16 @@
|
|
1
1
|
module Plugit
|
2
2
|
class Environment
|
3
|
-
class UninitializedRootError < StandardError; end
|
4
|
-
|
5
|
-
class << self
|
6
|
-
attr_accessor :library_root_path
|
7
|
-
end
|
8
|
-
|
9
3
|
attr_reader :name, :description
|
10
4
|
|
11
|
-
def initialize(name, description)
|
12
|
-
@name, @description = name, description
|
5
|
+
def initialize(name, description, root_path)
|
6
|
+
@name, @description, @root_path = name, description, root_path
|
13
7
|
@libraries = []
|
14
8
|
end
|
15
9
|
|
10
|
+
def [](library_name)
|
11
|
+
@libraries.detect {|l|l.name == library_name}
|
12
|
+
end
|
13
|
+
|
16
14
|
def add_library(library)
|
17
15
|
@libraries << library
|
18
16
|
end
|
@@ -22,9 +20,7 @@ module Plugit
|
|
22
20
|
end
|
23
21
|
|
24
22
|
def library_root_path
|
25
|
-
root_path
|
26
|
-
raise UninitializedRootError unless root_path
|
27
|
-
File.join(root_path, name.to_s)
|
23
|
+
File.join(@root_path, name.to_s)
|
28
24
|
end
|
29
25
|
end
|
30
26
|
end
|
data/lib/plugit/library.rb
CHANGED
@@ -5,12 +5,14 @@ module Plugit
|
|
5
5
|
include FileUtils
|
6
6
|
|
7
7
|
attr_accessor :load_paths, :requires
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :configuration, :name
|
9
9
|
|
10
|
-
def initialize(name,
|
11
|
-
@name
|
12
|
-
@
|
13
|
-
@
|
10
|
+
def initialize(name, configuration = {})
|
11
|
+
@name = name
|
12
|
+
@configuration = configuration
|
13
|
+
@load_paths ||= ['/lib']
|
14
|
+
@requires ||= []
|
15
|
+
|
14
16
|
yield self if block_given?
|
15
17
|
end
|
16
18
|
|
@@ -18,15 +20,37 @@ module Plugit
|
|
18
20
|
@after_update = block
|
19
21
|
end
|
20
22
|
|
23
|
+
def before_install(&block)
|
24
|
+
@before_install = block
|
25
|
+
end
|
26
|
+
|
21
27
|
def checkout(target_path)
|
22
|
-
command = "#{
|
28
|
+
command = "#{export} #{target_path}"
|
23
29
|
puts "Checking out #{name}: #{command}"
|
24
30
|
`#{command}`
|
25
31
|
end
|
26
32
|
|
27
33
|
def install(environment)
|
28
|
-
|
29
|
-
|
34
|
+
target_path = self.target_path(environment)
|
35
|
+
cd(target_path) do
|
36
|
+
instance_eval(&@before_install)
|
37
|
+
end if @before_install
|
38
|
+
load_paths.reverse.each { |l| $LOAD_PATH.unshift File.join(target_path, l) }
|
39
|
+
requires.each { |r| Object.send :require, r }
|
40
|
+
end
|
41
|
+
|
42
|
+
def method_missing(method, *args)
|
43
|
+
if value = @configuration[method.to_sym]
|
44
|
+
value
|
45
|
+
else
|
46
|
+
super(method, *args)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def target_path(environment)
|
51
|
+
paths = [environment.library_root_path, name.to_s]
|
52
|
+
paths << version if version
|
53
|
+
File.join(paths)
|
30
54
|
end
|
31
55
|
|
32
56
|
def update(environment, force = false)
|
@@ -41,9 +65,8 @@ module Plugit
|
|
41
65
|
end
|
42
66
|
end
|
43
67
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
68
|
+
def version
|
69
|
+
@configuration[:version]
|
70
|
+
end
|
48
71
|
end
|
49
72
|
end
|
data/plugit.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aiwilliams-plugit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Williams
|
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
52
|
requirements: []
|
53
53
|
|
54
54
|
rubyforge_project:
|
55
|
-
rubygems_version: 1.0
|
55
|
+
rubygems_version: 1.2.0
|
56
56
|
signing_key:
|
57
57
|
specification_version: 2
|
58
58
|
summary: Helping you write tests for code that depends on libraries
|