aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormms <git@sapka.me>2024-11-19 21:50:07 +0100
committermms <git@sapka.me>2024-11-19 21:50:07 +0100
commit64ab548e16fdc8fa862e2b432464f3d67f5d9db8 (patch)
tree75c8e273d47eb54af67da5c6299876601f054e93 /lib
parent8004fd7f9fc91ce9ec02b1b8e8eac639b17d0eb8 (diff)
feat: allow for --new param
Diffstat (limited to 'lib')
-rw-r--r--lib/.chotto.rb.swp (renamed from lib/chotto/.messages.rb.swp)bin12288 -> 12288 bytes
-rw-r--r--lib/chotto.rb26
-rw-r--r--lib/chotto/config.rb4
3 files changed, 20 insertions, 10 deletions
diff --git a/lib/chotto/.messages.rb.swp b/lib/.chotto.rb.swp
index d31c1b5..288ee5d 100644
--- a/lib/chotto/.messages.rb.swp
+++ b/lib/.chotto.rb.swp
Binary files 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/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