Skip to content

Commit

Permalink
Merge pull request #208 from sisimai/sisimai-fact-1
Browse files Browse the repository at this point in the history
Sisimai::Fact
  • Loading branch information
azumakuniyuki authored Feb 7, 2021
2 parents ba6a79a + ce206ac commit d1cad5b
Show file tree
Hide file tree
Showing 398 changed files with 8,525 additions and 9,562 deletions.
2 changes: 0 additions & 2 deletions .rspec

This file was deleted.

11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
language: ruby
rvm:
# See http://rubies.travis-ci.org for Precompiled Ruby Versions
- 2.1.1
- 2.2.4
# - 2.1.1
# - 2.2.10
# - 2.3.0
# - 2.4.0
- 2.4.9
# - 2.5.0
- 2.6.0
- 2.6.6
# - 2.7.0
# - jruby-9.0.5.0
# - jruby-9.1.9.0
before_install:
script:
- rake spec
- make user-test
sudo: false
notifications:
recipients:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ gemspec name: 'sisimai'

group :development, :test do
gem 'rake', :require => false
gem 'rspec', :require => false
gem 'minitest', :require => false
gem 'coveralls', :require => false
end

15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ RUBY ?= ruby
JRUBY ?= /usr/local/jr
RAKE ?= rake
MKDIR := mkdir -p
RSPEC := rspec -Ilib -f progress
CP := cp
RM := rm -f

DEPENDENCIES = bundle rake rspec
DEPENDENCIES = bundle rake minitest
.DEFAULT_GOAL = git-status
REPOS_TARGETS = git-status git-push git-commit-amend git-tag-list git-diff \
git-reset-soft git-rm-cached git-branch
Expand Down Expand Up @@ -57,18 +56,20 @@ release:
PATH="$(JRUBY)/bin:$$PATH" $(JRUBY)/bin/rake release; \
fi

test: cruby-test
test: user-test author-test
user-test:
rake publictest

author-test:
rake privatetest

check:
find lib -type f -exec grep --color -E ' $$' {} /dev/null \;
find lib -type f -exec grep --color -E '[;][ ]*$$' {} /dev/null \;

cruby-test:
$(RAKE) spec

jruby-test:
if [ -d "$(JRUBY)" ]; then \
PATH="$(JRUBY)/bin:$$PATH" LS_HEAP_SIZE='1024m' $(JRUBY)/bin/rake spec; \
PATH="$(JRUBY)/bin:$$PATH" LS_HEAP_SIZE='1024m' $(JRUBY)/bin/rake publictest; \
fi

patrol:
Expand Down
2 changes: 1 addition & 1 deletion README-JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ $ cd /usr/local/src
$ git clone https://github.com/sisimai/rb-sisimai.git
$ cd ./rb-sisimai
$ sudo make depend install-from-local
gem install bundle rake rspec coveralls
gem install bundle rake minitest coveralls
...
4 gems installed
bundle exec rake install
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ $ cd /usr/local/src
$ git clone https://github.com/sisimai/rb-sisimai.git
$ cd ./rb-sisimai
$ sudo make depend install-from-local
gem install bundle rake rspec coveralls
gem install bundle rake minitest coveralls
...
4 gems installed
bundle exec rake install
Expand Down
12 changes: 9 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
require 'rspec/core/rake_task'
require 'bundler/gem_helper'

if RUBY_PLATFORM =~ /java/
filename = 'sisimai-java'
else
filename = 'sisimai'
end
Bundler::GemHelper.install_tasks :name => filename
RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task :default => :test
task :test => [:publictest, :privatetest]
task :publictest do
Dir.glob('./test/public/*-test.rb').each { |cf| require cf }
end
task :privatetest do
Dir.glob('./test/private/*-test.rb').each { |cf| require cf }
end

39 changes: 18 additions & 21 deletions lib/sisimai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
# results. Sisimai is the system formerly known as bounceHammer 4, is the successor to bounceHammer.
require 'sisimai/version'
module Sisimai
# Imported from p5-Sisimail/lib/Sisimai.pm
class << self
def version(); return Sisimai::VERSION; end
def libname(); return 'Sisimai'; end

# Emulate "rise" method for the backward compatible
def make(argv0, **argv1)
warn ' ***warning: Sisimai.make will be removed at v5.1.0. Use Sisimai.rise instead';
return Sisimai.rise(argv0, **argv1)
end

# Wrapper method for parsing mailbox/maidir
# @param [String] argv0 Path to mbox or Maildir/
# @param [Hash] argv0 or Hash (decoded JSON)
Expand All @@ -16,46 +21,38 @@ def libname(); return 'Sisimai'; end
# @options argv1 [Array] c___ Proc object to a callback method for the message and each file
# @return [Array] Parsed objects
# @return [nil] nil if the argument was wrong or an empty array
def make(argv0, **argv1)
def rise(argv0, **argv1)
return nil unless argv0
require 'sisimai/data'
require 'sisimai/message'
require 'sisimai/mail'
require 'sisimai/fact'

list = []
return nil unless mail = Sisimai::Mail.new(argv0)
kind = mail.kind
c___ = argv1[:c___].is_a?(Array) ? argv1[:c___] : [nil, nil]
sisi = []

while r = mail.data.read do
# Read and parse each email file
args = { data: r, hook: c___[0] }
path = mail.data.path
sisi = []

mesg = Sisimai::Message.new(args)
unless mesg.void
# Sisimai::Message object was created successfully
args = { data: mesg, delivered: argv1[:delivered], origin: path }
sisi = Sisimai::Data.make(args)
end
args = { data: r, hook: c___[0], origin: path, delivered: argv1[:delivered] }
fact = Sisimai::Fact.rise(args) || []

if c___[1]
# Run the callback function specified with "c___" parameter of Sisimai.make
# after reading each email file in Maildir/ every time
args = { 'kind' => kind, 'mail' => r, 'path' => path, 'sisi' => sisi }
# Run the callback function specified with "c___" parameter of Sisimai.rise after reading
# each email file in Maildir/ every time
args = { 'kind' => kind, 'mail' => r, 'path' => path, 'fact' => fact }
begin
c___[1].call(args) if c___[1].is_a?(Proc)
rescue StandardError => ce
warn ' ***warning: Something is wrong in the second element of the ":c___":' << ce.to_s
end
end

list += sisi unless sisi.empty?
sisi += fact unless fact.empty?
end

return nil if list.empty?
return list
return nil if sisi.empty?
return sisi
end

# Wrapper method to parse mailbox/Maildir and dump as JSON
Expand All @@ -69,7 +66,7 @@ def make(argv0, **argv1)
def dump(argv0, **argv1)
return nil unless argv0

nyaan = Sisimai.make(argv0, argv1) || []
nyaan = Sisimai.rise(argv0, argv1) || []
if RUBY_PLATFORM.start_with?('java')
# java-based ruby environment like JRuby.
require 'jrjackson'
Expand Down
Loading

0 comments on commit d1cad5b

Please sign in to comment.