Class: ContentBlockTools::InternalContentPath

Inherits:
Object
  • Object
show all
Defined in:
lib/content_block_tools/internal_content_path.rb

Overview

Represents the path to internal content within a content block

An internal content path identifies a specific piece of content within a content block’s details hash. The path is used with ‘dig` to traverse the nested structure.

Examples:

Path to a block

path = InternalContentPath.new([:email_addresses, :main])
path.present?    #=> true
path.singular?   #=> false
path.block_type  #=> :email_addresses
path.block_name  #=> :main

Path to a field in a one-to-one relationship

path = InternalContentPath.new([:date_range])
path.singular?   #=> true
path.block_type  #=> :date_range
path.block_name  #=> :date_range

Empty path (render the whole block)

path = InternalContentPath.new([])
path.present?    #=> false
path.block_type  #=> nil

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ InternalContentPath

Returns a new instance of InternalContentPath.



29
30
31
# File 'lib/content_block_tools/internal_content_path.rb', line 29

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



27
28
29
# File 'lib/content_block_tools/internal_content_path.rb', line 27

def path
  @path
end

Instance Method Details

#block_nameObject



45
46
47
# File 'lib/content_block_tools/internal_content_path.rb', line 45

def block_name
  path.last
end

#block_typeObject



41
42
43
# File 'lib/content_block_tools/internal_content_path.rb', line 41

def block_type
  path.first
end

#present?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/content_block_tools/internal_content_path.rb', line 33

def present?
  path.any?
end

#singular?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/content_block_tools/internal_content_path.rb', line 37

def singular?
  path.one?
end