Sha256: 4e38384d0dbb2a8cf98670ecce1973f8026163fb592fafc9ec9dcca0a79eb789

Contents?: true

Size: 702 Bytes

Versions: 4

Compression:

Stored size: 702 Bytes

Contents

module AbAdmin
  module Concerns
    module Headerable
      extend ActiveSupport::Concern

      included do
        has_one :header, as: :headerable, dependent: :delete

        accepts_nested_attributes_for :header, reject_if: :all_blank

        ::Header.all_translated_attribute_names.each do |attr|
          define_method "header_#{attr}=" do |val|
            default_header.send("#{attr}=", val)
          end

          define_method "header_#{attr}" do
            default_header.send(attr)
          end
        end
      end

      def default_header
        header || build_header
      end

      def default_persistent_header
        header || create_header
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ab_admin-0.11.0 lib/ab_admin/concerns/headerable.rb
ab_admin-0.10.0 lib/ab_admin/concerns/headerable.rb
ab_admin-0.9.0 lib/ab_admin/concerns/headerable.rb
ab_admin-0.8.3 lib/ab_admin/concerns/headerable.rb