module Mbrao::ContentInterface::ClassMethods

Class methods.

Public Instance Methods

create(metadata, body) click to toggle source

Creates a content with metadata and body.

@param metadata [Hash] The metadata. @param body [String] The body of the content. @return [Content] A new content.

# File lib/mbrao/content_interface.rb, line 44
def create(metadata, body)
  rv = Mbrao::Content.new
  rv.body = body.ensure_string.strip
  assign_metadata(rv, metadata.symbolize_keys) if metadata.is_a?(Hash)
  rv
end
validate_locales(locales, content = nil) click to toggle source

Validates locales for attribute retrieval.

@param locales [Array] A list of desired locales for an attribute. Can include `*` to match all. If none are specified, the default mbrao locale will be

used.

@param content [Content|nil] An optional content to check for availability @return [Array] The validated list of locales.

# File lib/mbrao/content_interface.rb, line 32
def validate_locales(locales, content = nil)
  locales = locales.ensure_array(no_duplicates: true, compact: true, flatten: true) { |l| l.ensure_string.strip }
  locales = (locales.empty? ? [Mbrao::Parser.locale] : locales)
  raise Mbrao::Exceptions::UnavailableLocalization if content && !content.enabled_for_locales?(locales)
  locales
end