提交 0af2ab18 编写于 作者: S Shinya Maeda

Decouple to_params from AtomicInternalId concern

上级 632b87a8
...@@ -14,7 +14,7 @@ module Ci ...@@ -14,7 +14,7 @@ module Ci
belongs_to :auto_canceled_by, class_name: 'Ci::Pipeline' belongs_to :auto_canceled_by, class_name: 'Ci::Pipeline'
belongs_to :pipeline_schedule, class_name: 'Ci::PipelineSchedule' belongs_to :pipeline_schedule, class_name: 'Ci::PipelineSchedule'
has_internal_id :iid, scope: :project, presence: false, to_param: false, init: -> do |s| has_internal_id :iid, scope: :project, presence: false, init: -> do |s|
s&.project&.pipelines&.maximum(:iid) || s&.project&.pipelines.count s&.project&.pipelines&.maximum(:iid) || s&.project&.pipelines.count
end end
......
...@@ -25,7 +25,7 @@ module AtomicInternalId ...@@ -25,7 +25,7 @@ module AtomicInternalId
extend ActiveSupport::Concern extend ActiveSupport::Concern
module ClassMethods module ClassMethods
def has_internal_id(column, scope:, init:, presence: true, to_param: true) # rubocop:disable Naming/PredicateName def has_internal_id(column, scope:, init:, presence: true) # rubocop:disable Naming/PredicateName
before_validation :"ensure_#{column}!", on: :create before_validation :"ensure_#{column}!", on: :create
validates column, presence: presence, numericality: true validates column, presence: presence, numericality: true
...@@ -42,10 +42,6 @@ module AtomicInternalId ...@@ -42,10 +42,6 @@ module AtomicInternalId
read_attribute(column) read_attribute(column)
end end
define_method("to_param") do
read_attribute(column)
end if to_param
end end
end end
end end
module IIDRoutes
##
# This automagically enforces all related routes to use `iid` instead of `id`
# If you want to use `iid` for some routes and `id` for other routes, this module should not to be included,
# instead you should define `iid` or `id` explictly at each route generators. e.g. pipeline_path(project.id, pipeline.iid)
def to_param
iid.to_s
end
end
class Deployment < ActiveRecord::Base class Deployment < ActiveRecord::Base
include AtomicInternalId include AtomicInternalId
include IIDRoutes
belongs_to :project, required: true belongs_to :project, required: true
belongs_to :environment, required: true belongs_to :environment, required: true
......
...@@ -2,6 +2,7 @@ require 'carrierwave/orm/activerecord' ...@@ -2,6 +2,7 @@ require 'carrierwave/orm/activerecord'
class Issue < ActiveRecord::Base class Issue < ActiveRecord::Base
include AtomicInternalId include AtomicInternalId
include IIDRoutes
include Issuable include Issuable
include Noteable include Noteable
include Referable include Referable
......
class MergeRequest < ActiveRecord::Base class MergeRequest < ActiveRecord::Base
include AtomicInternalId include AtomicInternalId
include IIDRoutes
include Issuable include Issuable
include Noteable include Noteable
include Referable include Referable
......
...@@ -9,6 +9,7 @@ class Milestone < ActiveRecord::Base ...@@ -9,6 +9,7 @@ class Milestone < ActiveRecord::Base
include CacheMarkdownField include CacheMarkdownField
include AtomicInternalId include AtomicInternalId
include IIDRoutes
include Sortable include Sortable
include Referable include Referable
include StripAttribute include StripAttribute
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册