Class: Formular::Path

Inherits:
Array
  • Object
show all
Defined in:
lib/formular/path.rb

Instance Method Summary collapse

Instance Method Details

#to_encoded_idObject

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_nameObject

name #attribute without model…

User, :name

> user #regular attribute

User, roles: 0, :name

> user[][name]



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