Class: Slotify::ValueStore

Inherits:
Object
  • Object
show all
Includes:
SymbolInflectionHelper
Defined in:
lib/slotify/value_store.rb

Instance Method Summary collapse

Methods included from SymbolInflectionHelper

#plural?, #singular?, #singularize

Constructor Details

#initialize(view_context) ⇒ ValueStore

Returns a new instance of ValueStore.



5
6
7
8
# File 'lib/slotify/value_store.rb', line 5

def initialize(view_context)
  @view_context = view_context
  @values = []
end

Instance Method Details

#add(slot_name, args = [], options = {}, block = nil) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/slotify/value_store.rb', line 14

def add(slot_name, args = [], options = {}, block = nil)
  if plural?(slot_name)
    Array.wrap(args.shift).map { add(singularize(slot_name), [_1, *args], options, block) }
  else
    @values << Value.new(@view_context, args, options, block, slot_name: singularize(slot_name))
  end
end

#for(slot_name) ⇒ Object



10
11
12
# File 'lib/slotify/value_store.rb', line 10

def for(slot_name)
  @values.select { _1.slot_name == singularize(slot_name) }
end

#slot_namesObject



22
23
24
# File 'lib/slotify/value_store.rb', line 22

def slot_names
  @values.map(&:slot_name).uniq
end