Class: Infold::SearchFormGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/infold/search_form_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_model_fileObject



20
21
22
# File 'lib/generators/infold/search_form_generator.rb', line 20

def create_model_file
  template "search_form.rb", Rails.root.join("app/forms/admin", "#{name.underscore.singularize}_search_form.rb"), force: true
end

#setupObject



11
12
13
14
15
16
17
18
# File 'lib/generators/infold/search_form_generator.rb', line 11

def setup
  resource_name = name.camelize.singularize
  db_schema_file = Rails.root.join('db/schema.rb')
  db_schema = DbSchema.new(File.exist?(db_schema_file) ? File.read(db_schema_file) : nil)
  yaml = YAML.load_file(Rails.root.join("config/infold/#{resource_name.underscore}.yml"))
  resource = YamlReader.generate_resource(resource_name, yaml, db_schema)
  @writer = SearchFormWriter.new(resource)
end