Class: Julewire::Core::Fields::StackSet

Inherits:
Object
  • Object
show all
Defined in:
lib/julewire/core/fields/stack_set.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**sections) ⇒ StackSet

Returns a new instance of StackSet.



24
25
26
27
28
# File 'lib/julewire/core/fields/stack_set.rb', line 24

def initialize(**sections)
  @stacks = Bags.stack_sections.to_h do |section|
    [section, field_stack(sections.fetch(section, nil), section)]
  end
end

Class Method Details

.inherit_from(source, inherit_attributes:) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/julewire/core/fields/stack_set.rb', line 8

def inherit_from(source, inherit_attributes:)
  stacks = Bags.stack_sections.each_with_object({}) do |section, inherited|
    next unless inherit_section?(section, inherit_attributes)

    inherited[section] = source.stack(section).branch
  end
  new(**stacks)
end

Instance Method Details

#add(section, fields, owned: false) ⇒ Object



38
39
40
# File 'lib/julewire/core/fields/stack_set.rb', line 38

def add(section, fields, owned: false)
  stack(section).add(fields, owned: owned)
end

#delete(section, path) ⇒ Object



42
43
44
# File 'lib/julewire/core/fields/stack_set.rb', line 42

def delete(section, path)
  stack(section).delete(path)
end

#snapshot(section) ⇒ Object



34
35
36
# File 'lib/julewire/core/fields/stack_set.rb', line 34

def snapshot(section)
  stack(section).snapshot
end

#stack(section) ⇒ Object



30
31
32
# File 'lib/julewire/core/fields/stack_set.rb', line 30

def stack(section)
  @stacks.fetch(section)
end

#with(section, fields = nil, owned: false, **keyword_fields) ⇒ Object



46
47
48
# File 'lib/julewire/core/fields/stack_set.rb', line 46

def with(section, fields = nil, owned: false, **keyword_fields, &)
  stack(section).with(fields, owned: owned, **keyword_fields, &)
end

#without(section, path) ⇒ Object



50
51
52
# File 'lib/julewire/core/fields/stack_set.rb', line 50

def without(section, path, &)
  stack(section).without(path, &)
end