Sha256: d29236459a064df8e5413a4b1b549ffb67a677a42fdd89bde0b7086c2cfc4d2f

Contents?: true

Size: 1.18 KB

Versions: 104

Compression:

Stored size: 1.18 KB

Contents

module Terraspace::Plugin
  class Finder
    def find_with(options)
      result = if options.key?(:plugin)
                 find_with_plugin(options[:plugin])
               elsif options.key?(:backend)
                 find_with_backend(options[:backend])
               elsif options.key?(:resource)
                 find_with_resource(options[:resource])
               else
                 raise "Must provide backend, plugin, or resource option."
               end
      return unless result
      raw = Hash[*result] # convert result to Hash instead of an Array
      Meta.new(raw)
    end

    def find_with_backend(backend)
      meta.find do |provider, data|
        data[:backend] == backend
      end
    end

    def find_with_plugin(plugin)
      meta.find do |plugin_name, data|
        plugin_name == plugin
      end
    end

    def find_with_resource(resource)
      map = resource_map
      base = resource.split('_').first # google_compute_firewall => google, aws_security_group => aws
      plugin = map[base] || base
      find_with_plugin(plugin)
    end

    def resource_map
      Terraspace::Plugin.resource_map
    end

    def meta
      Terraspace::Plugin.meta
    end
  end
end

Version data entries

104 entries across 104 versions & 1 rubygems

Version Path
terraspace-2.2.17 lib/terraspace/plugin/finder.rb
terraspace-2.2.16 lib/terraspace/plugin/finder.rb
terraspace-2.2.15 lib/terraspace/plugin/finder.rb
terraspace-2.2.14 lib/terraspace/plugin/finder.rb
terraspace-2.2.13 lib/terraspace/plugin/finder.rb
terraspace-2.2.12 lib/terraspace/plugin/finder.rb
terraspace-2.2.11 lib/terraspace/plugin/finder.rb
terraspace-2.2.10 lib/terraspace/plugin/finder.rb
terraspace-2.2.9 lib/terraspace/plugin/finder.rb
terraspace-2.2.8 lib/terraspace/plugin/finder.rb
terraspace-2.2.7 lib/terraspace/plugin/finder.rb
terraspace-2.2.6 lib/terraspace/plugin/finder.rb
terraspace-2.2.5 lib/terraspace/plugin/finder.rb
terraspace-2.2.4 lib/terraspace/plugin/finder.rb
terraspace-2.2.3 lib/terraspace/plugin/finder.rb
terraspace-2.2.2 lib/terraspace/plugin/finder.rb
terraspace-2.2.1 lib/terraspace/plugin/finder.rb
terraspace-2.2.0 lib/terraspace/plugin/finder.rb
terraspace-2.1.7 lib/terraspace/plugin/finder.rb
terraspace-2.1.6 lib/terraspace/plugin/finder.rb