Module: Win32::CaptureIE::Feature

Included in:
Win32::CaptureIE, BitMap
Defined in:
lib/win32/capture_ie/feature.rb

Overview

:nodoc:

Defined Under Namespace

Classes: DisabledError

Constant Summary collapse

DISABLED_FEATURE =
[]

Class Method Summary collapse

Class Method Details

.disable_feature(feature) ⇒ Object



13
14
15
16
# File 'lib/win32/capture_ie/feature.rb', line 13

def disable_feature(feature)
  DISABLED_FEATURE << feature if feature_enable?(feature)
  nil
end

.enable_feature(feature) ⇒ Object



18
19
20
21
# File 'lib/win32/capture_ie/feature.rb', line 18

def enable_feature(feature)
  DISABLED_FEATURE.delete(feature)
  nil
end

.feature_available?(feature) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
# File 'lib/win32/capture_ie/feature.rb', line 27

def feature_available?(feature)
  begin
    load_depended_library(feature, "test")
    true
  rescue LoadError, DisabledError => ignored
    false
  end
end

.feature_enable?(feature) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/win32/capture_ie/feature.rb', line 23

def feature_enable?(feature)
  not DISABLED_FEATURE.include?(feature)
end

.load_depended_library(feature, function) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/win32/capture_ie/feature.rb', line 48

def load_depended_library(feature, function)
  begin
    load_feature feature, function
  rescue LoadError
    begin
      load_feature "rubygems", function
      load_feature feature, function
    rescue LoadError
      raise LoadError, "no such file to load -- `#{feature}'. " +
        "Please install `#{feature}' to #{function}."
    end
  end
end

.load_feature(feature, function) ⇒ Object



43
44
45
46
# File 'lib/win32/capture_ie/feature.rb', line 43

def load_feature(feature, function)
  raise_if_disabled(feature, function)
  require feature
end

.raise_if_disabled(feature, function) ⇒ Object



36
37
38
39
40
41
# File 'lib/win32/capture_ie/feature.rb', line 36

def raise_if_disabled(feature, function)
  if DISABLED_FEATURE.include?(feature)
    raise DisabledError, "`#{feature}' is disabled. " +
      "Please enable `#{feature}' to #{function}."
  end
end