Class: ActiveAdmin::Generators::Boilerplate

Inherits:
Object
  • Object
show all
Defined in:
lib/active_admin/generators/boilerplate.rb

Instance Method Summary collapse

Constructor Details

#initialize(class_name) ⇒ Boilerplate


4
5
6
# File 'lib/active_admin/generators/boilerplate.rb', line 4

def initialize(class_name)
  @class_name = class_name
end

Instance Method Details

#attributesObject


8
9
10
# File 'lib/active_admin/generators/boilerplate.rb', line 8

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

#column(name) ⇒ Object


24
25
26
# File 'lib/active_admin/generators/boilerplate.rb', line 24

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

#columnsObject


20
21
22
# File 'lib/active_admin/generators/boilerplate.rb', line 20

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

#filter(name) ⇒ Object


32
33
34
# File 'lib/active_admin/generators/boilerplate.rb', line 32

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

#filtersObject


28
29
30
# File 'lib/active_admin/generators/boilerplate.rb', line 28

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

#form_input(name) ⇒ Object


40
41
42
# File 'lib/active_admin/generators/boilerplate.rb', line 40

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

#form_inputsObject


36
37
38
# File 'lib/active_admin/generators/boilerplate.rb', line 36

def form_inputs
  attributes.reject{|a| %w(id created_at updated_at).include? a}.map{ |a| form_input(a) }.join("\n")
end

#row(name) ⇒ Object


16
17
18
# File 'lib/active_admin/generators/boilerplate.rb', line 16

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

#rowsObject


12
13
14
# File 'lib/active_admin/generators/boilerplate.rb', line 12

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