popper 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7232ff188e9e7483abf67f901bac0066af3cf11
4
- data.tar.gz: ce479bb8379e9cba23f98a91c7f08c644058409e
3
+ metadata.gz: 8aa57a97616a3885fc9216806fde0f78ce86bafa
4
+ data.tar.gz: 1611c6a9cfaa3d53569b589da0eed2c62ed7dd67
5
5
  SHA512:
6
- metadata.gz: 537aa5adb32b996c1c3ad3a19f959219ac66e3f8d58e2306760cc2ea36f09a3ca425db32c3cf4a160965fb4fb4c6e6406ea90317b2d3bea2cbf3b60eea7a72ce
7
- data.tar.gz: 38d5d81059b220718748d12a59e9abec2d804677dc078a007561eab02b09f8c89b21fd48b7687dabe6b72160c60b4c04948c5f985f1b1d69bfc85d3786353a8c
6
+ metadata.gz: fdf39038cf7116daebea81aa8d1fa5826e32f8610d7609bc5ef2590c18a3b5d96d6492141c1aacc82e4107ffd31441e478965c46e4482897a460d870db93d30c
7
+ data.tar.gz: 25f8a470266ef54f88706672cb50af61757e86a8ed000171b9e1f20cd70f8a2377e39f7ce98bc281060c2757ec7d424185efd1186ed98b9475f57e883b7910bf
@@ -6,16 +6,14 @@ module Popper::Action
6
6
 
7
7
  def self.run(config, mail, params={})
8
8
  @action_config = config.send(self.action) if config.respond_to?(self.action)
9
- if action?
10
- begin
11
- Popper.log.info "run action #{self.action}"
12
- params = task(mail, params)
13
- Popper.log.info "exit action #{self.action}"
14
- rescue => e
15
- Popper.log.warn e
16
- Popper.log.warn e.backtrace
17
- end
18
- end
9
+ begin
10
+ Popper.log.info "run action #{self.action}"
11
+ params = task(mail, params)
12
+ Popper.log.info "exit action #{self.action}"
13
+ rescue => e
14
+ Popper.log.warn e
15
+ Popper.log.warn e.backtrace
16
+ end if action?
19
17
  next_run(config, mail, params)
20
18
  end
21
19
 
data/lib/popper/cli.rb CHANGED
@@ -21,9 +21,15 @@ module Popper
21
21
  Popper.load_config(options)
22
22
 
23
23
  accounts = Popper.configure.accounts.map {|account| MailAccount.new(account)}
24
+ interval = case
25
+ when Popper.configure.global.respond_to?(:interval)
26
+ Popper.configure.global.interval
27
+ else
28
+ 60
29
+ end
24
30
  while true
25
31
  accounts.each(&:run)
26
- sleep(60 || Popper.configure.global.interval)
32
+ sleep(interval)
27
33
  end
28
34
 
29
35
  rescue => e
@@ -33,7 +39,7 @@ module Popper
33
39
 
34
40
  class_option :config, type: :string, aliases: '-c'
35
41
  desc "print", "print configure"
36
- def print
42
+ def print
37
43
  Popper.load_config(options)
38
44
  Popper.configure.accounts.each do |account|
39
45
  print_config(account)
@@ -56,26 +62,30 @@ module Popper
56
62
 
57
63
  no_commands do
58
64
  def print_config(config)
59
- puts config.name
60
65
  last_rule = nil
61
- last_header = nil
62
-
63
- config.rule_with_conditions_each do |rule,mail_header,condition|
64
- puts " "*1 + "rule[#{rule}]" if rule != last_rule
65
- puts " "*2 + "actions" if rule != last_rule
66
+ puts config.name
66
67
 
67
- config.action_by_rule(rule).each_pair do |action,params|
68
- puts " "*3 + "#{action}"
69
- params.each_pair do |k,v|
70
- puts " "*4 + "#{k} #{v}"
68
+ config.rules.to_h.keys.each do |rule|
69
+ config.condition_by_rule(rule).to_h.each do |mail_header,conditions|
70
+ if rule != last_rule
71
+ puts " "*1 + "rule[#{rule}]"
72
+ puts " "*2 + "actions"
73
+ print_action(config, rule)
71
74
  end
72
- end if rule != last_rule
73
75
 
74
- puts " "*2 + "header[#{mail_header}]"
75
- puts " "*3 + "#{condition}"
76
+ puts " "*2 + "header[#{mail_header}]"
77
+ puts " "*3 + "#{conditions}"
78
+ last_rule = rule
79
+ end
80
+ end
81
+ end
76
82
 
77
- last_rule = rule
78
- last_header = mail_header
83
+ def print_action(config, rule)
84
+ config.action_by_rule(rule).each_pair do |action,params|
85
+ puts " "*3 + "#{action}"
86
+ params.each_pair do |k,v|
87
+ puts " "*4 + "#{k} #{v}"
88
+ end
79
89
  end
80
90
  end
81
91
  end
data/lib/popper/config.rb CHANGED
@@ -66,22 +66,6 @@ module Popper
66
66
  AccountAttributes.new(hash)
67
67
  end
68
68
  end
69
-
70
- def rule_with_conditions_all?(&block)
71
- rules.to_h.keys.find do |rule|
72
- condition_by_rule(rule).to_h.all? do |mail_header,conditions|
73
- block.call(rule, mail_header, conditions)
74
- end
75
- end
76
- end
77
-
78
- def rule_with_conditions_each(&block)
79
- rules.to_h.keys.each do |rule|
80
- condition_by_rule(rule).to_h.each do |mail_header,conditions|
81
- block.call(rule, mail_header, conditions)
82
- end
83
- end
84
- end
85
69
  end
86
70
 
87
71
  def self.load_config(options)
@@ -51,8 +51,11 @@ module Popper
51
51
 
52
52
  def session_start(&block)
53
53
  pop = Net::POP3.new(@config.login.server, @config.login.port || 110)
54
- pop.open_timeout = ENV['POP_TIMEOUT'] || 120
55
- pop.read_timeout = ENV['POP_TIMEOUT'] || 120
54
+ %w(
55
+ open_timeout
56
+ read_timeout
57
+ ).each {|m| pop.instance_variable_set("@#{m}", ENV['POP_TIMEOUT'] || 120) }
58
+
56
59
  pop.start(
57
60
  @config.login.user,
58
61
  @config.login.password
@@ -69,9 +72,11 @@ module Popper
69
72
  end
70
73
 
71
74
  def match_rule?(mail)
72
- @config.rule_with_conditions_all? do |rule, mail_header, conditions|
73
- conditions.all? do |condition|
74
- mail.respond_to?(mail_header) && mail.send(mail_header).to_s.match(/#{condition}/)
75
+ @config.rules.to_h.keys.find do |rule|
76
+ @config.condition_by_rule(rule).to_h.all? do |mail_header,conditions|
77
+ conditions.all? do |condition|
78
+ mail.respond_to?(mail_header) && mail.send(mail_header).to_s.match(/#{condition}/)
79
+ end
75
80
  end
76
81
  end
77
82
  end
@@ -1,3 +1,3 @@
1
1
  module Popper
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: popper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pyama86