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

Returns a new instance of Boilerplate.



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

def initialize(class_name)
  @class_name = class_name
end

Instance Method Details

#assignable_attributesObject



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

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

#attributesObject



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

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

#column(name) ⇒ Object



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

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

#columnsObject



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

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

#filter(name) ⇒ Object



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

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

#filtersObject



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

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

#form_input(name) ⇒ Object



49
50
51
# File 'lib/active_admin/generators/boilerplate.rb', line 49

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

#form_inputsObject



45
46
47
# File 'lib/active_admin/generators/boilerplate.rb', line 45

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

#permit_paramsObject



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

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

#row(name) ⇒ Object



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

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

#rowsObject



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

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