Class: Teapot::Config

Inherits:
Object
  • Object
show all
Includes:
Dependency
Defined in:
lib/teapot/config.rb

Defined Under Namespace

Classes: Package

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Dependency

chain, #dependencies, #depends, #depends?, #provides, #provides?, #provisions

Constructor Details

#initialize(root, options = {}) ⇒ Config

Returns a new instance of Config.



88
89
90
91
92
93
94
95
# File 'lib/teapot/config.rb', line 88

def initialize(root, options = {})
	@root = Pathname.new(root)
	@options = options

	@packages = []

	@environment = Environment.new
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



105
106
107
# File 'lib/teapot/config.rb', line 105

def environment
  @environment
end

#optionsObject (readonly)

Returns the value of attribute options.



103
104
105
# File 'lib/teapot/config.rb', line 103

def options
  @options
end

#packagesObject (readonly)

Returns the value of attribute packages.



102
103
104
# File 'lib/teapot/config.rb', line 102

def packages
  @packages
end

#rootObject (readonly)

Returns the value of attribute root.



101
102
103
# File 'lib/teapot/config.rb', line 101

def root
  @root
end

Class Method Details

.load(root, options = {}) {|config| ... } ⇒ Object

Yields:

  • (config)


142
143
144
145
146
147
148
149
150
151
# File 'lib/teapot/config.rb', line 142

def self.load(root, options = {})
	config = new(root, options)
	
	yield config if block_given?
	
	teapot_path = File.join(root, "Teapot")
	config.load(teapot_path) if File.exist? teapot_path
	
	return config
end

.load_default(root = Dir.getwd, options = {}) ⇒ Object



153
154
155
156
157
158
159
160
161
162
# File 'lib/teapot/config.rb', line 153

def self.load_default(root = Dir.getwd, options = {})
	# Load project specific Teapot file
	load(root, options) do |config|
		user_path = File.expand_path("~/.Teapot")
		
		if File.exist? user_path
			config.load(user_path)
		end
	end
end

Instance Method Details

#host(*args, &block) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/teapot/config.rb', line 115

def host(*args, &block)
	name = @options[:host_platform] || RUBY_PLATFORM
	
	if block_given?
		if args.find{|arg| arg === name}
			yield
		end
	else
		name
	end
end

#load(teapot_path) ⇒ Object



138
139
140
# File 'lib/teapot/config.rb', line 138

def load(teapot_path)
	instance_eval File.read(teapot_path), teapot_path
end

#nameObject



97
98
99
# File 'lib/teapot/config.rb', line 97

def name
	:config
end

#package(name, options = {}) ⇒ Object



134
135
136
# File 'lib/teapot/config.rb', line 134

def package(name, options = {})
	@packages << Package.new(self, name, options)
end

#packages_pathObject



107
108
109
# File 'lib/teapot/config.rb', line 107

def packages_path
	@root + (@options[:packages_path] || "packages")
end

#platforms_pathObject



111
112
113
# File 'lib/teapot/config.rb', line 111

def platforms_path
	@root + (@options[:platforms_path] || "platforms")
end

#source(path) ⇒ Object



130
131
132
# File 'lib/teapot/config.rb', line 130

def source(path)
	@options[:source] = path
end