From 64ab548e16fdc8fa862e2b432464f3d67f5d9db8 Mon Sep 17 00:00:00 2001 From: mms Date: Tue, 19 Nov 2024 21:50:07 +0100 Subject: feat: allow for --new param --- lib/.chotto.rb.swp | Bin 0 -> 12288 bytes lib/chotto.rb | 26 +++++++++++++++++++------- lib/chotto/.messages.rb.swp | Bin 12288 -> 0 bytes lib/chotto/config.rb | 4 +--- 4 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 lib/.chotto.rb.swp delete mode 100644 lib/chotto/.messages.rb.swp (limited to 'lib') diff --git a/lib/.chotto.rb.swp b/lib/.chotto.rb.swp new file mode 100644 index 0000000..288ee5d Binary files /dev/null and b/lib/.chotto.rb.swp differ diff --git a/lib/chotto.rb b/lib/chotto.rb index 71a1ac8..62e9a0d 100644 --- a/lib/chotto.rb +++ b/lib/chotto.rb @@ -12,17 +12,25 @@ require_relative 'chotto/ruleset' module Chotto class << self - attr_accessor :config - attr_reader :db, :rule_sets + attr_reader :rule_sets, :config def configure(&block) - @config ||= Config.new - @config.db_class = ::Notmuch::Database - @rule_sets = [] + @rule_sets ||= [] + @config ||= force_fresh_config instance_eval(&block) + end - @db = Database.new(path: config.database_path, db_class: config.db_class) + def force_fresh_config + @db = nil + @rule_sets = [] + @config = Config.new( + db_class: ::Notmuch::Database + ) + end + + def db + @db ||= Database.new(path: config.database_path, db_class: config.db_class) end def rule_set(name, &block) @@ -35,7 +43,11 @@ module Chotto end end -def eval_rules +def eval_rules(options = {}) + Chotto.configure do + config.only_new = options.fetch(:only_new, false) + end + Chotto.rule_sets.each(&:run) Chotto.close_db end diff --git a/lib/chotto/.messages.rb.swp b/lib/chotto/.messages.rb.swp deleted file mode 100644 index d31c1b5..0000000 Binary files a/lib/chotto/.messages.rb.swp and /dev/null differ diff --git a/lib/chotto/config.rb b/lib/chotto/config.rb index 2edfcc8..609ab5c 100644 --- a/lib/chotto/config.rb +++ b/lib/chotto/config.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true module Chotto - class Config - attr_accessor :database_path, :db_class - end + Config = Struct.new(:database_path, :db_class, :only_new) end -- cgit v1.2.3