Class: Taksi::Components::Skeleton

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, name, &block) ⇒ Skeleton

Returns a new instance of Skeleton.



8
9
10
11
12
13
14
15
# File 'lib/taksi/components/skeleton.rb', line 8

def initialize(parent, name, &block)
  @parent = parent
  @name = name

  raise 'To build a component you need to provide a `content` block' unless block_given?

  @content = ::Taksi::Components::Field.new(self, :content, &block)
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



6
7
8
# File 'lib/taksi/components/skeleton.rb', line 6

def content
  @content
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/taksi/components/skeleton.rb', line 6

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



6
7
8
# File 'lib/taksi/components/skeleton.rb', line 6

def parent
  @parent
end

Instance Method Details

#as_jsonObject



29
30
31
32
33
34
35
36
37
# File 'lib/taksi/components/skeleton.rb', line 29

def as_json
  {
    name: name,
    identifier: id,
    requires_data: dynamic?
  }.tap do |json|
    json.merge!(content.as_json)
  end
end

#dynamic?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/taksi/components/skeleton.rb', line 25

def dynamic?
  @content.dynamic?
end

#fieldsObject



21
22
23
# File 'lib/taksi/components/skeleton.rb', line 21

def fields
  content.fields
end

#idObject



17
18
19
# File 'lib/taksi/components/skeleton.rb', line 17

def id
  parent.id_of(self)
end