Class: Gitlab::WikiPages::FrontMatterParser::Block
- Inherits:
-
Object
- Object
- Gitlab::WikiPages::FrontMatterParser::Block
- Includes:
- Utils::StrongMemoize
- Defined in:
- lib/gitlab/wiki_pages/front_matter_parser.rb
Instance Method Summary collapse
- #data ⇒ Object
- #error ⇒ Object
-
#initialize(delim = nil, lang = '', text = nil) ⇒ Block
constructor
A new instance of Block.
- #valid? ⇒ Boolean
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
#data ⇒ Object
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. end |
#error ⇒ Object
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
58 59 60 |
# File 'lib/gitlab/wiki_pages/front_matter_parser.rb', line 58 def valid? error.nil? end |