Class: Slotify::ValueStore

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

Instance Method Summary collapse

Methods included from InflectionHelper

#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
21
22
# File 'lib/slotify/value_store.rb', line 14

def add(slot_name, args = [], options = {}, block = nil)
  if plural?(slot_name)
    Array.wrap(args.first).map { add(singularize(slot_name), _1, options, block) }
  else
    MethodArgsResolver.call(args, options, block) do
      @values << Value.new(@view_context, _1, _2, _3, slot_name: singularize(slot_name))
    end
  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



24
25
26
# File 'lib/slotify/value_store.rb', line 24

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