Class: IisObject

Inherits:
Object
  • Object
show all
Defined in:
lib/inetmgr/iis_object.rb

Overview

Represents an IIS configuration element. Serves as the base class for all IIS artifacts like Site, Application and VirtualDirectory.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element) ⇒ IisObject

Returns a new instance of IisObject.



5
6
7
# File 'lib/inetmgr/iis_object.rb', line 5

def initialize element
  @element = element
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object (private)



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/inetmgr/iis_object.rb', line 72

def method_missing(symbol, *args)
  name = symbol.to_s.to_camel_case
  if (/=$/.match(name))
    
    @element.Properties.Item(name.sub(/=$/, '')).Value = args[0]
  else
    @element.Properties.Item(name).Value
  end
rescue WIN32OLERuntimeError
  raise "property '#{symbol}' -> #{$!}"
end

Class Method Details

.child(name, element_name, type) ⇒ Object



52
53
54
55
56
# File 'lib/inetmgr/iis_object.rb', line 52

def self.child name, element_name, type
  define_method(name.to_s) do
    type.new @element.ChildElements.Item(element_name.to_s)
  end
end

.children(name, item_name, type) ⇒ Object

Creates a collection property with the specified name.

Parameters

  • name - The name of the property to create

  • item_name - The name of the element in the configuration schema.

  • type - The collection’s item type.



46
47
48
49
50
# File 'lib/inetmgr/iis_object.rb', line 46

def self.children name, item_name, type
  define_method(name.to_s) do
    IisObjectCollection.new @element.ChildElements.Item(name.to_s).Collection, item_name.to_s, type
  end
end

.collection(name, item_name, type) ⇒ Object

Creates a collection property with the specified name.

Parameters

  • name - The name of the property to create

  • type - The collection’s item type.



34
35
36
37
38
# File 'lib/inetmgr/iis_object.rb', line 34

def self.collection name, item_name, type
  define_method(name.to_s) do
    IisObjectCollection.new @element.Collection, item_name.to_s, type
  end
end

.prop(name, actual_name, setter = lambda { |v| v }, reader = lambda { |v| v }) ⇒ Object

Creates a property with the specified name.

Parameters

  • name - The name of the property to create

  • actual_name - Optional, The actual name of the attribute or

element in the IIS configuration schema.

  • setter - Optional, a lambda or proc to convert the property

value to a value in the IIS configuration schema.

  • reader - Optional, a lambda or proc to convert the IIS

configuration value to the desired property value.



19
20
21
22
23
24
25
26
27
# File 'lib/inetmgr/iis_object.rb', line 19

def self.prop name, actual_name, setter = lambda { |v| v }, reader = lambda { |v| v }
  define_method(name.to_s) do
    reader.call(@element.Properties.Item(actual_name.to_s).Value)
  end

  define_method("#{name.to_s}=") do |val|
    @element.Properties.Item(actual_name.to_s).Value = setter.call(val)
  end
end

Instance Method Details

#invoke_method(name) {|method| ... } ⇒ Object

Yields:

  • (method)


58
59
60
61
62
63
64
65
66
67
68
# File 'lib/inetmgr/iis_object.rb', line 58

def invoke_method name
  method = @element.Methods.Item(name.to_s).CreateInstance()
  
  # TODO: if block_given? change method_missing to change this:

  # method.Input.Properties.Item("key").Value = value

  # in to this:

  # method.key = value


  yield method if block_given?
  method.Execute()
end