Class: Plugit::Library
- Inherits:
-
Object
show all
- Includes:
- FileUtils
- Defined in:
- lib/plugit/library.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, configuration = {}) {|_self| ... } ⇒ Library
Returns a new instance of Library.
10
11
12
13
14
15
16
17
|
# File 'lib/plugit/library.rb', line 10
def initialize(name, configuration = {})
@name = name
@configuration = configuration
@load_paths ||= ['/lib']
@requires ||= []
yield self if block_given?
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/plugit/library.rb', line 42
def method_missing(method, *args)
if value = @configuration[method.to_sym]
value
else
super(method, *args)
end
end
|
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
8
9
10
|
# File 'lib/plugit/library.rb', line 8
def configuration
@configuration
end
|
#load_paths ⇒ Object
Returns the value of attribute load_paths.
7
8
9
|
# File 'lib/plugit/library.rb', line 7
def load_paths
@load_paths
end
|
#name ⇒ Object
Returns the value of attribute name.
8
9
10
|
# File 'lib/plugit/library.rb', line 8
def name
@name
end
|
#requires ⇒ Object
Returns the value of attribute requires.
7
8
9
|
# File 'lib/plugit/library.rb', line 7
def requires
@requires
end
|
Instance Method Details
#after_update(&block) ⇒ Object
19
20
21
|
# File 'lib/plugit/library.rb', line 19
def after_update(&block)
@after_update = block
end
|
#before_install(&block) ⇒ Object
23
24
25
|
# File 'lib/plugit/library.rb', line 23
def before_install(&block)
@before_install = block
end
|
#checkout(target_path) ⇒ Object
27
28
29
30
31
|
# File 'lib/plugit/library.rb', line 27
def checkout(target_path)
command = "#{export} #{target_path}"
puts "Checking out #{name}: #{command}"
`#{command}`
end
|
#install(environment) ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/plugit/library.rb', line 33
def install(environment)
target_path = self.target_path(environment)
cd(target_path) do
instance_eval(&@before_install)
end if @before_install
load_paths.reverse.each { |l| $LOAD_PATH.unshift File.join(target_path, l) }
requires.each { |r| Object.send :require, r }
end
|
#target_path(environment) ⇒ Object
50
51
52
53
54
|
# File 'lib/plugit/library.rb', line 50
def target_path(environment)
paths = [environment.library_root_path, name.to_s]
paths << version if version
File.join(paths)
end
|
#update(environment, force = false) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/plugit/library.rb', line 56
def update(environment, force = false)
target_path = self.target_path(environment)
mkdir_p(File.dirname(target_path))
if !File.directory?(target_path) || force
rm_rf(target_path)
checkout(target_path)
cd(target_path) do
instance_eval(&@after_update)
end if @after_update
end
end
|
#version ⇒ Object
68
69
70
|
# File 'lib/plugit/library.rb', line 68
def version
@configuration[:version]
end
|