Class: Teapot::Context

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Context

Returns a new instance of Context.



75
76
77
78
79
80
81
82
83
84
# File 'lib/teapot/context.rb', line 75

def initialize(config)
	@config = config

	@selection = nil

	@targets = {config.name => config}

	@dependencies = []
	@selection = Set.new
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



86
87
88
# File 'lib/teapot/context.rb', line 86

def config
  @config
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



99
100
101
# File 'lib/teapot/context.rb', line 99

def dependencies
  @dependencies
end

#selectionObject (readonly)

Returns the value of attribute selection.



100
101
102
# File 'lib/teapot/context.rb', line 100

def selection
  @selection
end

#targetsObject (readonly)

Returns the value of attribute targets.



87
88
89
# File 'lib/teapot/context.rb', line 87

def targets
  @targets
end

Instance Method Details

#direct_targets(ordered) ⇒ Object



102
103
104
105
106
# File 'lib/teapot/context.rb', line 102

def direct_targets(ordered)
	@dependencies.collect do |dependency|
		ordered.find{|(package, _)| package.provides? dependency}
	end.compact
end

#load(package) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/teapot/context.rb', line 108

def load(package)
	loader = Loader.new(self, package)
	
	path = (package.path + package.loader_path).to_s
	loader.load(path)
	
	if loader.version == nil
		raise IncompatibleTeapot.new("No version specified in #{path}!")
	end
	
	loader.defined
end

#select(names) ⇒ Object



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

def select(names)
	names.each do |name|
		if @targets.key? name
			@selection << name
		else
			@dependencies << name
		end
	end
end