Sha256: c7562d832e383005f580c4f8147f905d57cc890e2381e6318f889b6c2c5b9172

Contents?: true

Size: 1.01 KB

Versions: 10

Compression:

Stored size: 1.01 KB

Contents

module Dossier
  module Naming

    # not using ActiveSupport::Concern because ClassMethods
    # must be extended after ActiveModel::Naming
    def self.included(base)
      base.extend ActiveModel::Naming
      base.extend ClassMethods
    end

    def self.class_to_name(klass)
      (klass.name || anonymous_report).underscore[0..-8]
    end

    def self.name_to_class(name)
      "#{name}_report".classify.constantize
    end

    def self.anonymous_report
      'AnonymousReport'
    end

    def to_key
      [report_name]
    end

    def to_s
      report_name
    end

    delegate :report_name, :formatted_title, to: "self.class"

    module ClassMethods
      def report_name
        Dossier::Naming.class_to_name(self)
      end

      def formatted_title
        Dossier::Formatter.report_name(self)
      end

      def model_name
        @model_name ||= ActiveModel::Name.new(self, nil, superclass.name).tap do |name|
          name.instance_variable_set(:@param_key, 'options')
        end
      end

    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dossier-2.12.2 lib/dossier/naming.rb
dossier-2.12.1 lib/dossier/naming.rb
dossier-2.12.0 lib/dossier/naming.rb
dossier-2.11.0 lib/dossier/naming.rb
dossier-2.10.0 lib/dossier/naming.rb
dossier-2.9.3 lib/dossier/naming.rb
dossier-2.9.2 lib/dossier/naming.rb
dossier-2.9.1 lib/dossier/naming.rb
dossier-2.9.0 lib/dossier/naming.rb
dossier-2.8.0 lib/dossier/naming.rb