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

Version Path
cmor_legal-0.0.60.pre app/builders/cmor/legal/personal_data_hash_builder.rb
cmor_legal-0.0.59.pre app/builders/cmor/legal/personal_data_hash_builder.rb
cmor_legal-0.0.58.pre app/builders/cmor/legal/personal_data_hash_builder.rb
cmor_legal-0.0.57.pre app/builders/cmor/legal/personal_data_hash_builder.rb
cmor_legal-0.0.56.pre app/builders/cmor/legal/personal_data_hash_builder.rb
cmor_legal-0.0.55.pre app/builders/cmor/legal/personal_data_hash_builder.rb
cmor_legal-0.0.54.pre app/builders/cmor/legal/personal_data_hash_builder.rb
cmor_legal-0.0.53.pre app/builders/cmor/legal/personal_data_hash_builder.rb
cmor_legal-0.0.52.pre app/builders/cmor/legal/personal_data_hash_builder.rb
cmor_legal-0.0.51.pre app/builders/cmor/legal/personal_data_hash_builder.rb
cmor_legal-0.0.50.pre app/builders/cmor/legal/personal_data_hash_builder.rb
cmor_legal-0.0.49.pre app/builders/cmor/legal/personal_data_hash_builder.rb
cmor_legal-0.0.48.pre app/builders/cmor/legal/personal_data_hash_builder.rb
cmor_legal-0.0.45.pre app/builders/cmor/legal/personal_data_hash_builder.rb