Class: PlanMyStuff::CommentMetadata

Inherits:
BaseMetadata show all
Defined in:
lib/plan_my_stuff/comment_metadata.rb

Constant Summary

Constants inherited from BaseMetadata

BaseMetadata::SCHEMA_VERSION

Instance Attribute Summary collapse

Attributes inherited from BaseMetadata

#app_name, #created_by, #custom_fields, #gem_version, #rails_env, #schema_version, #visibility

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseMetadata

#internal?, #public?, #to_json, #validate_custom_fields!

Constructor Details

#initializeCommentMetadata

Returns a new instance of CommentMetadata.



52
53
54
55
56
# File 'lib/plan_my_stuff/comment_metadata.rb', line 52

def initialize
  super
  @issue_body = false
  @attachments = []
end

Instance Attribute Details

#attachmentsArray<PlanMyStuff::Attachment>

Returns consuming-app attachment records associated with this comment.

Returns:



8
9
10
# File 'lib/plan_my_stuff/comment_metadata.rb', line 8

def attachments
  @attachments
end

#issue_bodyBoolean

Returns true if this comment holds the issue’s body content.

Returns:

  • (Boolean)

    true if this comment holds the issue’s body content



6
7
8
# File 'lib/plan_my_stuff/comment_metadata.rb', line 6

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

Parameters:

  • user (Object, Integer)

    user object or user_id

  • visibility (String) (defaults to: 'internal')

    “public” or “internal”

  • custom_fields (Hash) (defaults to: {})

    app-defined field values

  • issue_body (Boolean) (defaults to: false)

    whether this comment holds the issue body

  • attachments (Array<Hash, PlanMyStuff::Attachment>) (defaults to: [])

    consuming-app attachment records

Returns:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/plan_my_stuff/comment_metadata.rb', line 36

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
  .attachments = attachments

  
end

.from_hash(hash) ⇒ CommentMetadata

Builds a CommentMetadata from a parsed hash (e.g. from MetadataParser)

Parameters:

  • hash (Hash)

Returns:



17
18
19
20
21
22
23
24
# File 'lib/plan_my_stuff/comment_metadata.rb', line 17

def from_hash(hash)
   = new
  apply_common_from_hash(, hash, PlanMyStuff.configuration.custom_fields_for(:comment))
  .issue_body = hash[:issue_body] || false
  .attachments = hash[:attachments]

  
end

Instance Method Details

#issue_body?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/plan_my_stuff/comment_metadata.rb', line 70

def issue_body?
  issue_body == true
end

#to_hHash

Returns:

  • (Hash)


75
76
77
78
79
80
# File 'lib/plan_my_stuff/comment_metadata.rb', line 75

def to_h
  super.merge(
    issue_body: issue_body,
    attachments: attachments.map(&:to_h),
  )
end