Class: Teapot::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/teapot/loader.rb

Defined Under Namespace

Classes: Definitions

Constant Summary collapse

Files =
Build::Files
Rule =
Build::Rule

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, package) ⇒ Loader

Returns a new instance of Loader.



66
67
68
69
70
71
72
# File 'lib/teapot/loader.rb', line 66

def initialize(context, package)
	@context = context
	@package = package

	@defined = Definitions.new
	@version = nil
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



74
75
76
# File 'lib/teapot/loader.rb', line 74

def context
  @context
end

#definedObject (readonly)

Returns the value of attribute defined.



76
77
78
# File 'lib/teapot/loader.rb', line 76

def defined
  @defined
end

#packageObject (readonly)

Returns the value of attribute package.



75
76
77
# File 'lib/teapot/loader.rb', line 75

def package
  @package
end

#versionObject (readonly)

Returns the value of attribute version.



77
78
79
# File 'lib/teapot/loader.rb', line 77

def version
  @version
end

Instance Method Details

#define_configuration(*args) {|configuration| ... } ⇒ Object

Yields:

  • (configuration)


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

def define_configuration(*args)
	configuration = Configuration.new(@context, @package, *args)

	configuration.top!

	yield configuration

	@defined << configuration
end

#define_generator(*args) {|generator| ... } ⇒ Object

Yields:

  • (generator)


107
108
109
110
111
112
113
# File 'lib/teapot/loader.rb', line 107

def define_generator(*args)
	generator = Generator.new(@context, @package, *args)

	yield generator

	@defined << generator
end

#define_project(*args) {|project| ... } ⇒ Object

Yields:

  • (project)


91
92
93
94
95
96
97
# File 'lib/teapot/loader.rb', line 91

def define_project(*args)
	project = Project.new(@context, @package, *args)
	
	yield project
	
	@defined << project
end

#define_target(*args) {|target| ... } ⇒ Object

Yields:

  • (target)


99
100
101
102
103
104
105
# File 'lib/teapot/loader.rb', line 99

def define_target(*args)
	target = Target.new(@context, @package, *args)

	yield target

	@defined << target
end

#host(*args, &block) ⇒ Object

Checks the host patterns and executes the block if they match.



126
127
128
129
130
131
132
133
134
135
136
# File 'lib/teapot/loader.rb', line 126

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

#load(path) ⇒ Object

Load a teapot.rb file relative to the root of the @package.



139
140
141
142
143
144
145
146
147
148
149
# File 'lib/teapot/loader.rb', line 139

def load(path)
	absolute_path = @package.path + path
	
	raise NonexistantTeapotError.new(absolute_path) unless File.exist?(absolute_path)
	
	self.instance_eval(absolute_path.read, absolute_path.to_s)
	
	if @version == nil
		raise IncompatibleTeapotError.new(@package, "<unspecified>")
	end
end

#teapot_version(version) ⇒ Object Also known as: required_version



79
80
81
82
83
84
85
86
87
# File 'lib/teapot/loader.rb', line 79

def teapot_version(version)
	version = version[0..2]
	
	if version >= MINIMUM_LOADER_VERSION && version <= LOADER_VERSION
		@version = version
	else
		raise IncompatibleTeapotError.new(package, version)
	end
end