Class: Rubee::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/rubee/generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(model_name, model_attributes, controller_name, action_name, **options) ⇒ Generator

Returns a new instance of Generator.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rubee/generator.rb', line 6

def initialize(model_name, model_attributes, controller_name, action_name, **options)
  @model_name = model_name&.downcase
  @model_attributes = model_attributes || []
  @filtered_attributes = @model_attributes.select { |attribute| !attribute[:type].to_s.include?('index') }
  @base_name = controller_name.to_s.gsub('Controller', '').downcase.to_s
  color_puts("base_name: #{@base_name}", color: :gray)
  @plural_name = @base_name.plural? ? @base_name : @base_name.pluralize
  @action_name = action_name
  @react = options[:react] || {}
  @app_name = options[:app_name] || :app
  @namespace = @app_name == :app ? '' : "#{@app_name.camelize}::"
end

Instance Method Details

#callObject



19
20
21
22
23
24
# File 'lib/rubee/generator.rb', line 19

def call
  generate_model if @model_name
  generate_db_file if @model_name
  generate_controller if @base_name && @action_name
  generate_view if @base_name
end