Class: Gitlab::WikiPages::FrontMatterParser::Block

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/wiki_pages/front_matter_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(delim = nil, lang = '', text = nil) ⇒ Block

Returns a new instance of Block.



47
48
49
50
# File 'lib/gitlab/wiki_pages/front_matter_parser.rb', line 47

def initialize(delim = nil, lang = '', text = nil)
  @lang = lang&.downcase.presence || Gitlab::FrontMatter::DELIM_LANG[delim]
  @text = text&.strip!
end

Instance Method Details

#dataObject



52
53
54
55
56
# File 'lib/gitlab/wiki_pages/front_matter_parser.rb', line 52

def data
  @data ||= YAML.safe_load(text, symbolize_names: true)
rescue Psych::DisallowedClass, Psych::SyntaxError => error
  raise ParseError, error.message
end

#errorObject



62
63
64
# File 'lib/gitlab/wiki_pages/front_matter_parser.rb', line 62

def error
  strong_memoize(:error) { no_match? || too_long? || not_yaml? || not_mapping? }
end

#valid?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/gitlab/wiki_pages/front_matter_parser.rb', line 58

def valid?
  error.nil?
end