diff options
author | mms <git@sapka.me> | 2024-11-19 21:50:07 +0100 |
---|---|---|
committer | mms <git@sapka.me> | 2024-11-19 21:50:07 +0100 |
commit | 64ab548e16fdc8fa862e2b432464f3d67f5d9db8 (patch) | |
tree | 75c8e273d47eb54af67da5c6299876601f054e93 /lib/chotto.rb | |
parent | 8004fd7f9fc91ce9ec02b1b8e8eac639b17d0eb8 (diff) |
feat: allow for --new param
Diffstat (limited to 'lib/chotto.rb')
-rw-r--r-- | lib/chotto.rb | 26 |
1 files changed, 19 insertions, 7 deletions
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 |