Sha256: 8237a00b4f0944d8294cd3f02f7e9b363caabb6a471788ceeed7ce87d605729e
Contents?: true
Size: 1.16 KB
Versions: 13
Compression:
Stored size: 1.16 KB
Contents
# frozen_string_literal: true require 'rspec/rails/api/field_config' module RSpec module Rails module Api # Represents an entity configuration. # Basically, entities configuration only have a collection of fields # and a method to serialize them for comparison with actual content class EntityConfig attr_accessor :fields def initialize(fields) @fields = {} fields.each_key do |name| @fields[name] = FieldConfig.new fields[name] end end def to_h out = {} @fields.each_key do |key| out[key] = @fields[key].to_h end out end def expand_with(entities) hash = to_h hash.each_pair do |field, config| next unless %i[array object].include? config[:type] attributes = config[:attributes] next unless attributes.is_a? Symbol raise "Entity #{attributes} not found for entity completion." unless entities[attributes] hash[field][:attributes] = entities[attributes].expand_with(entities) end end end end end end
Version data entries
13 entries across 13 versions & 1 rubygems