Sha256: ed636e265d366913c48c4611d61d1d75855497b897bf16716511212ba526cfef

Contents?: true

Size: 1.27 KB

Versions: 14

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module Cmor
  module Legal
    class PersonalData
      include ActiveModel::Model

      attr_accessor :root, :options, :block

      def to_hash_with_options
        @hash ||= build_hash_with_options!
      end

      def build_hash_with_options!
        Cmor::Legal::PersonalDataHashBuilder.new({ root: root, options: options, block: block }, { with_options: true }).hash
      end

      def to_hash
        @hash ||= build_hash!
      end

      def build_hash!
        Cmor::Legal::PersonalDataHashBuilder.new({ root: root, options: options, block: block }, { with_options: false }).hash
      end

      def self.all
        Cmor::Legal::PersonalDataRegistry.all
      end

      def self.count
        Cmor::Legal::PersonalDataRegistry.count
      end

      def self.attribute_names
        [:root, :options, :block]
      end

      def self.find(id)
        all.find { |x| x.root == id.gsub("-", "/").camelize }
      end

      def id
        root.underscore.gsub("/", "-")
      end

      def to_param
        id
      end

      def to_s
        [self.class.model_name.human, root_model_human].compact.join(" - ")
      end

      def root_model_human
        return if root.nil?
        root.constantize.model_name.human
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

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