Class: Canvas::ExpandAttributes

Inherits:
Object
  • Object
show all
Defined in:
lib/canvas/services/expand_attributes.rb

Overview

:documented: This service will convert the attributes from a hash, as they are defined in the front matter, into an array of hashes that the Validator::SchemaAttribute class expects. e.g. the following front matter:

my_title:

type: string

my_color:

type: color

will get converted to:

[

{
  "name" => "my_title",
  "type" => "string"
},
{
  "name" => "my_color",
  "type" => "color"
}

]

Class Method Summary collapse

Class Method Details

.call(attributes_hash) ⇒ Array<Hash>

Returns array of hashes that represent each attribute.

Parameters:

  • attributes_hash (Hash)

    hash of attributes pulled from front matter

Returns:

  • (Array<Hash>)

    array of hashes that represent each attribute



31
32
33
34
35
36
37
38
# File 'lib/canvas/services/expand_attributes.rb', line 31

def call(attributes_hash)
  return [] if attributes_hash.nil?
  return attributes_hash if attributes_hash.is_a?(Array)

  attributes_hash.each_with_object([]) do |(name, attribute_hash), attrs|
    attrs << attribute_hash.merge("name" => name)
  end
end