lazylead 0.6.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +7 -2
- data/.docker/Dockerfile +17 -6
- data/.docs/duedate_expired.md +1 -1
- data/.rubocop.yml +119 -3
- data/.simplecov +1 -1
- data/Gemfile +1 -1
- data/Guardfile +2 -2
- data/Rakefile +7 -4
- data/bin/lazylead +4 -2
- data/lazylead.gemspec +33 -29
- data/lib/lazylead.rb +2 -2
- data/lib/lazylead/allocated.rb +1 -1
- data/lib/lazylead/cc.rb +22 -21
- data/lib/lazylead/cli/app.rb +3 -3
- data/lib/lazylead/confluence.rb +10 -3
- data/lib/lazylead/email.rb +1 -21
- data/lib/lazylead/exchange.rb +17 -29
- data/lib/lazylead/home.rb +1 -1
- data/lib/lazylead/log.rb +1 -1
- data/lib/lazylead/model.rb +25 -17
- data/lib/lazylead/opts.rb +68 -3
- data/lib/lazylead/postman.rb +14 -19
- data/lib/lazylead/requires.rb +38 -0
- data/lib/lazylead/salt.rb +2 -1
- data/lib/lazylead/schedule.rb +1 -1
- data/lib/lazylead/smtp.rb +1 -1
- data/lib/lazylead/system/empty.rb +1 -1
- data/lib/lazylead/system/fake.rb +1 -1
- data/lib/lazylead/system/jira.rb +28 -20
- data/lib/lazylead/system/synced.rb +1 -1
- data/lib/lazylead/task/accuracy/accuracy.rb +23 -30
- data/lib/lazylead/task/accuracy/affected_build.rb +1 -1
- data/lib/lazylead/task/accuracy/attachment.rb +3 -7
- data/lib/lazylead/task/accuracy/environment.rb +1 -1
- data/lib/lazylead/task/accuracy/logs.rb +10 -5
- data/lib/lazylead/task/accuracy/onlyll.rb +147 -0
- data/lib/lazylead/task/accuracy/records.rb +2 -2
- data/lib/lazylead/task/accuracy/requirement.rb +1 -1
- data/lib/lazylead/task/accuracy/servers.rb +17 -8
- data/lib/lazylead/task/accuracy/stacktrace.rb +2 -2
- data/lib/lazylead/task/accuracy/testcase.rb +3 -3
- data/lib/lazylead/task/accuracy/wiki.rb +1 -1
- data/lib/lazylead/task/{alert.rb → alert/alert.rb} +6 -6
- data/lib/lazylead/task/alert/alertif.rb +75 -0
- data/lib/lazylead/task/alert/changed_to.rb +58 -0
- data/lib/lazylead/task/assignment.rb +1 -1
- data/lib/lazylead/task/confluence_ref.rb +1 -1
- data/lib/lazylead/task/echo.rb +1 -1
- data/lib/lazylead/task/fix_version.rb +5 -3
- data/lib/lazylead/task/loading.rb +94 -0
- data/lib/lazylead/task/missing_comment.rb +1 -1
- data/lib/lazylead/task/propagate_down.rb +4 -4
- data/lib/lazylead/task/savepoint.rb +1 -1
- data/lib/lazylead/task/svn/diff.rb +6 -14
- data/lib/lazylead/task/svn/grep.rb +41 -13
- data/lib/lazylead/task/svn/touch.rb +3 -5
- data/lib/lazylead/version.rb +2 -2
- data/lib/messages/accuracy.erb +1 -1
- data/lib/messages/alertif.erb +134 -0
- data/lib/messages/created_recently.erb +110 -0
- data/lib/messages/illegal_fixversion_change.erb +8 -2
- data/lib/messages/loading.erb +117 -0
- data/lib/messages/only_ll.erb +107 -0
- data/lib/messages/svn_diff_attachment.erb +18 -8
- data/lib/messages/svn_grep.erb +1 -1
- data/readme.md +3 -3
- data/test/lazylead/allocated_test.rb +1 -1
- data/test/lazylead/cc_test.rb +2 -1
- data/test/lazylead/cli/app_test.rb +2 -2
- data/test/lazylead/confluence_test.rb +1 -1
- data/test/lazylead/exchange_test.rb +1 -1
- data/test/lazylead/model_test.rb +11 -1
- data/test/lazylead/opts_test.rb +48 -1
- data/test/lazylead/postman_test.rb +9 -6
- data/test/lazylead/salt_test.rb +1 -1
- data/test/lazylead/smoke_test.rb +14 -1
- data/test/lazylead/smtp_test.rb +2 -5
- data/test/lazylead/system/jira_test.rb +10 -1
- data/test/lazylead/task/accuracy/accuracy_test.rb +1 -1
- data/test/lazylead/task/accuracy/affected_build_test.rb +1 -1
- data/test/lazylead/task/accuracy/attachment_test.rb +2 -2
- data/test/lazylead/task/accuracy/environment_test.rb +1 -1
- data/test/lazylead/task/accuracy/logs_test.rb +13 -1
- data/test/lazylead/task/accuracy/onlyll_test.rb +138 -0
- data/test/lazylead/task/accuracy/records_test.rb +1 -1
- data/test/lazylead/task/accuracy/score_test.rb +2 -2
- data/test/lazylead/task/accuracy/servers_test.rb +3 -3
- data/test/lazylead/task/accuracy/stacktrace_test.rb +1 -1
- data/test/lazylead/task/accuracy/testcase_test.rb +28 -1
- data/test/lazylead/task/accuracy/wiki_test.rb +1 -1
- data/test/lazylead/task/alert/alertif_test.rb +54 -0
- data/test/lazylead/task/{assignee_alert_test.rb → alert/assignee_alert_test.rb} +10 -10
- data/test/lazylead/task/alert/changed_to_test.rb +42 -0
- data/test/lazylead/task/assignment_test.rb +1 -1
- data/test/lazylead/task/confluence_ref_test.rb +1 -1
- data/test/lazylead/task/created_recently_test.rb +53 -0
- data/test/lazylead/task/duedate_test.rb +5 -12
- data/test/lazylead/task/echo_test.rb +1 -1
- data/test/lazylead/task/fix_version_test.rb +2 -1
- data/test/lazylead/task/loading_test.rb +54 -0
- data/test/lazylead/task/missing_comment_test.rb +1 -1
- data/test/lazylead/task/propagate_down_test.rb +5 -4
- data/test/lazylead/task/savepoint_test.rb +10 -7
- data/test/lazylead/task/svn/diff_test.rb +1 -1
- data/test/lazylead/task/svn/grep_test.rb +44 -2
- data/test/lazylead/task/svn/touch_test.rb +1 -1
- data/test/lazylead/version_test.rb +1 -1
- data/test/sqlite_test.rb +1 -1
- data/test/test.rb +8 -9
- data/upgrades/sqlite/001-install-main-lazylead-tables.sql +1 -1
- data/upgrades/sqlite/999.testdata.sql +3 -2
- metadata +133 -58
data/lib/lazylead/cli/app.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# The MIT License
|
4
4
|
#
|
5
|
-
# Copyright (c) 2019-
|
5
|
+
# Copyright (c) 2019-2021 Yurii Dubinka
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the "Software"),
|
@@ -57,8 +57,8 @@ module Lazylead
|
|
57
57
|
private
|
58
58
|
|
59
59
|
def apply_vcs_migration(opts)
|
60
|
-
@db = File.expand_path(opts[:home])
|
61
|
-
vcs = File.expand_path(opts[:home])
|
60
|
+
@db = "#{File.expand_path(opts[:home])}/#{opts[:sqlite]}"
|
61
|
+
vcs = "#{File.expand_path(opts[:home])}/#{opts[:vcs4sql]}"
|
62
62
|
@log.debug "Database: '#{@db.colorize(:light_blue)}', "\
|
63
63
|
"sql migration dir: '#{vcs.colorize(:light_blue)}'"
|
64
64
|
Vcs4sql::Sqlite::Migration.new(@db).upgrade vcs, opts[:testdata]
|
data/lib/lazylead/confluence.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# The MIT License
|
4
4
|
#
|
5
|
-
# Copyright (c) 2019-
|
5
|
+
# Copyright (c) 2019-2021 Yurii Dubinka
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the "Software"),
|
@@ -104,16 +104,23 @@ module Lazylead
|
|
104
104
|
end
|
105
105
|
|
106
106
|
# Detect links mentioned in ticket comments
|
107
|
+
# @todo #/DEV Refactor this method in order to make it more human-readable and remove the
|
108
|
+
# suppresion below
|
109
|
+
#
|
110
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
111
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
107
112
|
def mentioned_links(ticket)
|
108
113
|
ticket.comments
|
109
114
|
.map { |cmnt| cmnt.attrs["body"] }
|
110
115
|
.select { |cmnt| @confl.any? { |c| cmnt.include? c.url } }
|
111
|
-
.flat_map
|
116
|
+
.flat_map(&:split)
|
112
117
|
.select { |cmnt| @confl.any? { |c| cmnt.start_with? c.url } }
|
113
|
-
.map(
|
118
|
+
.map { |url| to_page_id(url) }
|
114
119
|
.reject(&:blank?)
|
115
120
|
.uniq
|
116
121
|
end
|
122
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
123
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
117
124
|
|
118
125
|
# Convert confluence page url to the following format:
|
119
126
|
# http://confluence.com/pages/viewpage.action?pageId=xxxxx
|
data/lib/lazylead/email.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# The MIT License
|
4
4
|
#
|
5
|
-
# Copyright (c) 2019-
|
5
|
+
# Copyright (c) 2019-2021 Yurii Dubinka
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the "Software"),
|
@@ -25,26 +25,6 @@
|
|
25
25
|
require "tilt"
|
26
26
|
|
27
27
|
module Lazylead
|
28
|
-
# Email notifications utilities.
|
29
|
-
module Emailing
|
30
|
-
# Construct html document from template and binds.
|
31
|
-
def make_body(opts)
|
32
|
-
Email.new(
|
33
|
-
opts["template"],
|
34
|
-
opts.merge(version: Lazylead::VERSION)
|
35
|
-
).render
|
36
|
-
end
|
37
|
-
|
38
|
-
# Split text with email addresses by ',' and trim all elements if needed.
|
39
|
-
def split(type, opts)
|
40
|
-
if opts[type].include? ","
|
41
|
-
opts[type].split(",").map(&:strip).reject(&:empty?)
|
42
|
-
else
|
43
|
-
[opts[type]]
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
28
|
# An email regarding tickets based on file with markup.
|
49
29
|
#
|
50
30
|
# The 'tilt' gem was used as a template engine.
|
data/lib/lazylead/exchange.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# The MIT License
|
4
4
|
#
|
5
|
-
# Copyright (c) 2019-
|
5
|
+
# Copyright (c) 2019-2021 Yurii Dubinka
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the "Software"),
|
@@ -39,8 +39,6 @@ module Lazylead
|
|
39
39
|
# Copyright:: Copyright (c) 2019-2020 Yurii Dubinka
|
40
40
|
# License:: MIT
|
41
41
|
class Exchange
|
42
|
-
include Emailing
|
43
|
-
|
44
42
|
def initialize(
|
45
43
|
log = Log.new, salt = Salt.new("exchange_salt"), opts = ENV.to_h
|
46
44
|
)
|
@@ -52,38 +50,28 @@ module Lazylead
|
|
52
50
|
# Send an email.
|
53
51
|
# :opts :: the mail configuration like from, cc, subject, template.
|
54
52
|
def send(opts)
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
53
|
+
if opts.msg_to.empty?
|
54
|
+
@log.warn "ll-012: Email can't be sent to '#{opts.msg_to}," \
|
55
|
+
" more: '#{opts}'"
|
56
|
+
else
|
57
|
+
msg = make_msg opts
|
58
|
+
cli.send_message msg
|
59
|
+
msg[:file_attachments].each(&:close) unless opts.msg_attachments.empty?
|
60
|
+
@log.debug "#{__FILE__} sent '#{opts['subject']}' to '#{opts.msg_to}'."
|
60
61
|
end
|
61
|
-
msg = make_msg(to, opts)
|
62
|
-
msg.update(cc_recipients: opts["cc"]) if opts.key? "cc"
|
63
|
-
add_attachments(msg, opts)
|
64
|
-
cli.send_message msg
|
65
|
-
close_attachments msg
|
66
|
-
@log.debug "#{__FILE__} sent '#{opts['subject']}' to '#{to}'."
|
67
62
|
end
|
68
63
|
|
69
|
-
def make_msg(
|
70
|
-
{
|
64
|
+
def make_msg(opts)
|
65
|
+
msg = {
|
71
66
|
subject: opts["subject"],
|
72
|
-
body:
|
67
|
+
body: opts.msg_body,
|
73
68
|
body_type: "HTML",
|
74
|
-
to_recipients:
|
69
|
+
to_recipients: opts.msg_to
|
75
70
|
}
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
files = split("attachments", opts).map { |f| File.open(f, "r") }
|
81
|
-
msg[:file_attachments] = files
|
82
|
-
end
|
83
|
-
|
84
|
-
def close_attachments(msg)
|
85
|
-
return if msg[:file_attachments].nil? || msg[:file_attachments].empty?
|
86
|
-
msg[:file_attachments].each(&:close)
|
71
|
+
files = opts.msg_attachments.map { |f| File.open(f, "r") }
|
72
|
+
msg[:file_attachments] = files unless files.empty?
|
73
|
+
msg[:cc_recipients] = opts["cc"] if opts.key? "cc"
|
74
|
+
msg
|
87
75
|
end
|
88
76
|
|
89
77
|
private
|
data/lib/lazylead/home.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# The MIT License
|
4
4
|
#
|
5
|
-
# Copyright (c) 2019-
|
5
|
+
# Copyright (c) 2019-2021 Yurii Dubinka
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the "Software"),
|
data/lib/lazylead/log.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# The MIT License
|
4
4
|
#
|
5
|
-
# Copyright (c) 2019-
|
5
|
+
# Copyright (c) 2019-2021 Yurii Dubinka
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the "Software"),
|
data/lib/lazylead/model.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# The MIT License
|
4
4
|
#
|
5
|
-
# Copyright (c) 2019-
|
5
|
+
# Copyright (c) 2019-2021 Yurii Dubinka
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the "Software"),
|
@@ -68,9 +68,7 @@ module Lazylead
|
|
68
68
|
opts.each_with_object({}) do |e, o|
|
69
69
|
k = e[0]
|
70
70
|
v = e[1]
|
71
|
-
if v.respond_to?
|
72
|
-
v = ENV[v.slice(2, v.length - 3)] if v.start_with? "${"
|
73
|
-
end
|
71
|
+
v = ENV[v.slice(2, v.length - 3)] if v.respond_to?(:start_with?) && v.start_with?("${")
|
74
72
|
o[k] = v
|
75
73
|
end
|
76
74
|
end
|
@@ -106,6 +104,7 @@ module Lazylead
|
|
106
104
|
sys = system.connect
|
107
105
|
opts = props
|
108
106
|
opts = detect_cc(sys) if opts.key? "cc"
|
107
|
+
opts["system"] = second_sys if opts.numeric? "system"
|
109
108
|
action.constantize.new.run(sys, postman, opts)
|
110
109
|
end
|
111
110
|
|
@@ -137,12 +136,12 @@ module Lazylead
|
|
137
136
|
|
138
137
|
def props
|
139
138
|
@props ||= begin
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
139
|
+
if team.nil?
|
140
|
+
Opts.new(env(to_hash))
|
141
|
+
else
|
142
|
+
Opts.new(env(team.to_hash.merge(to_hash)))
|
143
|
+
end
|
144
|
+
end
|
146
145
|
end
|
147
146
|
|
148
147
|
def postman
|
@@ -153,17 +152,21 @@ module Lazylead
|
|
153
152
|
end
|
154
153
|
end
|
155
154
|
|
155
|
+
def second_sys
|
156
|
+
sys = System.find(props["system"])
|
157
|
+
raise "ll-014: No ticketing system found for #{self}" if sys.nil?
|
158
|
+
sys.connect
|
159
|
+
end
|
160
|
+
|
156
161
|
private
|
157
162
|
|
158
163
|
# Parse scheduling #type and #unit
|
159
164
|
def trigger
|
160
165
|
@trigger ||= begin
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
trg.map(&:strip).map(&:chomp)
|
166
|
-
end
|
166
|
+
trg = schedule.split(":")
|
167
|
+
raise "ll-007: illegal schedule format '#{schedule}'" unless trg.size == 2
|
168
|
+
trg.map(&:strip).map(&:chomp)
|
169
|
+
end
|
167
170
|
end
|
168
171
|
end
|
169
172
|
|
@@ -179,6 +182,10 @@ module Lazylead
|
|
179
182
|
@log = log
|
180
183
|
end
|
181
184
|
|
185
|
+
# @todo #/DEV Remove the suppression during next refactoring (or enhancements)
|
186
|
+
# for the method below
|
187
|
+
#
|
188
|
+
# rubocop:disable Metrics/AbcSize
|
182
189
|
def exec
|
183
190
|
Logging.mdc["tid"] = "task #{id}"
|
184
191
|
@log.debug "'#{name}' is started."
|
@@ -189,12 +196,13 @@ module Lazylead
|
|
189
196
|
rescue StandardError => e
|
190
197
|
msg = <<~MSG
|
191
198
|
ll-006: Task ##{id} #{e} (#{e.class}) at #{self}
|
192
|
-
#{Backtrace.new(e) if ARGV.include? '--trace'}
|
199
|
+
#{Backtrace.new(e) if ARGV.include? '--trace'}
|
193
200
|
MSG
|
194
201
|
@log.error msg
|
195
202
|
ensure
|
196
203
|
Logging.mdc["tid"] = ""
|
197
204
|
end
|
205
|
+
# rubocop:enable Metrics/AbcSize
|
198
206
|
end
|
199
207
|
|
200
208
|
# Ticketing systems to monitor.
|
data/lib/lazylead/opts.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# The MIT License
|
4
4
|
#
|
5
|
-
# Copyright (c) 2019-
|
5
|
+
# Copyright (c) 2019-2021 Yurii Dubinka
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the "Software"),
|
@@ -34,7 +34,7 @@ module Lazylead
|
|
34
34
|
# License:: MIT
|
35
35
|
class Opts
|
36
36
|
extend Forwardable
|
37
|
-
def_delegators :@origin, :[], :[]=, :to_s, :key?, :fetch, :
|
37
|
+
def_delegators :@origin, :[], :[]=, :to_s, :key?, :fetch, :except, :each, :each_pair, :sort_by
|
38
38
|
|
39
39
|
def initialize(origin = {})
|
40
40
|
@origin = origin
|
@@ -43,7 +43,13 @@ module Lazylead
|
|
43
43
|
# Split text value by delimiter, trim all spaces and reject blank items
|
44
44
|
def slice(key, delim)
|
45
45
|
return [] unless to_h.key? key
|
46
|
-
to_h[key].split(delim)
|
46
|
+
trim to_h[key].split(delim)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Trim all spaces and reject blank items in array
|
50
|
+
def trim(arr)
|
51
|
+
return [] if arr.nil?
|
52
|
+
arr.map(&:chomp).map(&:strip).reject(&:blank?)
|
47
53
|
end
|
48
54
|
|
49
55
|
def blank?(key)
|
@@ -77,5 +83,64 @@ module Lazylead
|
|
77
83
|
return Salt.new(sid).decrypt(text) if ENV.key? sid
|
78
84
|
text
|
79
85
|
end
|
86
|
+
|
87
|
+
def merge(args)
|
88
|
+
return self unless args.is_a? Hash
|
89
|
+
Opts.new @origin.merge(args)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Construct html document from template and binds.
|
93
|
+
def msg_body(template = "template")
|
94
|
+
Email.new(
|
95
|
+
to_h[template],
|
96
|
+
to_h.merge(version: Lazylead::VERSION)
|
97
|
+
).render
|
98
|
+
end
|
99
|
+
|
100
|
+
def msg_to(delim = ",")
|
101
|
+
sliced delim, :to, "to"
|
102
|
+
end
|
103
|
+
|
104
|
+
def msg_cc(delim = ",")
|
105
|
+
sliced delim, :cc, "cc"
|
106
|
+
end
|
107
|
+
|
108
|
+
def msg_from(delim = ",")
|
109
|
+
sliced delim, :from, "from"
|
110
|
+
end
|
111
|
+
|
112
|
+
def msg_attachments(delim = ",")
|
113
|
+
sliced(delim, :attachments, "attachments").select { |f| File.file? f }
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# Find the option by key and split by delimiter
|
118
|
+
# Opts.new("key" => "a,b").sliced(",", "key") => [a, b]
|
119
|
+
# Opts.new(key: "a,b").sliced(",", :key) => [a, b]
|
120
|
+
# Opts.new(key: "a,b").sliced(",", "key", :key) => [a, b]
|
121
|
+
# Opts.new(key: "").sliced ",", :key) => []
|
122
|
+
#
|
123
|
+
def sliced(delim, *keys)
|
124
|
+
return [] if keys.empty?
|
125
|
+
key = keys.detect { |k| key? k }
|
126
|
+
val = to_h[key]
|
127
|
+
return [] if val.nil? || val.blank?
|
128
|
+
return val if val.is_a? Array
|
129
|
+
return [val] unless val.include? delim
|
130
|
+
slice key, delim
|
131
|
+
end
|
132
|
+
|
133
|
+
# Ensure that particular key from options is a positive numer
|
134
|
+
# Opts.new("key" => "1").numeric? "key" => true
|
135
|
+
# Opts.new("key" => "0").numeric? "key" => false
|
136
|
+
# Opts.new("key" => ".").numeric? "key" => false
|
137
|
+
# Opts.new("key" => "nil").numeric? "key" => false
|
138
|
+
def numeric?(key)
|
139
|
+
to_h[key].to_i.positive?
|
140
|
+
end
|
141
|
+
|
142
|
+
def construct(field, delim: ",")
|
143
|
+
slice(field, delim).map(&:constantize).map(&:new)
|
144
|
+
end
|
80
145
|
end
|
81
146
|
end
|
data/lib/lazylead/postman.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# The MIT License
|
4
4
|
#
|
5
|
-
# Copyright (c) 2019-
|
5
|
+
# Copyright (c) 2019-2021 Yurii Dubinka
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the "Software"),
|
@@ -44,8 +44,6 @@ module Lazylead
|
|
44
44
|
# Copyright:: Copyright (c) 2019-2020 Yurii Dubinka
|
45
45
|
# License:: MIT
|
46
46
|
class Postman
|
47
|
-
include Emailing
|
48
|
-
|
49
47
|
def initialize(log = Log.new)
|
50
48
|
@log = log
|
51
49
|
end
|
@@ -53,32 +51,29 @@ module Lazylead
|
|
53
51
|
# Send an email.
|
54
52
|
# :opts :: the mail configuration like to, from, cc, subject, template.
|
55
53
|
def send(opts)
|
56
|
-
|
57
|
-
|
58
|
-
|
54
|
+
if opts.msg_to.empty?
|
55
|
+
@log.warn "ll-013: Email can't be sent to '#{opts.msg_to}," \
|
56
|
+
" more: '#{opts}'"
|
57
|
+
else
|
58
|
+
mail = make_email(opts)
|
59
|
+
mail.deliver
|
60
|
+
@log.debug "#{__FILE__} sent '#{mail.subject}' to '#{mail.to}'."
|
61
|
+
end
|
59
62
|
end
|
60
63
|
|
61
64
|
# Construct an email based on input arguments
|
62
65
|
def make_email(opts)
|
63
66
|
mail = Mail.new
|
64
|
-
mail.to opts
|
65
|
-
mail.from opts
|
66
|
-
mail.cc opts
|
67
|
+
mail.to opts.msg_to
|
68
|
+
mail.from opts.msg_from
|
69
|
+
mail.cc opts.msg_cc if opts.key? "cc"
|
67
70
|
mail.subject opts["subject"]
|
68
|
-
html = make_body(opts)
|
69
71
|
mail.html_part do
|
70
72
|
content_type "text/html; charset=UTF-8"
|
71
|
-
body
|
73
|
+
body opts.msg_body
|
72
74
|
end
|
73
|
-
|
75
|
+
opts.msg_attachments.each { |f| mail.add_file f }
|
74
76
|
mail
|
75
77
|
end
|
76
|
-
|
77
|
-
def add_attachments(mail, opts)
|
78
|
-
return unless opts.key?("attachments") || opts.key?(:attachments)
|
79
|
-
attach = opts["attachments"] || opts[:attachments]
|
80
|
-
return if attach.nil?
|
81
|
-
attach.select { |a| File.file? a }.each { |a| mail.add_file a }
|
82
|
-
end
|
83
78
|
end
|
84
79
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# The MIT License
|
4
|
+
#
|
5
|
+
# Copyright (c) 2019-2021 Yurii Dubinka
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the "Software"),
|
9
|
+
# to deal in the Software without restriction, including without limitation
|
10
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
11
|
+
# and/or sell copies of the Software, and to permit persons to whom
|
12
|
+
# the Software is furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included
|
15
|
+
# in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
22
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
23
|
+
# OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
|
25
|
+
module Lazylead
|
26
|
+
#
|
27
|
+
# Allows to load all ruby files within particular dir.
|
28
|
+
#
|
29
|
+
class Requires
|
30
|
+
def initialize(dir)
|
31
|
+
@dir = dir
|
32
|
+
end
|
33
|
+
|
34
|
+
def load
|
35
|
+
Dir[File.join(@dir, "*.rb")].sort.each { |f| require f }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|