Sha256: 82e476fbc176a524d0daca19f24aef03e9e2d0d20879a2e2d67f6de47650854b

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

require 'podmode/version'
require 'podmode/touchwonders'
require 'podmode/prompt'
require 'podmode/console'
require 'dotenv'

module Podmode

  	def self.podmodes_dir()
  		return File.join(Touchwonders::config_dir(), 'podmodes')
  	end

    def self.for(name, git_url)
      return ::Podmode::Podmode.new(name, git_url).options()
    end

  class Podmode
  	def initialize(name, git_url)
  		@name = name
  		@git_url = git_url
  	end

  	def options()
  		load()

  		options = {}
  		pod_mode = pod_mode()

  		if pod_mode.nil? || pod_mode.empty? || pod_mode == 'auto'
  			options[:git] = "ssh://#{@git_url}"
  		else
	  		case pod_mode
	  			when 'local'
	  				options[:path] = pod_path()

	  			when 'branch'
	  				options[:git] = "ssh://#{@git_url}"
	  				options[:branch] = pod_branch()

	  			when 'tag'
	  				options[:git] = "ssh://#{@git_url}"
	  				options[:tag] = pod_tag()
  			end
  		end

  		return options
  	end

  	private

  	def load()
  		user_config = File.join(::Podmode.podmodes_dir(), "#{@name.downcase}.podmode")
  		if File.exist? user_config
  			puts "Reading #{user_config}"
  			Dotenv.load!(user_config)
  		end

  		if File.exist? '.env.local'
    		puts "Loading local environment variables from '.env.local'"
    		Dotenv.overload('.env.local') 
  		end
  	end


  	def pod_mode()
  		return ENV["#{@name.upcase}_PODMODE"]
  	end

  	def pod_path
  		return ENV["#{@name.upcase}_PODMODE_PATH"]
  	end

  	def pod_branch
  		return ENV["#{@name.upcase}_PODMODE_BRANCH"]
  	end

  	def pod_tag
  		return ENV["#{@name.upcase}_PODMODE_TAG"]
  	end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
podmode-0.2.0 lib/podmode.rb