class FieldMaskBuilder::Engine
Public Class Methods
build(fields)
click to toggle source
@param [Symbol | String | Hash | Array] fields @return [<String>]
# File lib/field_mask_builder/engine.rb, line 6 def build(fields) Engine.new(fields).build end
new(fields)
click to toggle source
@param [Symbol | String | Hash | Array] fields
# File lib/field_mask_builder/engine.rb, line 12 def initialize(fields) @fields = fields end
Public Instance Methods
build()
click to toggle source
@return [<String>]
# File lib/field_mask_builder/engine.rb, line 17 def build r = [] Helper.to_array(@fields).each do |f| case f when Symbol, String r.push(f.to_s) when Hash r += to_field_mask_paths(f) else raise "f must be Symbol or String or Hash, but got #{f}" end end r end
Private Instance Methods
to_field_mask_paths(hash)
click to toggle source
@param [Hash] hash @return [<String>]
# File lib/field_mask_builder/engine.rb, line 36 def to_field_mask_paths(hash) r = [] hash.each do |entity, fields| Helper.to_array(fields).each do |f| case f when Symbol, String r.push("#{entity}.#{f}") when Hash r += to_field_mask_paths(f).map { |p| "#{entity}.#{p}" } else raise "f must be Symbol or String or Hash, but got #{f}" end end end r end