Sha256: b1646f0654eae04f66db8e11b0d84acb752a864965f627b9492fa16ce103e613

Contents?: true

Size: 749 Bytes

Versions: 1

Compression:

Stored size: 749 Bytes

Contents

require 'pathname'

module SchemaDev
  GEMFILES_DIR = "gemfiles"

  module GemfileSelector
    def self.gemfile(opts = {})
      opts = opts.keyword_args(rails: :required, db: nil)
      root = Pathname.new(GEMFILES_DIR)
      if db
        root.join("rails-#{opts.rails}", "Gemfile.#{opts.db}")
      else
        root.join("Gemfile.#{opts.rails}")
      end
    end

    def self.command(opts={})
      opts = opts.keyword_args(rails: :required, db: nil)
      "BUNDLE_GEMFILE=#{gemfile(rails: opts.rails, db: opts.db)}"
    end

    def self.infer_db
      (env = ENV['BUNDLE_GEMFILE']) =~ %r{rails.*/Gemfile[.](.*)}
      $1 or raise "Can't infer db: Env BUNDLE_GEMFILE=#{env.inspect}) isn't a schema_dev Gemfile path with db"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
schema_dev-0.1.4 lib/schema_dev/gemfile_selector.rb