diff --git a/init.rb b/init.rb index fe6b7d5..5871e88 100644 --- a/init.rb +++ b/init.rb @@ -1,14 +1,11 @@ -require_dependency 'stopwatch' -require 'stopwatch/hooks' - Redmine::Plugin.register :stopwatch do name 'Redmine Stopwatch Plugin' author 'Jens Krämer' author_url 'https://jkraemer.net/' description "Start/stop timer and quick access to today's time bookings for Redmine" - version '0.2.0' + version '1.0.0' - requires_redmine version_or_higher: '3.4.0' + requires_redmine version_or_higher: '5.0.0' settings default: { 'default_activity' => 'always_ask', }, partial: 'stopwatch/settings' @@ -21,10 +18,4 @@ Redmine::Plugin.register :stopwatch do if: ->(*_){ User.current.logged? and User.current.allowed_to?(:log_time, nil, global: true) } end -Rails.configuration.to_prepare do - Stopwatch::ContextMenusControllerPatch.apply - Stopwatch::IssuesControllerPatch.apply - Stopwatch::TimeEntryPatch.apply - Stopwatch::UserPatch.apply -end - +Stopwatch.setup diff --git a/lib/stopwatch.rb b/lib/stopwatch.rb index 723e8f5..ef60a0f 100644 --- a/lib/stopwatch.rb +++ b/lib/stopwatch.rb @@ -1,6 +1,15 @@ # frozen_string_literal: true module Stopwatch + def self.setup + Stopwatch::ContextMenusControllerPatch.apply + Stopwatch::IssuesControllerPatch.apply + ::TimeEntry.prepend Stopwatch::TimeEntryPatch + ::User.prepend Stopwatch::UserPatch + Stopwatch::Hooks # just load it + end + + def self.settings Setting.plugin_stopwatch end diff --git a/lib/stopwatch/time_entry_patch.rb b/lib/stopwatch/time_entry_patch.rb index 4580eca..f576d89 100644 --- a/lib/stopwatch/time_entry_patch.rb +++ b/lib/stopwatch/time_entry_patch.rb @@ -1,13 +1,9 @@ module Stopwatch module TimeEntryPatch - def self.apply - TimeEntry.prepend self unless TimeEntry < self - end + extend ActiveSupport::Concern - def self.prepended(base) - base.class_eval do - before_destroy :stop_timer - end + prepended do + before_destroy :stop_timer end def stop_timer diff --git a/lib/stopwatch/user_patch.rb b/lib/stopwatch/user_patch.rb index c7c9ff8..0eefcda 100644 --- a/lib/stopwatch/user_patch.rb +++ b/lib/stopwatch/user_patch.rb @@ -1,8 +1,6 @@ module Stopwatch module UserPatch - def self.apply - User.prepend self unless User < self - end + extend ActiveSupport::Concern def timer_running? Stopwatch::Timer.new(self).running?