Sha256: 0f7373eb6c1e92619287eb70a08d3d90ab64258bc0598ec49deb7aecfd27c267

Contents?: true

Size: 726 Bytes

Versions: 1

Compression:

Stored size: 726 Bytes

Contents

# frozen_string_literal: true

module Taksi
  module Screens
    class Skeleton
      class WidgetNotFoundError < StandardError; end

      def initialize
        @widget_skeletons = []
      end

      def create_widget(identifier, &block)
        ::Taksi::Widgets::Skeleton.new(self, identifier, &block).tap do |widget|
          add(widget)
        end
      end

      def add(widget_skeleton)
        @widget_skeletons << widget_skeleton
        self
      end

      def id_of(widget)
        index = @widget_skeletons.index(widget)

        raise WidgetNotFoundError unless index

        "widget$#{index}"
      end

      def as_json(*)
        {widgets: @widget_skeletons.map(&:as_json)}
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
taksi-0.1.0 lib/taksi/screens/skeleton.rb