Class: AlphaApi::Generators::Boilerplate

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/resource/resource_generator.rb

Instance Method Summary collapse

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_attributesObject



40
41
42
# File 'lib/generators/resource/resource_generator.rb', line 40

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

#attributesObject



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

#columnsObject



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

#filtersObject



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_inputsObject



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_nameObject



32
33
34
# File 'lib/generators/resource/resource_generator.rb', line 32

def module_name
  @module_path.split('/').map(&:capitalize).join('::')
end

#permit_paramsObject



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

#rowsObject



48
49
50
# File 'lib/generators/resource/resource_generator.rb', line 48

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