Skip to content

Commit

Permalink
Merge pull request #38 from cat-in-136/fix-zeitwerk-check
Browse files Browse the repository at this point in the history
Fix bug where zeitwerk:check task fails
  • Loading branch information
cat-in-136 authored Apr 10, 2022
2 parents 2b42659 + ce020fe commit f3fda7a
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 93 deletions.
4 changes: 2 additions & 2 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

require File.expand_path('../lib/redmine_hearts/acts_as_heartable.rb', __FILE__)
require File.expand_path('../lib/redmine_hearts/redmine_heartable_patch.rb', __FILE__)
require File.expand_path('../lib/redmine/acts/heartable.rb', __FILE__)
require File.expand_path('../lib/redmine_hearts/heartable_patch.rb', __FILE__)
require File.expand_path('../lib/redmine_hearts/view_hook.rb', __FILE__)

Redmine::Plugin.register :redmine_hearts do
Expand Down
File renamed without changes.
50 changes: 50 additions & 0 deletions lib/redmine_hearts/heartable_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true
#
# Redmine Hearts plugin
# Copyright (C) @cat_in_136
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

module RedmineHearts
module HeartablePatch
def self.included(base) # :nodoc:
options = {}
if base == Message
options[:joins] = :board
options[:project_key] = "#{Board.table_name}.project_id"
elsif base == WikiPage
options[:joins] = :wiki
options[:project_key] = "#{Wiki.table_name}.project_id"
elsif base == Journal
options[:project_key] = Proc.new do |scope, projects|
scope.where(:journalized => Issue.where(:project_id => projects.map(&:id)))
end
end

base.class_eval do
unloadable
acts_as_heartable options
end
end
end
end

Board.send(:include, RedmineHearts::HeartablePatch)
Issue.send(:include, RedmineHearts::HeartablePatch)
Message.send(:include, RedmineHearts::HeartablePatch)
News.send(:include, RedmineHearts::HeartablePatch)
Wiki.send(:include, RedmineHearts::HeartablePatch)
WikiPage.send(:include, RedmineHearts::HeartablePatch)
Journal.send(:include, RedmineHearts::HeartablePatch)
49 changes: 0 additions & 49 deletions lib/redmine_hearts/redmine_heartable_patch.rb

This file was deleted.

86 changes: 44 additions & 42 deletions lib/redmine_hearts/view_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,54 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software

class RedmineViewHookForDevHook < Redmine::Hook::ViewListener

def view_layouts_base_html_head(context={})
controller = context[:controller]
subject = heartable_subject(controller)
if subject
controller.send(:render_to_string, {
:partial => "hooks/redmine_hearts/view_layouts_base_html_head",
:locals => context.merge(:@heartable => subject)
})
end
end

def view_layouts_base_content(context={})
controller = context[:controller]
subject = heartable_subject(controller)
if subject
controller.send(:render_to_string, {
:partial => "hooks/redmine_hearts/view_layouts_base_content",
:locals => context.merge(:@heartable => subject)
})
module RedmineHearts
class ViewHook < Redmine::Hook::ViewListener

def view_layouts_base_html_head(context={})
controller = context[:controller]
subject = heartable_subject(controller)
if subject
controller.send(:render_to_string, {
:partial => "hooks/redmine_hearts/view_layouts_base_html_head",
:locals => context.merge(:@heartable => subject)
})
end
end
end

def view_account_left_bottom(context={})
heart_count = Heart.where(:user => context[:user]).count
if heart_count > 0

def view_layouts_base_content(context={})
controller = context[:controller]
controller.send(:render_to_string, {
:partial => "hooks/redmine_hearts/view_account_left_bottom",
:locals => context.merge(:@heart_count => heart_count)
})
subject = heartable_subject(controller)
if subject
controller.send(:render_to_string, {
:partial => "hooks/redmine_hearts/view_layouts_base_content",
:locals => context.merge(:@heartable => subject)
})
end
end
end

private
def heartable_subject(controller)
subject = nil
if (controller && (controller.action_name == 'show'))
model_klass = controller.controller_name.classify.safe_constantize
if model_klass && model_klass.included_modules.include?(Redmine::Acts::Heartable::InstanceMethods)
subject = controller.instance_variable_get("@#{controller.controller_name.singularize}")

def view_account_left_bottom(context={})
heart_count = Heart.where(:user => context[:user]).count
if heart_count > 0
controller = context[:controller]
controller.send(:render_to_string, {
:partial => "hooks/redmine_hearts/view_account_left_bottom",
:locals => context.merge(:@heart_count => heart_count)
})
end
end

private
def heartable_subject(controller)
subject = nil
if (controller && (controller.action_name == 'show'))
model_klass = controller.controller_name.classify.safe_constantize
if model_klass && model_klass.included_modules.include?(Redmine::Acts::Heartable::InstanceMethods)
subject = controller.instance_variable_get("@#{controller.controller_name.singularize}")
end
elsif ((controller.kind_of? NewsController) && (controller.action_name == 'index'))
subject = controller.instance_variable_get(:@newss)
end
elsif ((controller.kind_of? NewsController) && (controller.action_name == 'index'))
subject = controller.instance_variable_get(:@newss)
subject
end
subject
end
end

0 comments on commit f3fda7a

Please sign in to comment.