Sha256: 67572bf5270a7443112a3254ce6f682281bc3c2a11fa81c827f2baeb4cc88f18

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

module Effective
  module Resources
    module Klass

      def klass
        @model_klass ||= (
          namespaced_class_name.safe_constantize ||
          class_name.safe_constantize ||
          name.classify.safe_constantize
        )
      end

      def datatable_klass
        @datatable_klass ||= if defined?(EffectiveDatatables)
          "#{namespaced_class_name.pluralize}Datatable".safe_constantize ||
          "#{class_name.pluralize.camelize}Datatable".safe_constantize ||
          "#{name.pluralize.camelize}Datatable".safe_constantize ||
          "Effective::Datatables::#{namespaced_class_name.pluralize}".safe_constantize ||
          "Effective::Datatables::#{class_name.pluralize.camelize}".safe_constantize ||
          "Effective::Datatables::#{name.pluralize.camelize}".safe_constantize
        end
      end

      def controller_klass
        @controller_klass ||= (
          "#{namespaced_class_name.pluralize}Controller".safe_constantize ||
          "#{class_name.pluralize.classify}Controller".safe_constantize ||
          "#{name.pluralize.classify}Controller".safe_constantize
        )
      end

      def active_record?
        klass.ancestors.include?(ActiveRecord::Base)
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
effective_resources-0.3.2 app/models/effective/resources/klass.rb
effective_resources-0.3.1 app/models/effective/resources/klass.rb
effective_resources-0.3.0 app/models/effective/resources/klass.rb