From 61fc8dd7c4106ca5e4e74e0cc07cfa043634cdac Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Wed, 21 Aug 2024 20:52:12 +1200 Subject: [PATCH] Remove support for wrappers, I felt they are too complex. --- bake.rb | 10 ------ lib/bake/bakefile_scope.rb | 15 --------- lib/bake/context.rb | 4 --- lib/bake/registry/aggregate.rb | 12 +------ lib/bake/registry/bakefile_loader.rb | 11 ++----- lib/bake/registry/wrappers.rb | 49 ---------------------------- lib/bake/scope.rb | 2 +- test/bake/context.rb | 38 --------------------- 8 files changed, 4 insertions(+), 137 deletions(-) delete mode 100644 lib/bake/bakefile_scope.rb delete mode 100644 lib/bake/registry/wrappers.rb diff --git a/bake.rb b/bake.rb index eed967c..e69de29 100644 --- a/bake.rb +++ b/bake.rb @@ -1,10 +0,0 @@ - -wrap('test') do - before do - puts "Before test..." - end - - after do - puts "After test..." - end -end diff --git a/lib/bake/bakefile_scope.rb b/lib/bake/bakefile_scope.rb deleted file mode 100644 index 873662d..0000000 --- a/lib/bake/bakefile_scope.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -# Released under the MIT License. -# Copyright, 2020-2024, by Samuel Williams. - -module Bake - # A special scope used for the root `bake.rb` file. - module BakefileScope - attr_accessor :wrappers - - def wrap(...) - @wrappers.wrap(...) - end - end -end diff --git a/lib/bake/context.rb b/lib/bake/context.rb index 5279e3b..1e1e33e 100644 --- a/lib/bake/context.rb +++ b/lib/bake/context.rb @@ -110,10 +110,6 @@ def lookup(command) @recipes[command] end - def wrap(...) - @registry.wrap(...) - end - def to_s if @root "#{self.class} #{File.basename(@root)}" diff --git a/lib/bake/registry/aggregate.rb b/lib/bake/registry/aggregate.rb index c0d588a..bd3e116 100644 --- a/lib/bake/registry/aggregate.rb +++ b/lib/bake/registry/aggregate.rb @@ -7,7 +7,6 @@ require_relative 'directory_loader' require_relative 'bakefile_loader' -require_relative 'wrappers' module Bake # Structured access to the working directory and loaded gems for loading bakefiles. @@ -36,12 +35,6 @@ def initialize # The ordered list of loaders: @ordered = Array.new - - @wrappers = Wrappers.new - end - - def wrap(...) - @wrappers.wrap(...) end # Whether any registry are defined. @@ -53,19 +46,16 @@ def empty? # Enumerate the registry in order. def each(&block) @ordered.each(&block) - yield @wrappers end def scopes_for(path, &block) @ordered.each do |registry| registry.scopes_for(path, &block) end - - @wrappers.scopes_for(path, &block) end def append_bakefile(path) - @ordered << BakefileLoader.new(path, @wrappers) + @ordered << BakefileLoader.new(path) end # Append a specific project path to the search path for recipes. diff --git a/lib/bake/registry/bakefile_loader.rb b/lib/bake/registry/bakefile_loader.rb index 3211682..292246d 100644 --- a/lib/bake/registry/bakefile_loader.rb +++ b/lib/bake/registry/bakefile_loader.rb @@ -4,14 +4,12 @@ # Copyright, 2020-2024, by Samuel Williams. require_relative '../scope' -require_relative '../bakefile_scope' module Bake module Registry class BakefileLoader - def initialize(path, wrappers) + def initialize(path) @path = path - @wrappers = wrappers end def to_s @@ -26,12 +24,7 @@ def each(&block) def scopes_for(path) if path == [] - scope = Scope.load(@path, []) do |scope| - scope.extend(BakefileScope) - scope.wrappers = @wrappers - end - - yield scope + yield Scope.load(@path, []) end end end diff --git a/lib/bake/registry/wrappers.rb b/lib/bake/registry/wrappers.rb deleted file mode 100644 index 52169cb..0000000 --- a/lib/bake/registry/wrappers.rb +++ /dev/null @@ -1,49 +0,0 @@ -module Bake - module Registry - class Wrappers - def initialize - @wrappers = Hash.new do |hash, key| - hash[key] = [] - end - end - - class Wrapper - def initialize(wrappers, path) - @wrappers = wrappers - @path = path - end - - def before(name = @path.last, &block) - wrapper = Module.new - wrapper.define_method(name) do |*arguments, **options| - instance_exec(&block) - super(*arguments, **options) - end - - @wrappers[@path] << wrapper - end - - def after(name = @path.last, &block) - wrapper = Module.new - wrapper.define_method(name) do |*arguments, **options| - super(*arguments, **options) - instance_exec(&block) - end - - @wrappers[@path] << wrapper - end - end - - def wrap(*path, &block) - Wrapper.new(@wrappers, path).instance_exec(&block) - end - - def each(&block) - end - - def scopes_for(path, &block) - @wrappers[path].each(&block) - end - end - end -end diff --git a/lib/bake/scope.rb b/lib/bake/scope.rb index 73c622e..89cdc12 100644 --- a/lib/bake/scope.rb +++ b/lib/bake/scope.rb @@ -21,7 +21,7 @@ def self.load(file_path, path = []) scope.const_set(:FILE_PATH, file_path) scope.const_set(:PATH, path) - yield scope if block_given? + # yield scope if block_given? scope.module_eval(File.read(file_path), file_path) diff --git a/test/bake/context.rb b/test/bake/context.rb index 4b720ab..3d85cd9 100644 --- a/test/bake/context.rb +++ b/test/bake/context.rb @@ -52,42 +52,4 @@ expect(parent.instance).to be(:respond_to?, :parent) end end - - with '#wrap' do - it "can wrap specific methods" do - events = [] - - context.wrap('wrap') do - before('invoked') do - events << :before - end - - after('invoked') do - events << :after - end - end - - context.call('wrap') - - expect(events).to be == [:before, :after] - end - - it "can wrap unspecified methods" do - events = [] - - context.wrap('wrap') do - before do - events << :before - end - - after do - events << :after - end - end - - context.call('wrap') - - expect(events).to be == [:before, :after] - end - end end