Class: DesignShell::Core

Inherits:
Object
  • Object
show all
Defined in:
lib/designshell/core.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aDependencies = nil) ⇒ Core

Returns a new instance of Core.



6
7
8
9
10
11
12
13
14
# File 'lib/designshell/core.rb', line 6

def initialize(aDependencies=nil)
	@@instance = self unless (defined? @@instance) && @@instance
	if aDependencies
		@context = aDependencies[:context]
		@repo = aDependencies[:repo]
		@keyChain = aDependencies[:keyChain] || @context.key_chain
	end
	configure(@context) if @context
end

Instance Attribute Details

#configuredObject (readonly)

Returns the value of attribute configured.



4
5
6
# File 'lib/designshell/core.rb', line 4

def configured
  @configured
end

#contextObject (readonly)

Returns the value of attribute context.



4
5
6
# File 'lib/designshell/core.rb', line 4

def context
  @context
end

#repoObject (readonly)

Returns the value of attribute repo.



4
5
6
# File 'lib/designshell/core.rb', line 4

def repo
  @repo
end

Class Method Details

.instanceObject



16
17
18
# File 'lib/designshell/core.rb', line 16

def self.instance
	(defined? @@instance) && @@instance
end

Instance Method Details

#buildObject



50
51
52
53
# File 'lib/designshell/core.rb', line 50

def build
	response = POpen4::shell('ls')
	# puts result[:stdout]
end

#call_server_command(aCommand, aParams = nil) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/designshell/core.rb', line 65

def call_server_command(aCommand, aParams=nil)
	#ds_conn = ensure_deploy_server
	command = aCommand
	command += " " + JSON.generate(aParams) if aParams
	#result = ds_conn.exec!(command)
	result = nil
	Net::SSH.start(@context.credentials[:deploy_host],nil) do |ssh|
		result = ssh.exec!(command)
	end
	result
end

#configure(aContext) ⇒ Object



20
21
22
# File 'lib/designshell/core.rb', line 20

def configure(aContext)
	@configured = true
end

#deployObject



55
56
57
58
59
60
61
62
63
# File 'lib/designshell/core.rb', line 55

def deploy
	ensure_repo_open
	deploy_branch = 'master'
	deploy_plan(repo.get_file_content('.deploy_plan.xml',deploy_branch))
	params = deploy_plan.deploy_items_values.clone
	params['site'] = deploy_plan.site
	params['repo_url'] = repo.origin.url
	call_server_command('DEPLOY',params)
end

#deploy_plan(*args) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/designshell/core.rb', line 39

def deploy_plan(*args)
	return @deploy_plan if args.empty?
	plan = args.first
	if plan.is_a?(DesignShell::DeployPlan)
		@deploy_plan = plan
	elsif plan
		@deploy_plan = DesignShell::DeployPlan.new(:core => self,:plan => plan)
	end
	@deploy_plan
end

#ensure_deploy_serverObject



35
36
37
# File 'lib/designshell/core.rb', line 35

def ensure_deploy_server
	@conn ||= Net::SSH.start(@context.credentials[:deploy_host],nil)
end

#ensure_repo_openObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/designshell/core.rb', line 24

def ensure_repo_open
	if (!@repo && @context)
		if git_root = @context.find_git_root
			@repo = DesignShell::Repo.new
			@repo.open git_root
		end
	end
	raise "unable to open repository" unless @repo.open?
	@repo
end