Sha256: f5cbe1c1c019d20e00463923b56aa98142e85f507b76d1e25fee4dc356eb3268

Contents?: true

Size: 1.36 KB

Versions: 26

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true
require 'dato/site/repo/base'

module Dato
  module Site
    module Repo
      class MenuItem < Base
        def create(resource_attributes)
          body = JsonApiSerializer.new(
            type: :menu_item,
            attributes: %i(label position),
            relationships: { item_type: { collection: false, type: :item_type }, parent: { collection: false, type: :menu_item } },
            required_attributes: %i(label position)
          ).serialize(resource_attributes)

          post_request '/menu-items', body
        end

        def update(menu_item_id, resource_attributes)
          body = JsonApiSerializer.new(
            type: :menu_item,
            attributes: %i(label position),
            relationships: { item_type: { collection: false, type: :item_type }, parent: { collection: false, type: :menu_item } },
            required_attributes: %i(label position),
            required_relationships: %i(item_type)
          ).serialize(resource_attributes, menu_item_id)

          put_request "/menu-items/#{menu_item_id}", body
        end

        def all
          get_request '/menu-items'
        end

        def find(menu_item_id)
          get_request "/menu-items/#{menu_item_id}"
        end

        def destroy(menu_item_id)
          delete_request "/menu-items/#{menu_item_id}"
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
dato-0.1.12 lib/dato/site/repo/menu_item.rb
dato-0.1.11 lib/dato/site/repo/menu_item.rb
dato-0.1.10 lib/dato/site/repo/menu_item.rb
dato-0.1.9 lib/dato/site/repo/menu_item.rb
dato-0.1.8 lib/dato/site/repo/menu_item.rb
dato-0.1.6 lib/dato/site/repo/menu_item.rb