Class: ActiveAdmin::Generators::Boilerplate
- Inherits:
-
Object
- Object
- ActiveAdmin::Generators::Boilerplate
- Defined in:
- lib/active_admin/generators/boilerplate.rb
Instance Method Summary collapse
- #attributes ⇒ Object
- #column(name) ⇒ Object
- #columns ⇒ Object
- #filter(name) ⇒ Object
- #filters ⇒ Object
- #form_input(name) ⇒ Object
- #form_inputs ⇒ Object
-
#initialize(class_name) ⇒ Boilerplate
constructor
A new instance of Boilerplate.
- #row(name) ⇒ Object
- #rows ⇒ Object
Constructor Details
#initialize(class_name) ⇒ Boilerplate
Returns a new instance of 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
#attributes ⇒ Object
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 |
#columns ⇒ Object
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 |
#filters ⇒ Object
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_inputs ⇒ Object
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 |
#rows ⇒ Object
12 13 14 |
# File 'lib/active_admin/generators/boilerplate.rb', line 12 def rows attributes.map { |a| row(a) }.join("\n") end |