Module: Fortitude::Erector

Defined in:
lib/fortitude/erector.rb

Defined Under Namespace

Classes: ErectorOutputBufferHolder

Class Method Summary collapse

Class Method Details

.is_erector_available?Boolean


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fortitude/erector.rb', line 4

def is_erector_available?
  @is_erector_available ||= begin
    %w{erector-rails4 erector}.each do |gem_name|
      begin
        gem gem_name
      rescue Gem::LoadError => le
        # ok
      end
    end

    begin
      require 'erector'
    rescue LoadError => le
      # ok
    end

    if defined?(::Erector::Widget) then :yes else :no end
  end

  @is_erector_available == :yes
end

.is_erector_widget?(widget) ⇒ Boolean


34
35
36
# File 'lib/fortitude/erector.rb', line 34

def is_erector_widget?(widget)
  is_erector_widget_class?(widget.class)
end

.is_erector_widget_class?(widget_class) ⇒ Boolean


26
27
28
29
30
31
32
# File 'lib/fortitude/erector.rb', line 26

def is_erector_widget_class?(widget_class)
  return false unless is_erector_available?
  return false unless widget_class.kind_of?(::Class)
  return true if widget_class == ::Erector::Widget
  return false if widget_class == ::Object
  return is_erector_widget_class?(widget_class.superclass)
end