Sha256: 5e95e43ea9aa661f2912a3472216f11a91bec892b317457c2ce506acf8d9ba31
Contents?: true
Size: 1.29 KB
Versions: 14
Compression:
Stored size: 1.29 KB
Contents
# frozen_string_literal: true module Cmor module Legal class PersonalDataHashBuilder include ActiveModel::Model attr_accessor :root, :options, :block def initialize(attributes, options = {}) super(attributes) @builder_options = options invoke_block end def attribute(name, options = {}) if with_options? hash[:attributes][name] = { options: options } else hash[:attributes] << name end end def association(name, options = {}, &block) if with_options? hash[:associations][name] = { options: options, attributes: Cmor::Legal::PersonalDataHashBuilder.new(block: block).hash } else hash[name] = Cmor::Legal::PersonalDataHashBuilder.new({ block: block }, @builder_options).hash end end def hash if with_options? @hash ||= { root: root, options: options, attributes: {}, associations: {} } else @hash ||= { attributes: [] } end end private def invoke_block self.block.call(self) end def with_options? @builder_options[:with_options] = true if @builder_options[:with_options].nil? @builder_options[:with_options] end end end end
Version data entries
14 entries across 14 versions & 1 rubygems