Class: AePageObjects::ConstantResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/ae_page_objects/core/constant_resolver.rb

Instance Method Summary collapse

Constructor Details

#initialize(application, from_mod, const_name) ⇒ ConstantResolver



3
4
5
6
7
8
9
# File 'lib/ae_page_objects/core/constant_resolver.rb', line 3

def initialize(application, from_mod, const_name)
  @application = application
  @from_mod    = from_mod
  @const_name  = const_name

  @path_for_constant = path_for_constant
end

Instance Method Details

#load_constant_from_path(path) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ae_page_objects/core/constant_resolver.rb', line 11

def load_constant_from_path(path)
  file_path = File.join(path, "#{@path_for_constant}.rb").sub(/(\.rb)?$/, ".rb")

  if File.file?(file_path) && ! ActiveSupport::Dependencies.loaded.include?(File.expand_path(file_path))
    ActiveSupport::Dependencies.require_or_load file_path

    unless ActiveSupport::Dependencies.local_const_defined?(@from_mod, @const_name)
      qualified_name = ActiveSupport::Dependencies.qualified_name_for(@from_mod, @const_name)
      raise LoadError, "Expected #{@file_path} to define #{qualified_name}"
    end

    @from_mod.const_get(@const_name)
  end
end