Class: Formular::Path
- Inherits:
-
Array
- Object
- Array
- Formular::Path
- Defined in:
- lib/formular/path.rb
Instance Method Summary collapse
-
#to_encoded_id ⇒ Object
need to inject the index in here…
-
#to_encoded_name ⇒ Object
name #attribute without model…
Instance Method Details
#to_encoded_id ⇒ Object
need to inject the index in here… else we will end up with the same ids
- User, :name
-
> user_name #regular attribute
- User, roles: 0, :name
-
> user_roles_0_name
21 22 23 |
# File 'lib/formular/path.rb', line 21 def to_encoded_id map { |segment| segment.is_a?(Array) ? segment.join('_') : segment }.join('_') end |
#to_encoded_name ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/formular/path.rb', line 6 def to_encoded_name map.with_index do |segment, i| first_or_last = i == 0 || i == size if first_or_last segment.is_a?(Array) ? "#{segment.first}[]" : segment else segment.is_a?(Array) ? "[#{segment.first}][]" : "[#{segment}]" end end.join('') end |