Class: PlanMyStuff::CommentMetadata
- Inherits:
-
BaseMetadata
- Object
- BaseMetadata
- PlanMyStuff::CommentMetadata
- Defined in:
- lib/plan_my_stuff/comment_metadata.rb
Constant Summary collapse
- LEGACY_URL_REGEXES =
[ %r{\Ahttps://raw\.githubusercontent\.com/(?<owner>[^/\s]+)/(?<repo>[^/\s]+)/(?<sha>[^/\s]+)/(?<path>.+)\z}, %r{\Ahttps://github\.com/(?<owner>[^/\s]+)/(?<repo>[^/\s]+)/blob/(?<sha>[^/\s]+)/(?<path>.+)\z}, ].freeze
- LEGACY_ATTACHMENT_DEPRECATION_MESSAGE =
'PlanMyStuff: legacy attachment metadata shape {filename, url} detected. It will continue to parse ' \ 'until 1.0.0, at which point legacy detection will be removed. New writes use the structured ' \ '{filename, owner, repo, sha, path} shape introduced in #70; existing entries migrate on their ' \ 'next write.'
Constants inherited from BaseMetadata
Instance Attribute Summary collapse
-
#attachments ⇒ Array<PlanMyStuff::Attachment>
Consuming-app attachment records associated with this comment.
-
#issue_body ⇒ Boolean
True if this comment holds the issue’s body content.
Attributes inherited from BaseMetadata
#app_name, #created_by, #custom_fields, #gem_version, #rails_env, #schema_version, #visibility
Class Method Summary collapse
-
.build(user:, visibility: 'internal', custom_fields: {}, issue_body: false, attachments: []) ⇒ CommentMetadata
Builds a new CommentMetadata for comment creation, auto-filling gem defaults.
-
.from_hash(hash) ⇒ CommentMetadata
Builds a CommentMetadata from a parsed hash (e.g. from MetadataParser).
Instance Method Summary collapse
-
#initialize ⇒ CommentMetadata
constructor
A new instance of CommentMetadata.
- #issue_body? ⇒ Boolean
- #to_h ⇒ Hash
Methods inherited from BaseMetadata
#internal?, #public?, #to_json, #validate_custom_fields!
Constructor Details
#initialize ⇒ CommentMetadata
Returns a new instance of CommentMetadata.
63 64 65 66 67 |
# File 'lib/plan_my_stuff/comment_metadata.rb', line 63 def initialize super @issue_body = false @attachments = [] end |
Instance Attribute Details
#attachments ⇒ Array<PlanMyStuff::Attachment>
Returns consuming-app attachment records associated with this comment.
19 20 21 |
# File 'lib/plan_my_stuff/comment_metadata.rb', line 19 def @attachments end |
#issue_body ⇒ Boolean
Returns true if this comment holds the issue’s body content.
17 18 19 |
# File 'lib/plan_my_stuff/comment_metadata.rb', line 17 def issue_body @issue_body end |
Class Method Details
.build(user:, visibility: 'internal', custom_fields: {}, issue_body: false, attachments: []) ⇒ CommentMetadata
Builds a new CommentMetadata for comment creation, auto-filling gem defaults
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/plan_my_stuff/comment_metadata.rb', line 47 def build(user:, visibility: 'internal', custom_fields: {}, issue_body: false, attachments: []) = new apply_common_build( , user: user, visibility: visibility, custom_fields_data: custom_fields, custom_fields_schema: PlanMyStuff.configuration.custom_fields_for(:comment), ) .issue_body = issue_body . = end |
.from_hash(hash) ⇒ CommentMetadata
Builds a CommentMetadata from a parsed hash (e.g. from MetadataParser)
28 29 30 31 32 33 34 35 |
# File 'lib/plan_my_stuff/comment_metadata.rb', line 28 def from_hash(hash) = new apply_common_from_hash(, hash, PlanMyStuff.configuration.custom_fields_for(:comment)) .issue_body = hash[:issue_body] || false . = hash[:attachments] end |
Instance Method Details
#issue_body? ⇒ Boolean
81 82 83 |
# File 'lib/plan_my_stuff/comment_metadata.rb', line 81 def issue_body? issue_body == true end |
#to_h ⇒ Hash
86 87 88 89 90 91 |
# File 'lib/plan_my_stuff/comment_metadata.rb', line 86 def to_h super.merge( issue_body: issue_body, attachments: .map(&:to_h), ) end |