Class: Metanorma::Release::DocumentEntry

Inherits:
Struct
  • Object
show all
Defined in:
lib/metanorma/release/config.rb

Overview

Single routing entry — matches by any combination of pattern, source, stage, and doctype. An entry with no criteria matches everything (catch-all).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ DocumentEntry

Returns a new instance of DocumentEntry.



66
67
68
69
70
71
72
73
74
# File 'lib/metanorma/release/config.rb', line 66

def initialize(data)
  super(
    pattern: data["pattern"],
    source: data["source"],
    stages: Array(data["stage"]).map(&:to_s),
    doctypes: Array(data["doctype"]).map(&:to_s),
    channels: Array(data["channels"]).map(&:to_s),
  )
end

Instance Attribute Details

#channelsObject

Returns the value of attribute channels

Returns:

  • (Object)

    the current value of channels



65
66
67
# File 'lib/metanorma/release/config.rb', line 65

def channels
  @channels
end

#doctypesObject

Returns the value of attribute doctypes

Returns:

  • (Object)

    the current value of doctypes



65
66
67
# File 'lib/metanorma/release/config.rb', line 65

def doctypes
  @doctypes
end

#patternObject

Returns the value of attribute pattern

Returns:

  • (Object)

    the current value of pattern



65
66
67
# File 'lib/metanorma/release/config.rb', line 65

def pattern
  @pattern
end

#sourceObject

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



65
66
67
# File 'lib/metanorma/release/config.rb', line 65

def source
  @source
end

#stagesObject

Returns the value of attribute stages

Returns:

  • (Object)

    the current value of stages



65
66
67
# File 'lib/metanorma/release/config.rb', line 65

def stages
  @stages
end

Instance Method Details

#matches?(publication) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/metanorma/release/config.rb', line 76

def matches?(publication)
  return false if channels.empty?

  if pattern && !File.fnmatch?(pattern, publication.slug)
    return false
  end

  if source && !(publication.source_path&.end_with?(source) || false)
    return false
  end

  if !stages.empty? && !stages.include?(publication.stage.to_s)
    return false
  end

  if !doctypes.empty? && !doctypes.include?(publication.doctype.to_s)
    return false
  end

  true
end