Class: Taksi::Interfaces::Skeleton

Inherits:
Object
  • Object
show all
Defined in:
lib/taksi/interfaces/skeleton.rb

Defined Under Namespace

Classes: ComponentNotFoundError

Instance Method Summary collapse

Constructor Details

#initializeSkeleton

Returns a new instance of Skeleton.



8
9
10
# File 'lib/taksi/interfaces/skeleton.rb', line 8

def initialize
  @component_skeletons = []
end

Instance Method Details

#add(component_skeleton) ⇒ Object



18
19
20
21
# File 'lib/taksi/interfaces/skeleton.rb', line 18

def add(component_skeleton)
  @component_skeletons << component_skeleton
  self
end

#as_jsonObject



31
32
33
# File 'lib/taksi/interfaces/skeleton.rb', line 31

def as_json(*)
  {components: @component_skeletons.map(&:as_json)}
end

#create_component(identifier, &block) ⇒ Object



12
13
14
15
16
# File 'lib/taksi/interfaces/skeleton.rb', line 12

def create_component(identifier, &block)
  ::Taksi::Components::Skeleton.new(self, identifier, &block).tap do |component|
    add(component)
  end
end

#id_of(component) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/taksi/interfaces/skeleton.rb', line 23

def id_of(component)
  index = @component_skeletons.index(component)

  raise ComponentNotFoundError unless index

  "component$#{index}"
end