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.



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

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

Class Method Details

.inherit_from(source, inherit_attributes: true) ⇒ Object



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

def inherit_from(source, inherit_attributes: true)
  stacks = Bags.stack_sections.to_h do |section|
    [section, inherited_stack(source, section, inherit_section?(section, inherit_attributes))]
  end
  new(**stacks)
end

Instance Method Details

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



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

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

#delete(section, path) ⇒ Object



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

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

#snapshot(section) ⇒ Object



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

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

#stack(section) ⇒ Object



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

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

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



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

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

#without(section, path) ⇒ Object



55
56
57
# File 'lib/julewire/core/fields/stack_set.rb', line 55

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