diff options
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 |