Files
openproject/lib/api/patchable_api.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
2.2 KiB
Ruby
Raw Normal View History

2015-03-17 17:18:04 +01:00
#-- copyright
2020-01-15 11:31:26 +01:00
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
2015-03-17 17:18:04 +01:00
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
2021-01-13 17:47:45 +01:00
# Copyright (C) 2006-2013 Jean-Philippe Lang
2015-03-17 17:18:04 +01:00
# Copyright (C) 2010-2013 the ChiliProject Team
#
# 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.
#
# See COPYRIGHT and LICENSE files for more details.
2015-03-17 17:18:04 +01:00
#++
module API
module PatchableAPI
def self.included(base)
2019-02-13 10:32:47 +01:00
base.class_eval do
prepend ClassMethods
end
2015-03-17 17:18:04 +01:00
end
module ClassMethods
2019-02-13 10:32:47 +01:00
def inherited(api, base_instance_parent = Grape::API::Instance)
2015-03-17 17:18:04 +01:00
super
# run unscoped patches (i.e. patches that are on the class root, not in a namespace)
2019-02-13 10:32:47 +01:00
api.send(:execute_patches_for, nil)
2015-03-17 17:18:04 +01:00
end
2015-03-18 16:24:26 +01:00
def namespace(name, *args, &)
2015-03-17 17:18:04 +01:00
super(name, *args) do
instance_eval(&)
execute_patches_for(name)
end
end
# we need to repeat all the aliases for them to work properly...
alias_method :group, :namespace
alias_method :resource, :namespace
alias_method :resources, :namespace
alias_method :segment, :namespace
private
def execute_patches_for(path)
if patches[path]
patches[path].each do |patch|
instance_eval(&patch)
end
end
end
def patches
2019-02-13 10:32:47 +01:00
::Constants::APIPatchRegistry.patches_for(self)
2015-03-17 17:18:04 +01:00
end
end
end
end