actionslack 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7d806e62f1769081a642b1bc493bb2bff9385e12a42695c0efd50ee40a6c8d05
4
+ data.tar.gz: 8bb05daac3e625e206c7ba47141fe88272831b531513c732916a4acaeb8e1635
5
+ SHA512:
6
+ metadata.gz: ee9728f120912769b9eccf32bd4a77c8b63d1cd5a888a7f0ea25a2019216e31aeb528c461cb3a6fd10dc193405999cde8ab8f336be507de6f8cf95d564a9c4f1
7
+ data.tar.gz: 030caa0c7a13a46b7bdaadc5607bce2c8114b89c78a40785b21e02d721ba68c561e50235b33278e012ea4457336854c11bc82c6c921c15f78e145fb75cbeb457
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ inherit_from:
2
+ - .rubocop_todo.yml
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.6
6
+
7
+ Metrics/BlockLength:
8
+ Exclude:
9
+ - spec/**/*
10
+
11
+ Style/StringLiterals:
12
+ Enabled: true
13
+ EnforcedStyle: single_quotes
14
+
15
+ Style/StringLiteralsInInterpolation:
16
+ Enabled: true
17
+ EnforcedStyle: single_quotes
18
+
19
+ Layout/LineLength:
20
+ Max: 120
21
+
22
+ Security/YAMLLoad:
23
+ Enabled: false
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,2 @@
1
+ Style/Documentation:
2
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-10-22
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at wetsand.wfs@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in actionslack.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+
10
+ gem 'rspec', '~> 3.0'
11
+
12
+ gem 'rubocop', '~> 1.21'
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # ActionSlack
2
+
3
+ ActionSlack is a framework that supports your implementation of slack notification functionality, inspierd by Rails.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ $ bundle add actionslack
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ $ gem install actionslack
14
+
15
+ ## Usage
16
+
17
+ First, prepare a file with name 'config/slack_webhooks.yml' and register name and url fields of [Slack Incoming Webhook](https://slack.com/help/articles/115005265063-Incoming-webhooks-for-Slack) as array.
18
+
19
+ ```yaml
20
+ - name: channel_onboarding
21
+ url: https://hooks.slack.com/services/DUMMY/INCOMING_WEBHOOK_URL
22
+ ```
23
+
24
+ Next, define two methods.
25
+ One is the template for the message to be sent.
26
+ The other must be a name of one of addresses you have just registered in `config/slack_webhooks.yml`.
27
+
28
+ Once everything is registered, you just call method `notify` to that template.
29
+
30
+ ```ruby
31
+ class WelcomingNewCommer < ActionSlack::Base
32
+ self.attributes = [:new_person]
33
+
34
+ def webhook_name
35
+ 'channel_onboarding'
36
+ end
37
+
38
+ def message
39
+ <<~MSG
40
+ Welcome, #{new_person.name}
41
+ MSG
42
+ end
43
+ end
44
+
45
+ class Person
46
+ attr_reader :name
47
+
48
+ def initialize(name)
49
+ @name = name
50
+ end
51
+ end
52
+
53
+ person = Person.new('John')
54
+
55
+ WelcomingNewCommer.notify(new_person: person)
56
+ ```
57
+
58
+ ## Development
59
+
60
+ I will not release this to rubygems until becomes stable.
61
+ Until then, I develop this privately.
62
+
63
+ I'm also planning providing rspec tools. Stay tuned.
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kakubin/actionslack. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/kakubin/actionslack/blob/main/CODE_OF_CONDUCT.md).
68
+
69
+ ## Code of Conduct
70
+
71
+ Everyone interacting in the ActionSlack project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/kakubin/actionslack/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ module ActionSlack
6
+ class Base
7
+ extend Forwardable
8
+
9
+ def_delegators :webhook, :url
10
+
11
+ class << self
12
+ def notify(**kargs)
13
+ instance = create(**kargs)
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
20
+ end
21
+
22
+ def attributes=(attrs)
23
+ @attributes = Array.wrap(attrs)
24
+ end
25
+
26
+ private
27
+
28
+ def create(**kargs)
29
+ instance_attributes = @attributes.presence || []
30
+
31
+ missing_arguments = instance_attributes - kargs.keys
32
+ raise ArgumentError, "missing keywords: #{missing_arguments.join(', ')}" if missing_arguments.present?
33
+
34
+ instance = new
35
+
36
+ instance_attributes.each do |instance_attribute|
37
+ instance.instance_variable_set(:"@#{instance_attribute}", kargs[instance_attribute])
38
+ instance.class_eval { attr_reader :"#{instance_attribute}" }
39
+ end
40
+
41
+ instance
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def webhook_name
48
+ raise NotImplementedError
49
+ end
50
+
51
+ def webhook
52
+ @webhook ||= Webhook.find(webhook_name)
53
+ end
54
+
55
+ def message
56
+ raise NotImplementedError
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionSlack
4
+ class Configuration
5
+ attr_accessor :filepath, :async
6
+
7
+ def self.set_default(name, default)
8
+ define_method name do
9
+ @configuration[name]
10
+ end
11
+
12
+ define_method :"#{name}=" do |value|
13
+ @configuration[name] = value
14
+ end
15
+
16
+ default_configuration[name] = default
17
+ end
18
+
19
+ def self.default_configuration
20
+ @default_configuration ||= {}
21
+ end
22
+
23
+ def initialize
24
+ @configuration = self.class.default_configuration.dup
25
+ end
26
+
27
+ set_default(:filepath, 'config/slack_webhooks.yml')
28
+ set_default(:async, true)
29
+ set_default(:env, :development)
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionSlack
4
+ class Notifier
5
+ def self.notify(url:, message:)
6
+ Slack::Notifier.new(url).post(text: message)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionSlack
4
+ class SendJob < ActiveJob::Base
5
+ def perform(url:, message:)
6
+ Notifier.notify(url: url, message: message)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionSlack
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionSlack
4
+ class Webhook
5
+ attr_reader :name, :url
6
+
7
+ class << self
8
+ def webhooks
9
+ @webhooks ||= load_webhooks
10
+ end
11
+
12
+ def find(name)
13
+ webhooks.find { |webhook| webhook.name == name }
14
+ end
15
+
16
+ private
17
+
18
+ def load_webhooks
19
+ filepath = ActionSlack.configuration.filepath
20
+ raise unless File.exist?(filepath)
21
+
22
+ erb = ERB.new(File.read(filepath))
23
+ yml = load_yaml(erb.result)
24
+ yml.map(&method(:new))
25
+ end
26
+
27
+ def load_yaml(src)
28
+ if Psych::VERSION > '4.0'
29
+ YAML.load(src, symbolize_names: true, aliases: true, freeze: true)
30
+ else
31
+ YAML.safe_load(src)
32
+ end
33
+ end
34
+ end
35
+
36
+ def initialize(webhook)
37
+ @name = webhook[:name]
38
+ @url = webhook[:url]
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+ require 'active_support/core_ext'
5
+ require 'yaml'
6
+ require 'erb'
7
+ require 'slack-notifier'
8
+
9
+ module ActionSlack
10
+ extend ActiveSupport::Autoload
11
+
12
+ autoload :Configuration
13
+ autoload :Webhook
14
+ autoload :Notifier
15
+ autoload :Base
16
+
17
+ autoload :SendJob if const_defined?(:ActiveJob)
18
+
19
+ class << self
20
+ def configure
21
+ yield configuration
22
+ end
23
+
24
+ def configuration
25
+ @configuration ||= Configuration.new
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ module ActionSlack
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: actionslack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kakubin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-11-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: slack-notifier
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activejob
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: actionslack
56
+ email:
57
+ - wetsand.wfs@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".rspec"
63
+ - ".rubocop.yml"
64
+ - ".rubocop_todo.yml"
65
+ - CHANGELOG.md
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - README.md
69
+ - Rakefile
70
+ - lib/action_slack.rb
71
+ - lib/action_slack/base.rb
72
+ - lib/action_slack/configuration.rb
73
+ - lib/action_slack/notifier.rb
74
+ - lib/action_slack/send_job.rb
75
+ - lib/action_slack/version.rb
76
+ - lib/action_slack/webhook.rb
77
+ - sig/action_slack.rbs
78
+ homepage: https://github.com/kakubin/actionslack
79
+ licenses: []
80
+ metadata:
81
+ allowed_push_host: https://rubygems.org
82
+ homepage_uri: https://github.com/kakubin/actionslack
83
+ source_code_uri: https://github.com/kakubin/actionslack
84
+ changelog_uri: https://github.com/kakubin/actionslack/blob/main/CHANGELOG.md
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: 2.6.0
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubygems_version: 3.3.7
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: actionslack
104
+ test_files: []