lib/teapot/context.rb in teapot-0.3.2 vs lib/teapot/context.rb in teapot-0.5.0

- old
+ new

@@ -19,88 +19,97 @@ # THE SOFTWARE. require 'pathname' require 'rainbow' -require 'teapot/package' -require 'teapot/platform' +require 'teapot/target' module Teapot - INFUSION_VERSION = "0.2" + LOADER_VERSION = "0.5" - class IncompatibleInfusion < StandardError + class IncompatibleTeapot < StandardError end - class Infusion - def initialize(context, record) + class Loader + def initialize(context, package) @context = context - @record = record + @package = package @defined = [] @version = nil end - attr :record + attr :package attr :defined attr :version def required_version(version) - if version <= INFUSION_VERSION + if version <= LOADER_VERSION @version = version else - raise IncompatibleInfusion.new("Version #{version} more recent than #{INFUSION_VERSION}!") + raise IncompatibleTeapot.new("Version #{version} more recent than #{LOADER_VERSION}!") end end - def define_package(*args, &block) - package = Package.new(@context, @record, *args) + def define_target(*args, &block) + target = Target.new(@context, @package, *args) - yield(package) + yield(target) - @context.packages[package.name] = package + @context.targets[target.name] = target - @defined << package + @defined << target end - def define_platform(*args, &block) - platform = Platform.new(@context, @record, *args) - - yield(platform) - - if platform.available? - @context.platforms[platform.name] = platform - end - - @defined << platform - end - def load(path) self.instance_eval(File.read(path), path) end end class Context def initialize(config) @config = config - @packages = {} - @platforms = {} + @selection = nil + + @targets = {config.name => config} + + @dependencies = [] + @selection = Set.new end attr :config - attr :packages - attr :platforms + attr :targets - def load(record) - infusion = Infusion.new(self, record) + def select(names) + names.each do |name| + if @targets.key? name + @selection << name + else + @dependencies << name + end + end + end + + attr :dependencies + attr :selection + + def direct_targets(ordered) + @dependencies.collect do |dependency| + ordered.find{|(package, _)| package.provides? dependency} + end.compact + end + + def load(package) + loader = Loader.new(self, package) - path = (record.destination_path + record.loader_path).to_s - infusion.load(path) + path = (package.path + package.loader_path).to_s + loader.load(path) - if infusion.version == nil - raise IncompatibleInfusion.new("No version specified in #{path}!") + if loader.version == nil + raise IncompatibleTeapot.new("No version specified in #{path}!") end - infusion.defined + loader.defined end end end