Sha256: 176b1e3bdd277443be21289b42e692327665afcda504aad175c76b6c18a18223

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

module SearchCraft::Annotate
  extend ActiveSupport::Concern

  # 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 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
    }
    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

1 entries across 1 versions & 1 rubygems

Version Path
searchcraft-0.4.0 lib/searchcraft/annotate.rb