Sha256: 29ade2cffd980b5712f3694e07a1e708573a5fb53612a0f7260741977e381b49

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

require 'iis_object'
require 'application'

module IISConfig

  class Site < IISObject

    def initialize
      @bindings = []
      @applications = []
      @virtual_directories = []
      @path = '/'
    end

    def name(name = nil)
      @name = name unless name.nil?
      @name
    end

    def binding(binding)
      @bindings << binding
    end

    def path(path)
      @path = path
    end

    def physical_path(path)
      @physical_path = path
    end

    def application(&block)
      add_instance(@applications, IISConfig::Application, block)
    end

    def virtual_directory(&block)
      add_instance(@virtual_directories, IISConfig::VirtualDirectory, block)
    end

    def delete
      %W{DELETE SITE #{@name}}
    end

    def add
      args = []
      args << 'ADD'
      args << 'SITE'
      args << "/name:#{@name}"
      args << "/bindings:\"#{@bindings.join('","')}\""
      args << "/physicalPath:#{@physical_path}"

      args
    end

    def build_commands(app_pool)
      commands = []
      commands << delete if exist? :site, @name
      commands << add
      commands << %W{SET SITE /site.name:#{@name} /[path='#{@path}'].applicationPool:#{app_pool}}

      @applications.each do |s|
        commands += s.build_commands @name, app_pool
      end

      @virtual_directories.each do |s|
        commands += s.build_commands "#{name}/"
      end

      commands
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
iisconfig-0.0.1.pre1 lib/iisconfig/site.rb