Sha256: 37258cb82ea9aa33c8118bc41657103cfa63de3a1e97456eefbea926ca270fcd

Contents?: true

Size: 1.11 KB

Versions: 17

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true
module ActiveAdmin
  module Generators
    class Boilerplate
      def initialize(class_name)
        @class_name = class_name
      end

      def attributes
        @class_name.constantize.new.attributes.keys
      end

      def assignable_attributes
        attributes - %w(id created_at updated_at)
      end

      def permit_params
        assignable_attributes.map { |a| a.to_sym.inspect }.join(", ")
      end

      def rows
        attributes.map { |a| row(a) }.join("\n  ")
      end

      def row(name)
        "#   row :#{name.gsub(/_id$/, '')}"
      end

      def columns
        attributes.map { |a| column(a) }.join("\n  ")
      end

      def column(name)
        "#   column :#{name.gsub(/_id$/, '')}"
      end

      def filters
        attributes.map { |a| filter(a) }.join("\n  ")
      end

      def filter(name)
        "# filter :#{name.gsub(/_id$/, '')}"
      end

      def form_inputs
        assignable_attributes.map { |a| form_input(a) }.join("\n  ")
      end

      def form_input(name)
        "#     f.input :#{name.gsub(/_id$/, '')}"
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
activeadmin-3.2.5 lib/active_admin/generators/boilerplate.rb
activeadmin-3.2.4 lib/active_admin/generators/boilerplate.rb
activeadmin-3.2.3 lib/active_admin/generators/boilerplate.rb
activeadmin-3.2.2 lib/active_admin/generators/boilerplate.rb
activeadmin-3.2.1 lib/active_admin/generators/boilerplate.rb
activeadmin-3.2.0 lib/active_admin/generators/boilerplate.rb
activeadmin-3.1.0 lib/active_admin/generators/boilerplate.rb
activeadmin-3.0.0 lib/active_admin/generators/boilerplate.rb
activeadmin-2.14.0 lib/active_admin/generators/boilerplate.rb
activeadmin-2.13.1 lib/active_admin/generators/boilerplate.rb
activeadmin-2.13.0 lib/active_admin/generators/boilerplate.rb
activeadmin-2.12.0 lib/active_admin/generators/boilerplate.rb
activeadmin-2.11.2 lib/active_admin/generators/boilerplate.rb
activeadmin-2.11.1 lib/active_admin/generators/boilerplate.rb
activeadmin-2.11.0 lib/active_admin/generators/boilerplate.rb
activeadmin-2.10.1 lib/active_admin/generators/boilerplate.rb
activeadmin-2.10.0 lib/active_admin/generators/boilerplate.rb