Module: TLoad

Defined in:
lib/loader_helper.rb

Overview

Some helpers for the Talia bootstrapping (when the module is loaded)

Class Method Summary collapse

Class Method Details

.force_rails_partsObject

Forces the loading of the parts of the rails framework that are used by Talia



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/loader_helper.rb', line 39

def self.force_rails_parts
  require_module("activerecord", "active_record", "/../../../rails/activerecord", RAILS_GEM_VERSION) unless(defined?(ActiveRecord))
  require_module("activesupport", "active_support", "/../../../rails/activesupport", RAILS_GEM_VERSION) unless(defined?(ActiveSupport))
  require_module("actionpack", "action_controller", "/../../../rails/actionpack", RAILS_GEM_VERSION)
  # This sets the automatic loader path for Talia, allowing the ActiveSupport
  # classes to automatically load classes from this directory.
  # From 2.3.9(?) onward a new method autoload_path is "suggested" but 2.3.8 does not know it and gives error.
  # This is to avoid the error:
  begin
    load_paths = ActiveSupport::Dependencies.autoload_paths
  rescue NoMethodError
    load_paths = ActiveSupport::Dependencies.load_paths
  end      
  load_paths << TLoad.start_dir unless(load_paths.include?(TLoad.start_dir))
  # Add the other plugins to the path, if we have a Rails root
  if(defined?(RAILS_ROOT))
    Dir["#{RAILS_ROOT}/vendor/plugins/*/lib"].each do |plugin_dir|
      load_paths << plugin_dir if(File.directory?(plugin_dir) || !load_paths.include?(plugin_dir))
    end
  end
end

.require_module(gem_name, local_name, local_path, gem_version = nil) ⇒ Object

This tries to load the the given module. It first attempts to load from local_path/lib/local_name The local path is always appended to the directory of the script currently running. If that fails, it tries to load the given gem



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

def self.require_module(gem_name, local_name, local_path, gem_version = nil)
  begin
    # Try to loaTad from local if it exists
    search_dir = File.expand_path(File.join(File.dirname(__FILE__), local_path, "lib"))
    if(File.exists?(search_dir))
      $:.unshift(search_dir)  
      require local_name  
    else
      load_from_gem(gem_name, local_name, gem_version)
    end
  rescue LoadError
    load_from_gem(gem_name, local_name, gem_version)
  end
end

.setup_load_pathObject

Sets up the ActiveSupport autoload path



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/loader_helper.rb', line 62

def self.setup_load_path
  # set up the load path to talia
  root_dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
  Kernel.const_set(:TALIA_CODE_ROOT, root_dir) unless(defined?(TALIA_CODE_ROOT))
  lib_dir = File.join(root_dir, 'lib')
  # From 2.3.9(?) onward a new method autoload_path is "suggested" but 2.3.8 does not know it and gives error.
  # This is to avoid the error:
  begin
    load_paths = ActiveSupport::Dependencies.autoload_paths
  rescue NoMethodError
    load_paths = ActiveSupport::Dependencies.load_paths
  end      
  load_paths << lib_dir unless(load_paths.include?(lib_dir))
end

.start_dirObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/loader_helper.rb', line 26

def self.start_dir
  @start_dir ||= begin
    # adding talia_core subdirectory to the ruby loadpath  
    file = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
    this_dir = File.dirname(File.expand_path(file))
    $: << this_dir
    $: << this_dir + '/talia_core/'
    this_dir
  end
end