class FieldMaskParser::Node
Attributes
attrs[R]
has_manies[R]
has_ones[R]
is_leaf[R]
klass[R]
name[R]
Public Class Methods
new(name:, is_leaf:, klass:)
click to toggle source
@param [Symbol | NilClass] name nil when being top-level node @param [bool] is_leaf
@param [ActiveRecord::Base] klass
# File lib/field_mask_parser/node.rb, line 8 def initialize(name:, is_leaf:, klass:) @name = name @is_leaf = is_leaf @klass = klass @attrs = [] @has_ones = [] @has_manies = [] end
Public Instance Methods
==(other)
click to toggle source
# File lib/field_mask_parser/node.rb, line 59 def ==(other) self.class == other.class && self.to_paths == other.to_paths end
assocs()
click to toggle source
# File lib/field_mask_parser/node.rb, line 32 def assocs has_ones + has_manies end
push_attr(f)
click to toggle source
@param [Symbol] f
# File lib/field_mask_parser/node.rb, line 18 def push_attr(f) @attrs.push(f) end
push_has_many(n)
click to toggle source
@param [Node] n
# File lib/field_mask_parser/node.rb, line 28 def push_has_many(n) @has_manies.push(n) end
push_has_one(n)
click to toggle source
@param [Node] n
# File lib/field_mask_parser/node.rb, line 23 def push_has_one(n) @has_ones.push(n) end
to_h()
click to toggle source
# File lib/field_mask_parser/node.rb, line 36 def to_h { name: @name, is_leaf: @is_leaf, klass: @klass, attrs: @attrs, has_ones: @has_ones.map(&:to_h), has_manies: @has_manies.map(&:to_h), } end
to_paths(prefix: [], sort: true)
click to toggle source
# File lib/field_mask_parser/node.rb, line 47 def to_paths(prefix: [], sort: true) r = [] attrs.each do |attr| r << (prefix + [attr]).join(".") end assocs.each do |assoc| r += assoc.to_paths(prefix: prefix + [assoc.name], sort: false) end r.sort! if sort r end