Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Aug 20, 2024
1 parent 35c7f95 commit 55a9b40
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
27 changes: 6 additions & 21 deletions lib/bake/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,22 @@ def self.bakefile_path(path, bakefile: BAKEFILE)
# @path [String] A file-system path.
def self.load(path = Dir.pwd)
if bakefile_path = self.bakefile_path(path)
scope = Scope.load(bakefile_path)

working_directory = File.dirname(bakefile_path)
loaders = Loaders.default(working_directory)
else
scope = nil

working_directory = path
loaders = Loaders.default(working_directory)
end

return self.new(loaders, scope, working_directory)
loaders = Loaders.default(working_directory, bakefile_path)
instance = self.new(loaders, working_directory)

return instance
end

# Initialize the context with the specified loaders.
# @parameter loaders [Loaders]
def initialize(loaders, scope = nil, root = nil)
def initialize(loaders, root = nil)
@loaders = loaders
@root = root

@wrappers = Hash.new do |hash, key|
hash[key] = []
Expand All @@ -72,16 +70,6 @@ def initialize(loaders, scope = nil, root = nil)
hash[key] = instance_for(key)
end

@scope = scope
@root = root

if @scope
base = Base.derive
base.prepend(@scope)

@instances[[]] = base.new(self)
end

@recipes = Hash.new do |hash, key|
hash[key] = recipe_for(key)
end
Expand All @@ -90,9 +78,6 @@ def initialize(loaders, scope = nil, root = nil)
# The loaders which will be used to resolve recipes in this context.
attr :loaders

# The scope for the root {BAKEFILE}.
attr :scope

# The root path of this context.
# @returns [String | Nil]
attr :root
Expand Down
2 changes: 2 additions & 0 deletions lib/bake/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ def scope_for(path)
end
end
end


end
9 changes: 8 additions & 1 deletion lib/bake/loaders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ class Loaders

# Create a loader using the specified working directory.
# @parameter working_directory [String]
def self.default(working_directory)
def self.default(working_directory, bakefile_path = nil)
loaders = self.new

if bakefile_path
loaders.append_path(File.dirname(bakefile_path))
end

loaders.append_defaults(working_directory)

return loaders
Expand All @@ -34,6 +38,9 @@ def empty?
@ordered.empty?
end

def append_bakefile(path)


# Add loaders according to the current working directory and loaded gems.
# @parameter working_directory [String]
def append_defaults(working_directory)
Expand Down
5 changes: 5 additions & 0 deletions lib/bake/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ def recipes
end

# The path of the file that was used to {load} this scope.
def file_path
self.const_get(:FILE_PATH)
end

# The path of the scope, relative to the root of the context.
def path
self.const_get(:PATH)
end
Expand Down

0 comments on commit 55a9b40

Please sign in to comment.