Class: DesignManagement::DesignAtVersion
- Inherits:
-
Object
- Object
- DesignManagement::DesignAtVersion
- Includes:
- ActiveModel::Validations, Gitlab::Utils::StrongMemoize, GlobalID::Identification
- Defined in:
- app/models/design_management/design_at_version.rb
Instance Attribute Summary collapse
-
#design ⇒ Object
readonly
Returns the value of attribute design.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #deleted? ⇒ Boolean
-
#id ⇒ Object
The ID, needed by GraphQL types and as part of the Lazy-fetch protocol, includes information about both the design and the version.
-
#initialize(design: nil, version: nil) ⇒ DesignAtVersion
constructor
A new instance of DesignAtVersion.
- #not_created_yet? ⇒ Boolean
- #status ⇒ Object
Constructor Details
#initialize(design: nil, version: nil) ⇒ DesignAtVersion
Returns a new instance of DesignAtVersion.
20 21 22 23 |
# File 'app/models/design_management/design_at_version.rb', line 20 def initialize(design: nil, version: nil) @design = design @version = version end |
Instance Attribute Details
#design ⇒ Object (readonly)
Returns the value of attribute design.
12 13 14 |
# File 'app/models/design_management/design_at_version.rb', line 12 def design @design end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
11 12 13 |
# File 'app/models/design_management/design_at_version.rb', line 11 def version @version end |
Class Method Details
.find(ids) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/models/design_management/design_at_version.rb', line 50 def self.find(ids) pairs = ids.map { |id| id.split('.').map(&:to_i) } design_ids = pairs.map(&:first).uniq version_ids = pairs.map(&:second).uniq designs = ::DesignManagement::Design .where(id: design_ids) .index_by(&:id) versions = ::DesignManagement::Version .where(id: version_ids) .index_by(&:id) pairs.map do |(design_id, version_id)| design = designs[design_id] version = versions[version_id] obj = new(design: design, version: version) obj if obj.valid? end.compact end |
.lazy_find(id) ⇒ Object
42 43 44 45 46 47 48 |
# File 'app/models/design_management/design_at_version.rb', line 42 def self.lazy_find(id) BatchLoader.for(id).batch do |ids, callback| find(ids).each do |record| callback.call(record.id, record) end end end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
34 35 36 37 38 |
# File 'app/models/design_management/design_at_version.rb', line 34 def ==(other) return false unless other && self.class == other.class other.id == id end |
#deleted? ⇒ Boolean
84 85 86 |
# File 'app/models/design_management/design_at_version.rb', line 84 def deleted? action&.deletion? end |
#id ⇒ Object
The ID, needed by GraphQL types and as part of the Lazy-fetch protocol, includes information about both the design and the version.
The particular format is not interesting, and should be treated as opaque by all callers.
30 31 32 |
# File 'app/models/design_management/design_at_version.rb', line 30 def id "#{design.id}.#{version.id}" end |
#not_created_yet? ⇒ Boolean
88 89 90 |
# File 'app/models/design_management/design_at_version.rb', line 88 def not_created_yet? action.nil? end |
#status ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'app/models/design_management/design_at_version.rb', line 74 def status if not_created_yet? :not_created_yet elsif deleted? :deleted else :current end end |