Class: Shaddox::ShadowScript

Inherits:
Object
  • Object
show all
Defined in:
lib/shaddox/shadow_script.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, task_key, opts = {}) ⇒ ShadowScript

Returns a new instance of ShadowScript.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/shaddox/shadow_script.rb', line 4

def initialize(config, task_key, opts = {})
	# Initialize properties
	@installer = opts[:installer]
	@debug = opts[:debug]

	@config = config
	@cast_tasks = []

	# Generate script
	params = []
	params.push(":installer => :#{@installer}") if @installer
	params.push(":debug => #{@debug}") if @debug

	@script = %Q{
require 'shaddox'
Shaddox::Shadow.new({#{params.join(',')}}) do
	## begin generated shadow ##
	}
	add_repos
	cast(task_key)
	@script += %Q{
	## end generated shadow ##
end
	}
end

Instance Attribute Details

#scriptObject (readonly)

Returns the value of attribute script.



3
4
5
# File 'lib/shaddox/shadow_script.rb', line 3

def script
  @script
end

Instance Method Details

#add_reposObject

add_repos Retrieves all repos from the @config and ensures their data is copied to the script for use by tasks.



52
53
54
55
56
57
58
59
# File 'lib/shaddox/shadow_script.rb', line 52

def add_repos
	@script += %Q(
	@repos = {)
	@config.repos.each do |key, repo|
		@script += ":#{key} => #{repo.to_source}"
	end
	@script += %Q(})
end

#cast(task_key) ⇒ Object

cast Retrieves a task from the @config and ensures all of its dependencies have been added to the script before adding itself. Tasks are only cast once to elimate redundency.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/shaddox/shadow_script.rb', line 34

def cast(task_key)
	task = @config.tasks[task_key]
	if !task
		raise "The task :#{task_key} could not be found. Please check your Doxfile and try again.".red
	end
	task.deps.each do |dep_key|
		cast(dep_key) if !@cast_tasks.include? dep_key
	end
	@script += %Q{
	## #{task_key} ##
	#{task.to_source}
	}
	@cast_tasks.push(task_key)
end