actionslack 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 7d806e62f1769081a642b1bc493bb2bff9385e12a42695c0efd50ee40a6c8d05
4
- data.tar.gz: 8bb05daac3e625e206c7ba47141fe88272831b531513c732916a4acaeb8e1635
3
+ metadata.gz: 27afb3fa4f6da31ef2138615bbf368d9cded850396c67122d73a647ca6bf2d1d
4
+ data.tar.gz: 9b3804e467796b8a3a0d44d720afd384e8a46cf8840a2250b2ad60b0f3ffe98f
5
5
  SHA512:
6
- metadata.gz: ee9728f120912769b9eccf32bd4a77c8b63d1cd5a888a7f0ea25a2019216e31aeb528c461cb3a6fd10dc193405999cde8ab8f336be507de6f8cf95d564a9c4f1
7
- data.tar.gz: 030caa0c7a13a46b7bdaadc5607bce2c8114b89c78a40785b21e02d721ba68c561e50235b33278e012ea4457336854c11bc82c6c921c15f78e145fb75cbeb457
6
+ metadata.gz: 2ad13e13c673e0e4c208ae4950e27403d271d23389f522485b00ce667fb166fbb49dd40340c511dd6a3108604d394b0d12861690787c41870ad4ddfc726a5b1f
7
+ data.tar.gz: 2f8394d469eddc413087431ff0bebfa62f018ec09cb0aea9b191fbc0236a152fc5ba2a920fc58f8da0f66cf5f26164e512c14989c73ea599916505e2ec9ee646
@@ -12,11 +12,7 @@ module ActionSlack
12
12
  def notify(**kargs)
13
13
  instance = create(**kargs)
14
14
 
15
- if ActionSlack.configuration.async
16
- SendJob.perform_later(url: instance.url, message: instance.message)
17
- else
18
- Notifier.notify(url: instance.url, message: instance.message)
19
- end
15
+ Notifier.notify(url: instance.url, message: instance.message)
20
16
  end
21
17
 
22
18
  def attributes=(attrs)
@@ -24,8 +24,18 @@ module ActionSlack
24
24
  @configuration = self.class.default_configuration.dup
25
25
  end
26
26
 
27
+ def async?
28
+ async
29
+ end
30
+
31
+ %i[local testflight production].each do |type_name|
32
+ define_method :"#{type_name}?" do
33
+ type_name == type
34
+ end
35
+ end
36
+
27
37
  set_default(:filepath, 'config/slack_webhooks.yml')
28
38
  set_default(:async, true)
29
- set_default(:env, :development)
39
+ set_default(:type, :local) # production, testflight, local
30
40
  end
31
41
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionSlack
4
+ class Logger < ::Logger; end
5
+ end
@@ -1,9 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionSlack
4
- class Notifier
5
- def self.notify(url:, message:)
6
- Slack::Notifier.new(url).post(text: message)
4
+ module Notifier
5
+ module_function
6
+
7
+ def notify(url:, message:)
8
+ message = ActionSlack.configuration.testflight? ? "[ActionSlack Test Posting]\n#{message}\n" : message
9
+
10
+ if ActionSlack.configuration.async?
11
+ notify_later(url, message)
12
+ else
13
+ notify_now(url, message)
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def notify_now(url, message)
20
+ if ActionSlack.configuration.local?
21
+ ActionSlack.logger.debug { "Post to Slack webhook url: #{url}, message: \"#{message}\"" }
22
+ else
23
+ ActionSlack.logger.info { "Start posting to Slack webhook url: #{url}, message: \"#{message}\"" }
24
+ Slack::Notifier.new(url).post(text: message)
25
+ ActionSlack.logger.info 'Posted to Slack'
26
+ end
27
+ end
28
+
29
+ def notify_later(url, message)
30
+ SendJob.perform_later(url: url, message: message)
7
31
  end
8
32
  end
9
33
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module ActionSlack
4
4
  class SendJob < ActiveJob::Base
5
- def perform(url:, message:)
6
- Notifier.notify(url: url, message: message)
5
+ def perform(url, message)
6
+ Notifier.__send__(:notify_now, url, message)
7
7
  end
8
8
  end
9
9
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionSlack
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
@@ -26,9 +26,9 @@ module ActionSlack
26
26
 
27
27
  def load_yaml(src)
28
28
  if Psych::VERSION > '4.0'
29
- YAML.load(src, symbolize_names: true, aliases: true, freeze: true)
29
+ YAML.safe_load(src, symbolize_names: true, freeze: true)
30
30
  else
31
- YAML.safe_load(src)
31
+ YAML.safe_load(src, symbolize_names: true)
32
32
  end
33
33
  end
34
34
  end
data/lib/action_slack.rb CHANGED
@@ -4,6 +4,7 @@ require 'active_support'
4
4
  require 'active_support/core_ext'
5
5
  require 'yaml'
6
6
  require 'erb'
7
+ require 'logger'
7
8
  require 'slack-notifier'
8
9
 
9
10
  module ActionSlack
@@ -13,6 +14,7 @@ module ActionSlack
13
14
  autoload :Webhook
14
15
  autoload :Notifier
15
16
  autoload :Base
17
+ autoload :Logger
16
18
 
17
19
  autoload :SendJob if const_defined?(:ActiveJob)
18
20
 
@@ -24,5 +26,18 @@ module ActionSlack
24
26
  def configuration
25
27
  @configuration ||= Configuration.new
26
28
  end
29
+
30
+ def logger
31
+ @logger ||= ActionSlack::Logger.new($stdout, level: :info)
32
+ end
33
+
34
+ def logger=(logger)
35
+ if logger.nil?
36
+ self.logger.level = Logger::FATAL
37
+ return
38
+ end
39
+
40
+ @logger = logger
41
+ end
27
42
  end
28
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionslack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kakubin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-03 00:00:00.000000000 Z
11
+ date: 2022-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -70,6 +70,7 @@ files:
70
70
  - lib/action_slack.rb
71
71
  - lib/action_slack/base.rb
72
72
  - lib/action_slack/configuration.rb
73
+ - lib/action_slack/logger.rb
73
74
  - lib/action_slack/notifier.rb
74
75
  - lib/action_slack/send_job.rb
75
76
  - lib/action_slack/version.rb
@@ -97,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
98
  - !ruby/object:Gem::Version
98
99
  version: '0'
99
100
  requirements: []
100
- rubygems_version: 3.3.7
101
+ rubygems_version: 3.0.3.1
101
102
  signing_key:
102
103
  specification_version: 4
103
104
  summary: actionslack