Sha256: 606118c40c8d0c7faa1714bb490bf1624ac7aa89ba92a96007188be6a85166b4

Contents?: true

Size: 1.37 KB

Versions: 5

Compression:

Stored size: 1.37 KB

Contents

$:.push File.expand_path(File.dirname(__FILE__))

require 'rexml/document'
require 'app_pool'
require 'ftp_site'
require 'site'

module IISConfig

  class IISConfiguration

    def initialize
      @app_pools = []
      @sites = []
      @ftp_sites = []
      @before = []
      @after = []
    end

    def app_pool(&block)
      add_instance @app_pools, IISConfig::AppPool, block
    end

    def site(&block)
      add_instance @sites, IISConfig::Site, block
    end

    def ftp_site(&block)
      add_instance @ftp_sites, IISConfig::FtpSite, block
    end

    def before(&block)
      @before << block
    end

    def after(&block)
      @after << block
    end
    
    def load(path)
      instance_eval IO.read(path), path
    end

    def run
      @before.each { |a| a.call }

      execute @app_pools
      execute @sites
      execute @ftp_sites

      @after.each { |a| a.call }
    end

    private

    def execute(objects)
      objects.each do |p|
        commands = p.build_commands
        Runner.run_commands commands

        p.required_paths.each do |path|
          FileUtils.mkdir_p path unless Dir.exist? path
        end
      end
    end

    def add_instance(collection, type, block)
      instance = type.new
      collection << instance
      block.call instance if block
    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
iisconfig-0.2.3 lib/iisconfig/configuration.rb
iisconfig-0.2.2 lib/iisconfig/configuration.rb
iisconfig-0.2.1 lib/iisconfig/configuration.rb
iisconfig-0.2.0 lib/iisconfig/configuration.rb
iisconfig-0.1.0 lib/iisconfig/configuration.rb