<commit_before>require 'formula'

class Geocouch < Formula
  homepage 'https://github.com/couchbase/geocouch'
  url 'https://github.com/couchbase/geocouch/archive/couchdb1.3.x.tar.gz'
  sha1 '73f5586c06cdec2fb6c5ab88da1ff99ef76beeb7'
  version '1.3.0'

  head 'https://github.com/couchbase/geocouch.git'

  def couchdb_share
    HOMEBREW_PREFIX/'share/couchdb'
  end
  def geocouch_share
    HOMEBREW_PREFIX/'share/geocouch'
  end

  #  Leverage generic couchdb.rb formula for couchdb (and therefore geocouch)
  #  dependencies.
  depends_on 'couchdb'

  #  GeoCouch currently supports couch_version(s) 1.1.x and 1.2.x (other
  #  versions at your own risk).  This formula supports GeoCouch 1.3.0 on top
  #  of Apache couchdb 1.3.0.
  def install
    #  Grab couchdb 1.3.x.
    couchdb_dir = buildpath/'couchdb-src'
    couchdb = Formula["couchdb"]
    couchdb.brew { couchdb_dir.install Dir['*'] }
    ENV['COUCH_SRC'] = couchdb_dir/"src/couchdb"

    #  Build geocouch.
    system "make"

    #  Install geocouch build files.
    (share/'geocouch').mkpath
    rm_rf share/'geocouch/ebin/'
    (share/'geocouch').install Dir['ebin']

    #  Install geocouch.plist for launchctl support.
    (share/'geocouch').install Dir[couchdb_dir/'etc/launchd/org.apache.couchdb.plist.tpl.in']
    mv share/'geocouch/org.apache.couchdb.plist.tpl.in', share/'geocouch/geocouch.plist'
    inreplace (share/'geocouch/geocouch.plist'), '<string>org.apache.couchdb</string>', \
      '<string>geocouch</string>'
    inreplace (share/'geocouch/geocouch.plist'), '<key>HOME</key>', <<-EOS.lstrip.chop
      <key>ERL_FLAGS</key>
      <string>-pa #{geocouch_share}/ebin</string>
      <key>HOME</key>
    EOS
    inreplace (share/'geocouch/geocouch.plist'), '%bindir%/%couchdb_command_name%', \
      HOMEBREW_PREFIX/'bin/couchdb'
    #  Turn off RunAtLoad and KeepAlive (to simplify experience for first-timers).
    inreplace (share/'geocouch/geocouch.plist'), '<true/>', \
      '<false/>'<commit_msg>geocouch: cleanup and fix formula.<commit_after>require 'formula'

class Geocouch < Formula
  homepage 'https://github.com/couchbase/geocouch'
  url 'https://github.com/couchbase/geocouch/archive/couchdb1.3.x.tar.gz'
  sha1 '73f5586c06cdec2fb6c5ab88da1ff99ef76beeb7'
  version '1.3.0'

  head 'https://github.com/couchbase/geocouch.git'

  depends_on "couchdb"
  depends_on "erlang" => :build

  def couchdb_share
    HOMEBREW_PREFIX/'share/couchdb'
  end
  def geocouch_share
    HOMEBREW_PREFIX/'share/geocouch'
  end

  #  GeoCouch currently supports couch_version(s) 1.1.x and 1.2.x (other
  #  versions at your own risk).  This formula supports GeoCouch 1.3.0 on top
  #  of Apache couchdb 1.3.0.
  def install
    couchdb_dir = buildpath/"couchdb-src"
    Formula["couchdb"].brew { couchdb_dir.install Dir["*"] }
    ENV["COUCH_SRC"] = couchdb_dir/"src/couchdb"

    #  Build geocouch.
    system "make"

    #  Install geocouch build files.
    (share/'geocouch').mkpath
    rm_rf share/'geocouch/ebin/'
    (share/'geocouch').install Dir['ebin']

    #  Install geocouch.plist for launchctl support.
    (share/'geocouch').install Dir[couchdb_dir/'etc/launchd/org.apache.couchdb.plist.tpl.in']
    mv share/'geocouch/org.apache.couchdb.plist.tpl.in', share/'geocouch/geocouch.plist'
    inreplace (share/'geocouch/geocouch.plist'), '<string>org.apache.couchdb</string>', \
      '<string>geocouch</string>'
    inreplace (share/'geocouch/geocouch.plist'), '<key>HOME</key>', <<-EOS.lstrip.chop
      <key>ERL_FLAGS</key>
      <string>-pa #{geocouch_share}/ebin</string>
      <key>HOME</key>
    EOS
    inreplace (share/'geocouch/geocouch.plist'), '%bindir%/%couchdb_command_name%', \
      HOMEBREW_PREFIX/'bin/couchdb'
    #  Turn off RunAtLoad and KeepAlive (to simplify experience for first-timers).
    inreplace (share/'geocouch/geocouch.plist'), '<true/>', \
      '<false/>'
{'fraction_non_alphanumeric': 0.14547330410110912, 'fraction_numerical': 0.018571060098013927, 'mean_word_length': 3.6002372479240807, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 32, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6300511', 'n_tokens_mistral': 1528, 'n_tokens_neox': 1470, 'n_words': 245}