diff options
Diffstat (limited to 'lib/some')
-rw-r--r-- | lib/some/config.rb | 5 | ||||
-rw-r--r-- | lib/some/database.rb | 4 | ||||
-rw-r--r-- | lib/some/helpers.rb | 2 | ||||
-rw-r--r-- | lib/some/message.rb | 2 | ||||
-rw-r--r-- | lib/some/messages.rb | 10 | ||||
-rw-r--r-- | lib/some/ruleset.rb | 11 |
6 files changed, 31 insertions, 3 deletions
diff --git a/lib/some/config.rb b/lib/some/config.rb new file mode 100644 index 0000000..916db0c --- /dev/null +++ b/lib/some/config.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class Config + attr_accessor :database_path +end diff --git a/lib/some/database.rb b/lib/some/database.rb index 5595a41..d481dd5 100644 --- a/lib/some/database.rb +++ b/lib/some/database.rb @@ -11,5 +11,9 @@ module Some def query(query) db.query(query) end + + def search_messages(query) + query(query).search_messages + end end end diff --git a/lib/some/helpers.rb b/lib/some/helpers.rb index 5842f73..36dcdef 100644 --- a/lib/some/helpers.rb +++ b/lib/some/helpers.rb @@ -2,7 +2,7 @@ module Some module Helpers - def header_name_from_dsl(method_name) + def self.header_name_from_dsl(method_name) method_name .to_s .split('_') diff --git a/lib/some/message.rb b/lib/some/message.rb index 47e397e..cd352f1 100644 --- a/lib/some/message.rb +++ b/lib/some/message.rb @@ -9,7 +9,7 @@ module Some end def method_missing(method_name, *_args) - handle_get(Helpers.header_name_from_dsl(method_name)) + handle_get(Some::Helpers.header_name_from_dsl(method_name)) end def handle_get(header_name) diff --git a/lib/some/messages.rb b/lib/some/messages.rb index 5e2ff48..9f2520b 100644 --- a/lib/some/messages.rb +++ b/lib/some/messages.rb @@ -44,8 +44,10 @@ module Some end attr_accessor :query, :current_conjuction, :token_count + attr_reader :db - def initialize + def initialize(db:) + @db = db @query = [] @current_conjuction = AND_CONJUCTION @token_count = 0 @@ -72,6 +74,12 @@ module Some self end + def each + db.search_messages(query_string).each do |msg| + yield(Message.new(msg: msg)) + end + end + def add_filter_from_string(string) @query << Token.new(current_conjuction, :direct, string, self) end diff --git a/lib/some/ruleset.rb b/lib/some/ruleset.rb new file mode 100644 index 0000000..6df1eff --- /dev/null +++ b/lib/some/ruleset.rb @@ -0,0 +1,11 @@ +module Some + RuleSet = Struct.new(:name, :rule) do + def messages + Messages.new(db: Some.db) + end + + def run + instance_eval(&rule) + end + end +end |