Module: Coradoc::FormatModule
- Defined in:
- lib/coradoc/format_module.rb
Overview
Declared interface contract for format modules.
Format modules registered via Coradoc.register_format must implement:
Required:
-
parse_to_core(input, options={}) → CoreModel::Base
-
serialize(model, **options) → String
Optional:
-
parse(input, options={}) → format-specific model
-
handles_model?(model) → Boolean
-
to_core(model) → CoreModel::Base
-
serialize? → Boolean
Defined Under Namespace
Modules: Interface
Constant Summary collapse
- MINIMUM_PARSE_METHODS =
%i[parse_to_core parse].freeze
- REQUIRED_METHODS =
%i[serialize].freeze
Class Method Summary collapse
-
.validate!(format_module, format_name) ⇒ Object
Validate that a format module implements the minimum interface.
Class Method Details
.validate!(format_module, format_name) ⇒ Object
Validate that a format module implements the minimum interface. Warns to $stderr if methods are missing. Returns true if valid.
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/coradoc/format_module.rb', line 36 def self.validate!(format_module, format_name) has_parse = MINIMUM_PARSE_METHODS.any? { |m| format_module.public_methods.include?(m) } has_serialize = REQUIRED_METHODS.all? { |m| format_module.public_methods.include?(m) } return true if has_parse && has_serialize missing = [] missing << 'parse_to_core or parse' unless has_parse missing << 'serialize' unless has_serialize warn "Coradoc: format :#{format_name} (#{format_module}) missing: #{missing.join(', ')}" false end |