Skip to content

Commit d473048

Browse files
author
root
committed
Replace alias_method_chain by Module prepend
1 parent 1873c1d commit d473048

19 files changed

+538
-698
lines changed

Diff for: lib/redmine_git_hosting/patches/changeset_patch.rb

+39-48
Original file line numberDiff line numberDiff line change
@@ -4,76 +4,67 @@ module RedmineGitHosting
44
module Patches
55
module ChangesetPatch
66

7-
def self.included(base)
8-
base.send(:include, InstanceMethods)
7+
def github_payload
8+
data = {}
9+
data[:id] = revision
10+
data[:message] = comments
11+
data[:timestamp] = committed_on
12+
data[:author] = author_data
13+
data[:added] = added_files
14+
data[:modified] = modified_files
15+
data[:removed] = removed_files
16+
data[:url] = url_for_revision(revision)
17+
data
918
end
1019

1120

12-
module InstanceMethods
13-
14-
def github_payload
15-
data = {}
16-
data[:id] = revision
17-
data[:message] = comments
18-
data[:timestamp] = committed_on
19-
data[:author] = author_data
20-
data[:added] = added_files
21-
data[:modified] = modified_files
22-
data[:removed] = removed_files
23-
data[:url] = url_for_revision(revision)
24-
data
25-
end
26-
27-
28-
def author_data
29-
{ name: author_name, email: author_email }
30-
end
31-
21+
def author_data
22+
{ name: author_name, email: author_email }
23+
end
3224

33-
def author_name
34-
RedmineGitHosting::Utils::Git.author_name(committer)
35-
end
3625

26+
def author_name
27+
RedmineGitHosting::Utils::Git.author_name(committer)
28+
end
3729

38-
def author_email
39-
RedmineGitHosting::Utils::Git.author_email(committer)
40-
end
4130

31+
def author_email
32+
RedmineGitHosting::Utils::Git.author_email(committer)
33+
end
4234

43-
def added_files
44-
filechanges_by_action('A')
45-
end
4635

36+
def added_files
37+
filechanges_by_action('A')
38+
end
4739

48-
def modified_files
49-
filechanges_by_action('M')
50-
end
5140

41+
def modified_files
42+
filechanges_by_action('M')
43+
end
5244

53-
def removed_files
54-
filechanges_by_action('D')
55-
end
5645

46+
def removed_files
47+
filechanges_by_action('D')
48+
end
5749

58-
def filechanges_by_action(action)
59-
filechanges.select { |c| c.action == action }.map(&:path)
60-
end
6150

51+
def filechanges_by_action(action)
52+
filechanges.select { |c| c.action == action }.map(&:path)
53+
end
6254

63-
def url_for_revision(revision)
64-
Rails.application.routes.url_helpers.url_for(
65-
controller: 'repositories', action: 'revision',
66-
id: project, repository_id: repository.identifier_param, rev: revision,
67-
only_path: false, host: Setting['host_name'], protocol: Setting['protocol']
68-
)
69-
end
7055

56+
def url_for_revision(revision)
57+
Rails.application.routes.url_helpers.url_for(
58+
controller: 'repositories', action: 'revision',
59+
id: project, repository_id: repository.identifier_param, rev: revision,
60+
only_path: false, host: Setting['host_name'], protocol: Setting['protocol']
61+
)
7162
end
7263

7364
end
7465
end
7566
end
7667

7768
unless Changeset.included_modules.include?(RedmineGitHosting::Patches::ChangesetPatch)
78-
Changeset.send(:include, RedmineGitHosting::Patches::ChangesetPatch)
69+
Changeset.send(:prepend, RedmineGitHosting::Patches::ChangesetPatch)
7970
end

Diff for: lib/redmine_git_hosting/patches/group_patch.rb

+11-19
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,34 @@ module RedmineGitHosting
44
module Patches
55
module GroupPatch
66

7-
def self.included(base)
8-
base.send(:include, InstanceMethods)
7+
def self.prepended(base)
98
base.class_eval do
109
# Relations
1110
has_many :protected_branches_members, dependent: :destroy, foreign_key: :principal_id
1211
has_many :protected_branches, through: :protected_branches_members
13-
14-
alias_method_chain :user_added, :git_hosting
15-
alias_method_chain :user_removed, :git_hosting
1612
end
1713
end
1814

1915

20-
module InstanceMethods
21-
22-
def user_added_with_git_hosting(user, &block)
23-
user_added_without_git_hosting(user, &block)
24-
protected_branches.each do |pb|
25-
RepositoryProtectedBranches::MemberManager.new(pb).add_user_from_group(user, self.id)
26-
end
16+
def user_added(user)
17+
super
18+
protected_branches.each do |pb|
19+
RepositoryProtectedBranches::MemberManager.new(pb).add_user_from_group(user, self.id)
2720
end
21+
end
2822

2923

30-
def user_removed_with_git_hosting(user, &block)
31-
user_removed_without_git_hosting(user, &block)
32-
protected_branches.each do |pb|
33-
RepositoryProtectedBranches::MemberManager.new(pb).remove_user_from_group(user, self.id)
34-
end
24+
def user_removed(user)
25+
super
26+
protected_branches.each do |pb|
27+
RepositoryProtectedBranches::MemberManager.new(pb).remove_user_from_group(user, self.id)
3528
end
36-
3729
end
3830

3931
end
4032
end
4133
end
4234

4335
unless Group.included_modules.include?(RedmineGitHosting::Patches::GroupPatch)
44-
Group.send(:include, RedmineGitHosting::Patches::GroupPatch)
36+
Group.send(:prepend, RedmineGitHosting::Patches::GroupPatch)
4537
end

Diff for: lib/redmine_git_hosting/patches/issue_patch.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module RedmineGitHosting
44
module Patches
55
module IssuePatch
66

7-
def self.included(base)
7+
def self.prepended(base)
88
base.class_eval do
99
has_one :github_issue, foreign_key: 'issue_id', class_name: 'GithubIssue', dependent: :destroy
1010
end
@@ -15,5 +15,5 @@ def self.included(base)
1515
end
1616

1717
unless Issue.included_modules.include?(RedmineGitHosting::Patches::IssuePatch)
18-
Issue.send(:include, RedmineGitHosting::Patches::IssuePatch)
18+
Issue.send(:prepend, RedmineGitHosting::Patches::IssuePatch)
1919
end

Diff for: lib/redmine_git_hosting/patches/journal_patch.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module RedmineGitHosting
44
module Patches
55
module JournalPatch
66

7-
def self.included(base)
7+
def self.prepended(base)
88
base.class_eval do
99
has_one :github_comment, foreign_key: 'journal_id', class_name: 'GithubComment', dependent: :destroy
1010
end
@@ -15,5 +15,5 @@ def self.included(base)
1515
end
1616

1717
unless Journal.included_modules.include?(RedmineGitHosting::Patches::JournalPatch)
18-
Journal.send(:include, RedmineGitHosting::Patches::JournalPatch)
18+
Journal.send(:prepend, RedmineGitHosting::Patches::JournalPatch)
1919
end

Diff for: lib/redmine_git_hosting/patches/member_patch.rb

+9-14
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,25 @@ module RedmineGitHosting
44
module Patches
55
module MemberPatch
66

7-
def self.included(base)
8-
base.send(:include, InstanceMethods)
9-
base.send(:include, RedmineGitHosting::GitoliteAccessor::Methods)
7+
include RedmineGitHosting::GitoliteAccessor::Methods
8+
9+
def self.prepended(base)
1010
base.class_eval do
1111
after_commit :update_project
1212
end
1313
end
1414

15+
private
1516

16-
module InstanceMethods
17-
18-
private
19-
20-
def update_project
21-
options = { message: "Membership changes on project '#{project}', update!" }
22-
gitolite_accessor.update_projects([project.id], options)
23-
end
24-
25-
end
17+
def update_project
18+
options = { message: "Membership changes on project '#{project}', update!" }
19+
gitolite_accessor.update_projects([project.id], options)
20+
end
2621

2722
end
2823
end
2924
end
3025

3126
unless Member.included_modules.include?(RedmineGitHosting::Patches::MemberPatch)
32-
Member.send(:include, RedmineGitHosting::Patches::MemberPatch)
27+
Member.send(:prepend, RedmineGitHosting::Patches::MemberPatch)
3328
end

Diff for: lib/redmine_git_hosting/patches/project_patch.rb

+25-30
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ module RedmineGitHosting
44
module Patches
55
module ProjectPatch
66

7-
def self.included(base)
8-
base.send(:include, InstanceMethods)
7+
def self.prepended(base)
98
base.class_eval do
109
# Add custom scope
1110
scope :active_or_closed, -> { where("status = #{Project::STATUS_ACTIVE} OR status = #{Project::STATUS_CLOSED}") }
@@ -19,51 +18,47 @@ def self.included(base)
1918
end
2019

2120

22-
module InstanceMethods
23-
24-
# Find all repositories owned by project which are Repository::Xitolite
25-
def gitolite_repos
26-
repositories.select { |x| x.is_a?(Repository::Xitolite) }.sort { |x, y| x.id <=> y.id }
27-
end
21+
# Find all repositories owned by project which are Repository::Xitolite
22+
def gitolite_repos
23+
repositories.select { |x| x.is_a?(Repository::Xitolite) }.sort { |x, y| x.id <=> y.id }
24+
end
2825

2926

30-
# Return first repo with a blank identifier (should be only one!)
31-
def repo_blank_ident
32-
Repository.where("project_id = ? and (identifier = '' or identifier is null)", id).first
33-
end
27+
# Return first repo with a blank identifier (should be only one!)
28+
def repo_blank_ident
29+
Repository.where("project_id = ? and (identifier = '' or identifier is null)", id).first
30+
end
3431

3532

36-
def users_available
37-
get_members_available('User')
38-
end
33+
def users_available
34+
get_members_available('User')
35+
end
3936

4037

41-
def groups_available
42-
get_members_available('Group')
43-
end
38+
def groups_available
39+
get_members_available('Group')
40+
end
4441

4542

46-
private
43+
private
4744

4845

49-
def get_members_available(klass)
50-
memberships.active.map(&:principal).select { |m| m.class.name == klass }.uniq.sort
51-
end
46+
def get_members_available(klass)
47+
memberships.active.map(&:principal).select { |m| m.class.name == klass }.uniq.sort
48+
end
5249

5350

54-
def additional_constraints_on_identifier
55-
if new_record? && !identifier.blank?
56-
# Make sure that identifier does not match existing repository identifier
57-
errors.add(:identifier, :taken) if Repository.find_by_identifier_and_type(identifier, 'Repository::Xitolite')
58-
end
51+
def additional_constraints_on_identifier
52+
if new_record? && !identifier.blank?
53+
# Make sure that identifier does not match existing repository identifier
54+
errors.add(:identifier, :taken) if Repository.find_by_identifier_and_type(identifier, 'Repository::Xitolite')
5955
end
60-
61-
end
56+
end
6257

6358
end
6459
end
6560
end
6661

6762
unless Project.included_modules.include?(RedmineGitHosting::Patches::ProjectPatch)
68-
Project.send(:include, RedmineGitHosting::Patches::ProjectPatch)
63+
Project.send(:prepend, RedmineGitHosting::Patches::ProjectPatch)
6964
end

0 commit comments

Comments
 (0)