class Arbre::Form::Component::Path
Constants
- Member
Public Class Methods
new(errors: [], successes: [], &block)
click to toggle source
# File lib/arbre/form/component/path.rb, line 5 def initialize(errors: [], successes: [], &block) @members = [] @errors = errors @successes = successes instance_exec(&block) end
Public Instance Methods
components()
click to toggle source
# File lib/arbre/form/component/path.rb, line 38 def components @members.map do |member| if member.index [member.name, member.index] else [member.name] end end end
errors()
click to toggle source
# File lib/arbre/form/component/path.rb, line 48 def errors current_validations(@errors) end
id(*attributes)
click to toggle source
# File lib/arbre/form/component/path.rb, line 34 def id(*attributes) (components + attributes.compact).join('_') end
name(*attributes)
click to toggle source
# File lib/arbre/form/component/path.rb, line 24 def name(*attributes) name_components = [] (components + attributes.compact).each_with_index do |(name, member_index), index| next name_components << name if index == 0 name_components << "[#{name}]" name_components << '[]' if member_index end name_components.join('') end
peek()
click to toggle source
# File lib/arbre/form/component/path.rb, line 20 def peek @members.last end
pop()
click to toggle source
# File lib/arbre/form/component/path.rb, line 16 def pop @members.pop end
push(member, name, index = nil)
click to toggle source
# File lib/arbre/form/component/path.rb, line 12 def push(member, name, index = nil) @members << Member.new(member, name, index) end
successes()
click to toggle source
# File lib/arbre/form/component/path.rb, line 52 def successes current_validations(@successes) end
Private Instance Methods
current_validations(validations)
click to toggle source
# File lib/arbre/form/component/path.rb, line 58 def current_validations(validations) current_validations = validations @members.each_with_index do |member, index| next if index == 0 current_validations = current_validations.fetch(member.name, member.index ? [] : {}) current_validations = current_validations[member.index] || {} if member.index end current_validations end