Sha256: ad55555fbb064e1c13ee5d1aaf5f824a4b5d36b99a3000e4d4df0280a86db8c3

Contents?: true

Size: 1.49 KB

Versions: 11

Compression:

Stored size: 1.49 KB

Contents

require 'yaml'
require 'active_support/inflector'

class Provider
  def initialize
    config_file = "#{Ops::PROVIDERS_DIR}/#{self.class.name.underscore}.yml"
    begin
      config = YAML.load_file config_file
    rescue
      raise "Please, create '#{config_file}' file following gem instructions"
    end
    create_connection config
  end
  def create(config)
    raise "CREATE action not implemented"
  end
  def delete(host)
    raise "DELETE action not implemented"
  end
  def list_params
    raise "LIST PARAMS action not implemented"
  end

  private
  def create_connection(config)
    raise "PROVIDER connection should be created"
  end
end

Dir.glob("#{File.dirname(__FILE__)}/providers/*.rb").each { |r| load r }

class ProviderFactory
  class << self
    def build(provider_name)
      provider_name.classify.constantize.new
    end

    def list_providers
      say Dir.glob("#{File.dirname(__FILE__)}/providers/*.rb").
          select{|f| f.include? ".rb"}.
          map{|f| f.split("/").last.split(".")[0]}.
          join ", "
    end
  end
end

class Host
  def initialize(host_name)
    @host = host_name
    config_file = "#{Ops::HOSTS_DIR}/#{host_name}.yml"
    begin
      @config = YAML.load_file "#{config_file}"
      @config["name"]= host_name
    rescue
      raise "Please, create '#{config_file}' file with token value"
    end
    @provider = ProviderFactory.build @config["provider"]
  end
  def create
    @provider.create @config
  end
  def delete
    @provider.delete @host
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
open-dock-0.1.18 lib/open-dock/providers.rb
open-dock-0.1.17 lib/open-dock/providers.rb
open-dock-0.1.16 lib/open-dock/providers.rb
open-dock-0.1.15 lib/open-dock/providers.rb
open-dock-0.1.14 lib/open-dock/providers.rb
open-dock-0.1.13 lib/open-dock/providers.rb
open-dock-0.1.11 lib/open-dock/providers.rb
open-dock-0.1.10 lib/open-dock/providers.rb
open-dock-0.1.9 lib/open-dock/providers.rb
open-dock-0.1.8 lib/open-dock/providers.rb
open-dock-0.1.7 lib/open-dock/providers.rb