Sha256: 60fdc39fabc9910df5dd3d7762ea23a8ae11c21b60fe5a44a6a0257df7377828

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

module SearchCraft::Annotate
  # If using annotate gem, then automatically annotate models after rebuilding views
  # TODO: I'm suspicious this is not working for dependent Builders, e.g. demo_app's OnsaleSearchBuilder
  def annotate_models!
    return if SearchCraft.config.disable_annotate
    return unless Rails.env.development?
    return unless Object.const_defined?(:Annotate)

    options = {
      is_rake: true,
      position: "before",
      additional_file_patterns: [],
      model_dir: "app/models",
      root_dir: Rails.root.to_s,
      require: [],
      exclude_controllers: true,
      exclude_helpers: true,
      hide_limit_column_types: "",
      hide_default_column_types: "",
      ignore_unknown_models: true,
      show_indexes: true
    }
    capture_stdout do
      AnnotateModels.do_annotations(options)
    end
  rescue PG::UndefinedTable
  rescue => e
    puts "Error annotating models: #{e.message}"
    pp e.backtrace
  end

  def capture_stdout(&block)
    old_stdout = $stdout
    $stdout = StringIO.new
    yield
    if SearchCraft.debug?
      puts $stdout.string
    end
  ensure
    $stdout = old_stdout
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
searchcraft-0.5.2 lib/searchcraft/annotate.rb
searchcraft-0.5.1 lib/searchcraft/annotate.rb
searchcraft-0.5.0 lib/searchcraft/annotate.rb
searchcraft-0.4.2 lib/searchcraft/annotate.rb