Class: YaQueen::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/ya_queen/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(context, name, configs) ⇒ Base
Returns a new instance of Base.
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/ya_queen/base.rb', line 7
def initialize(context, name, configs)
@context = context
@name = name
@root = configs
@config = configs[name.to_sym] || configs[name.to_s]
@servers = @config["servers"] || {}
if s = @config["server"]
@servers[s] = {}
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/ya_queen/base.rb', line 18
def method_missing(name, *args, &block)
if context.respond_to?(name)
context.send(name, *args, &block)
else
begin
context.send(name, *args, &block)
rescue NameError
super
end
end
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
6
7
8
|
# File 'lib/ya_queen/base.rb', line 6
def config
@config
end
|
#context ⇒ Object
Returns the value of attribute context.
6
7
8
|
# File 'lib/ya_queen/base.rb', line 6
def context
@context
end
|
#name ⇒ Object
Returns the value of attribute name.
6
7
8
|
# File 'lib/ya_queen/base.rb', line 6
def name
@name
end
|
#root ⇒ Object
Returns the value of attribute root.
6
7
8
|
# File 'lib/ya_queen/base.rb', line 6
def root
@root
end
|
#servers ⇒ Object
Returns the value of attribute servers.
6
7
8
|
# File 'lib/ya_queen/base.rb', line 6
def servers
@servers
end
|
Instance Method Details
#common_task(&block) ⇒ Object
44
|
# File 'lib/ya_queen/base.rb', line 44
def common_task(&block); @common_task = block; end
|
#define_common_task ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/ya_queen/base.rb', line 56
def define_common_task
t = self
task(:"@#{name}/common") do
t.implement_common_task
t.set_deploy_target("@#{name}")
end
end
|
#define_each_task(host, options) ⇒ Object
64
65
66
67
|
# File 'lib/ya_queen/base.rb', line 64
def define_each_task(host, options)
t = self
task( :"@#{name}/#{host}"){ t.implement_each_task(host, options) }
end
|
#define_role_task ⇒ Object
51
52
53
54
|
# File 'lib/ya_queen/base.rb', line 51
def define_role_task
t = self
task(:"@#{name}"){ t.implement_role_task }
end
|
#define_tasks ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/ya_queen/base.rb', line 30
def define_tasks
return if servers.nil? or servers.empty?
define_role_task
servers.each do |host, options|
after :"@#{name}", :"@#{name}/#{host}"
define_each_task(host, options)
after :"@#{name}/#{host}", :"@#{name}/common"
end
define_common_task
end
|
#each_task(&block) ⇒ Object
45
|
# File 'lib/ya_queen/base.rb', line 45
def each_task(&block) ; @each_task = block; end
|
#implement_common_task ⇒ Object
48
|
# File 'lib/ya_queen/base.rb', line 48
def implement_common_task; @common_task.call if @common_task; end
|
#implement_each_task(host, options) ⇒ Object
49
|
# File 'lib/ya_queen/base.rb', line 49
def implement_each_task(host, options); @each_task.call(host, options) if @each_task; end
|
#implement_role_task ⇒ Object
47
|
# File 'lib/ya_queen/base.rb', line 47
def implement_role_task ; @role_task.call if @role_task; end
|
#role_task(&block) ⇒ Object
43
|
# File 'lib/ya_queen/base.rb', line 43
def role_task(&block) ; @role_task = block; end
|
#set_deploy_target(tgt) ⇒ Object
デプロイ先サーバ・ディレクトリ選択時に異なる種類のデプロイ対象を選択できないようにする(cap vagrant @apisrv-a01 @gotool01 deploy:update などをできないようにする)
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/ya_queen/base.rb', line 72
def set_deploy_target(tgt)
case selected = context.fetch(:selected_deploy_target, nil)
when nil
context.set :selected_deploy_target, tgt
when tgt
else
raise "already selected deploy target: #{selected}"
end
end
|