Class: AlphaApi::Generators::Boilerplate
- Inherits:
-
Object
- Object
- AlphaApi::Generators::Boilerplate
- Defined in:
- lib/generators/resource/resource_generator.rb
Instance Method Summary collapse
- #assignable_attributes ⇒ Object
- #attributes ⇒ Object
- #column(name) ⇒ Object
- #columns ⇒ Object
- #filter(name) ⇒ Object
- #filters ⇒ Object
- #form_input(name) ⇒ Object
- #form_inputs ⇒ Object
-
#initialize(class_name, module_path) ⇒ Boilerplate
constructor
A new instance of Boilerplate.
- #module_name ⇒ Object
- #permit_params ⇒ Object
- #row(name) ⇒ Object
- #rows ⇒ Object
Constructor Details
#initialize(class_name, module_path) ⇒ Boilerplate
Returns a new instance of Boilerplate.
27 28 29 30 |
# File 'lib/generators/resource/resource_generator.rb', line 27 def initialize(class_name, module_path) @module_path = module_path @class_name = class_name end |
Instance Method Details
#assignable_attributes ⇒ Object
40 41 42 |
# File 'lib/generators/resource/resource_generator.rb', line 40 def assignable_attributes attributes - %w(id created_at updated_at) end |
#attributes ⇒ Object
36 37 38 |
# File 'lib/generators/resource/resource_generator.rb', line 36 def attributes @class_name.constantize.new.attributes.keys end |
#column(name) ⇒ Object
60 61 62 |
# File 'lib/generators/resource/resource_generator.rb', line 60 def column(name) "# column :#{name.gsub(/_id$/, '')}" end |
#columns ⇒ Object
56 57 58 |
# File 'lib/generators/resource/resource_generator.rb', line 56 def columns attributes.map { |a| column(a) }.join("\n ") end |
#filter(name) ⇒ Object
68 69 70 |
# File 'lib/generators/resource/resource_generator.rb', line 68 def filter(name) "# filter :#{name.gsub(/_id$/, '')}" end |
#filters ⇒ Object
64 65 66 |
# File 'lib/generators/resource/resource_generator.rb', line 64 def filters attributes.map { |a| filter(a) }.join("\n ") end |
#form_input(name) ⇒ Object
76 77 78 |
# File 'lib/generators/resource/resource_generator.rb', line 76 def form_input(name) "# f.input :#{name.gsub(/_id$/, '')}" end |
#form_inputs ⇒ Object
72 73 74 |
# File 'lib/generators/resource/resource_generator.rb', line 72 def form_inputs assignable_attributes.map { |a| form_input(a) }.join("\n ") end |
#module_name ⇒ Object
32 33 34 |
# File 'lib/generators/resource/resource_generator.rb', line 32 def module_name @module_path.split('/').map(&:capitalize).join('::') end |
#permit_params ⇒ Object
44 45 46 |
# File 'lib/generators/resource/resource_generator.rb', line 44 def permit_params assignable_attributes.map { |a| a.to_sym.inspect }.join(", ") end |
#row(name) ⇒ Object
52 53 54 |
# File 'lib/generators/resource/resource_generator.rb', line 52 def row(name) "# row :#{name.gsub(/_id$/, '')}" end |
#rows ⇒ Object
48 49 50 |
# File 'lib/generators/resource/resource_generator.rb', line 48 def rows attributes.map { |a| row(a) }.join("\n ") end |