Sha256: 23e211d23112dbe8a9865f1737d4360fa3f9b45fdb295ec880f8e54a6bdd075f

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require 'active_support'
require 'active_support/inflector'

module ProxES
  module Helpers
    module Component
      def dataset
        policy_scope(settings.model_class)
      end

      def list
        params['count'] ||= 10
        params['page'] ||= 1

        dataset.select.paginate(params['page'].to_i, params['count'].to_i)
      end

      def heading(action = nil)
        @headings ||= begin
          heading = ActiveSupport::Inflector.demodulize settings.model_class
          h = Hash.new(heading)
          h[:new] = "New #{heading}"
          h[:list] = ActiveSupport::Inflector.pluralize heading
          h[:edit] = "Edit #{heading}"
          h
        end
        @headings[action]
      end

      def dehumanized
        settings.dehumanized || ActiveSupport::Inflector.underscore(heading)
      end

      def base_path
        settings.base_path || "/_proxes/#{heading(:list).downcase}"
      end

      def view_location
        settings.view_location || heading(:list).underscore.to_s
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
proxes-0.4.3 lib/proxes/helpers/component.rb
proxes-0.4.2 lib/proxes/helpers/component.rb
proxes-0.4.1 lib/proxes/helpers/component.rb