Skip to content
Snippets Groups Projects
Commit 013027fe authored by Alexander Olofsson's avatar Alexander Olofsson
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
.bundle/
log/*.log
pkg/
test/dummy/db/*.sqlite3
test/dummy/db/*.sqlite3-journal
test/dummy/log/*.log
test/dummy/node_modules/
test/dummy/yarn-error.log
test/dummy/storage/
test/dummy/tmp/
Gemfile 0 → 100644
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Declare your gem's dependencies in foreman_notification_send.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec
# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.
# To use a debugger
# gem 'byebug', group: [:development, :test]
The MIT License (MIT)
Copyright (c) 2018 Alexander Olofsson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
# ForemanNotificationSend
Short description and motivation.
## Usage
How to use my plugin.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'foreman_notification_send'
```
And then execute:
```bash
$ bundle
```
Or install it yourself as:
```bash
$ gem install foreman_notification_send
```
## Contributing
Contribution directions go here.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
Rakefile 0 → 100644
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
require 'rdoc/task'
RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'ForemanNotificationSend'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.md')
rdoc.rdoc_files.include('lib/**/*.rb')
end
require 'bundler/gem_tasks'
require 'rake/testtask'
Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end
task default: :test
# frozen_string_literal: true
module ForemanNotificationSend
module NotificationExtensions
def self.prepended(base)
base.class_eval do
after_save :send_notification
end
end
def send_notification
puts to_markdown
puts to_html
end
def to_html
if actions
action_str = ''
(actions[:links] || []).each do |action|
next unless action.key?(:href) && action.key?(:title)
action_str += ' | ' unless action_str.empty?
action_str += "<a href=\"#{action[:href]}\">#{action[:title]}</a>"
end
action_str = "<br/>[#{action_str}]"
end
"<b>#{notification_blueprint.group}</b>: #{message}#{action_str}"
end
def to_markdown
if actions
action_str = ''
(actions[:links] || []).each do |action|
next unless action.key?(:href) && action.key?(:title)
action_str += ' | ' unless action_str.empty?
action_str += "[#{action[:title]}](#{action[:href]})"
end
action_str = " \n[#{action_str}]"
end
"**#{notification_blueprint.group}**: #{message}#{action_str}"
end
end
end
require File.join File.expand_path('lib', __dir__), 'foreman_notification_send/version'
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = 'foreman_notification_send'
s.version = ForemanNotificationSend::VERSION
s.authors = ['Alexander Olofsson']
s.email = ['alexander.olofsson@liu.se']
# s.homepage = 'TODO'
s.summary = 'summary'
# s.description = 'TODO: Description of ForemanNotificationSend.'
s.license = 'MIT'
s.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
end
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
s.require_paths = ['lib']
s.add_development_dependency 'bundler', '~> 1.16'
s.add_development_dependency 'minitest', '~> 5.0'
s.add_development_dependency 'rake', '~> 10.0'
end
require 'foreman_notification_send/engine'
module ForemanNotificationSend
# Your code goes here...
end
# frozen_string_literal: true
module ForemanNotificationSend
class Engine < ::Rails::Engine
engine_name 'foreman_notification_send'
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
initializer 'foreman_ipxe.load_default_settings', before: :load_config_initializers do
require_dependency File.expand_path('../../app/models/setting/notification_send.rb', __dir__) if \
begin
Setting.table_exists?
rescue StandardError
(false)
end
end
initializer 'foreman_notification_send.register_plugin', before: :finisher_hook do |_app|
Foreman::Plugin.register :foreman_notification_send do
requires_foreman '>= 1.16'
end
end
config.to_prepare do
begin
Notification.send(:prepend, ForemanNotificationSend::NotificationExtensions)
rescue StandardError => e
Rails.logger.fatal "foreman_notification_send: skipping engine hook (#{e})"
end
end
end
end
module ForemanNotificationSend
VERSION = '0.1.0'.freeze
end
# desc "Explaining what the task does"
# task :foreman_notification_send do
# # Task goes here
# end
require 'test_helper'
class ForemanNotificationSend::Test < ActiveSupport::TestCase
test "truth" do
assert_kind_of Module, ForemanNotificationSend
end
end
# Configure Rails Environment
ENV["RAILS_ENV"] = "test"
require_relative "../test/dummy/config/environment"
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)]
require "rails/test_help"
# Filter out Minitest backtrace while allowing backtrace from other libraries
# to be shown.
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
require "rails/test_unit/reporter"
Rails::TestUnitReporter.executable = 'bin/test'
# Load fixtures from the engine
if ActiveSupport::TestCase.respond_to?(:fixture_path=)
ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__)
ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files"
ActiveSupport::TestCase.fixtures :all
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment