Module: Mbrao::ContentInterface::ClassMethods

Defined in:
lib/mbrao/content_interface.rb

Overview

Class methods.

Instance Method Summary collapse

Instance Method Details

#create(metadata, body) ⇒ Content

Creates a content with metadata and body.

Parameters:

  • metadata (Hash)

    The metadata.

  • body (String)

    The body of the content.

Returns:



44
45
46
47
48
49
# File 'lib/mbrao/content_interface.rb', line 44

def create(, body)
  rv = Mbrao::Content.new
  rv.body = body.ensure_string.strip
  (rv, .symbolize_keys) if .is_a?(Hash)
  rv
end

#validate_locales(locales, content = nil) ⇒ Array

Validates locales for attribute retrieval.

Parameters:

  • 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.

  • content (Content|nil) (defaults to: nil)

    An optional content to check for availability

Returns:

  • (Array)

    The validated list of locales.

Raises:



32
33
34
35
36
37
# 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