Sha256: 9378682204be8c395b13b903c69f4f85945f97449a39feef40490c59a80b1f69

Contents?: true

Size: 939 Bytes

Versions: 33

Compression:

Stored size: 939 Bytes

Contents

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 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
        attributes.reject{|a| %w(id created_at updated_at).include? a}.map{ |a| form_input(a) }.join("\n")
      end

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

Version data entries

33 entries across 33 versions & 6 rubygems

Version Path
activeadmin-rails-1.7.1 lib/active_admin/generators/boilerplate.rb
activeadmin-rails-1.7.0 lib/active_admin/generators/boilerplate.rb
activeadmin-rb-1.6.0 lib/active_admin/generators/boilerplate.rb
activeadmin-rb-1.5.2 lib/active_admin/generators/boilerplate.rb
activeadmin-rb-1.5.1 lib/active_admin/generators/boilerplate.rb
activeadmin-rb-1.5.0 lib/active_admin/generators/boilerplate.rb
activeadmin_addons-1.7.1 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/generators/boilerplate.rb
activeadmin-rb-1.4.0 lib/active_admin/generators/boilerplate.rb
activeadmin_addons-1.7.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/generators/boilerplate.rb
activeadmin-1.4.3 lib/active_admin/generators/boilerplate.rb
activeadmin-1.4.2 lib/active_admin/generators/boilerplate.rb
activeadmin-1.4.1 lib/active_admin/generators/boilerplate.rb
activeadmin-1.4.0 lib/active_admin/generators/boilerplate.rb
activeadmin-1.3.1 lib/active_admin/generators/boilerplate.rb
activeadmin_addons-1.6.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/generators/boilerplate.rb
dynamic_content-1.0.2 lib/dynamic_content/generators/boilerplate.rb
activeadmin_addons-1.5.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/generators/boilerplate.rb
dynamic_content-1.0.1 lib/dynamic_content/generators/boilerplate.rb
dynamic_content-1.0.0 lib/dynamic_content/generators/boilerplate.rb
activeadmin-1.3.0 lib/active_admin/generators/boilerplate.rb