Class: Generators::Avo::ResourceGenerator
Instance Method Summary
collapse
#parent_controller
#initialize
Instance Method Details
#class_from_args ⇒ Object
51
52
53
|
# File 'lib/generators/avo/resource_generator.rb', line 51
def class_from_args
@class_from_args ||= options["model-class"]&.camelize || (class_name if class_name.include?("::"))
end
|
#controller_class ⇒ Object
27
28
29
|
# File 'lib/generators/avo/resource_generator.rb', line 27
def controller_class
"Avo::#{class_name.remove(":").pluralize}Controller"
end
|
#controller_name ⇒ Object
35
36
37
|
# File 'lib/generators/avo/resource_generator.rb', line 35
def controller_name
"#{model_resource_name.pluralize}_controller"
end
|
#create ⇒ Object
18
19
20
21
|
# File 'lib/generators/avo/resource_generator.rb', line 18
def create
template "resource/resource.tt", "app/avo/resources/#{resource_name}.rb"
template "resource/controller.tt", "app/controllers/avo/#{controller_name}.rb"
end
|
#current_models ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/generators/avo/resource_generator.rb', line 39
def current_models
ActiveRecord::Base.connection.tables.map do |model|
model.capitalize.singularize.camelize
end
rescue ActiveRecord::NoDatabaseError
puts "Database not found, please create your database and regenerate the resource."
[]
rescue ActiveRecord::ConnectionNotEstablished
puts "Database connection error, please create your database and regenerate the resource."
[]
end
|
#model_class_from_args ⇒ Object
55
56
57
58
59
|
# File 'lib/generators/avo/resource_generator.rb', line 55
def model_class_from_args
if class_from_args.present? || class_name.include?("::")
"\n self.model_class = ::#{class_from_args || class_name}"
end
end
|
#resource_class ⇒ Object
23
24
25
|
# File 'lib/generators/avo/resource_generator.rb', line 23
def resource_class
class_name.remove(":").to_s
end
|
#resource_name ⇒ Object
31
32
33
|
# File 'lib/generators/avo/resource_generator.rb', line 31
def resource_name
model_resource_name.to_s
end
|