Class: Slotify::ValueStore
- Inherits:
-
Object
- Object
- Slotify::ValueStore
- Includes:
- InflectionHelper
- Defined in:
- lib/slotify/value_store.rb
Instance Method Summary collapse
- #add(slot_name, args = [], options = {}, block = nil) ⇒ Object
- #for(slot_name) ⇒ Object
-
#initialize(view_context) ⇒ ValueStore
constructor
A new instance of ValueStore.
- #slot_names ⇒ Object
Methods included from InflectionHelper
#plural?, #singular?, #singularize
Constructor Details
#initialize(view_context) ⇒ 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 = [], = {}, block = nil) if plural?(slot_name) Array.wrap(args.first).map { add(singularize(slot_name), _1, , block) } else MethodArgsResolver.call(args, , 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_names ⇒ Object
24 25 26 |
# File 'lib/slotify/value_store.rb', line 24 def slot_names @values.map(&:slot_name).uniq end |