Class: Configuration

Inherits:
Object show all
Includes:
RubySync::Utilities
Defined in:
lib/ruby_sync.rb

Instance Method Summary collapse

Methods included from RubySync::Utilities

#base_path, #call_if_exists, #connector_called, #ensure_dir_exists, #find_base_path, #get_preference, #get_preference_file_path, #include_in_search_path, #log_progress, #pipeline_called, #set_preference, #something_called, #with_rescue

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/ruby_sync.rb', line 68

def initialize
  include_in_search_path "#{base_path}/pipelines"
  include_in_search_path "#{base_path}/connectors"
  include_in_search_path "#{base_path}/shared/connectors"
  include_in_search_path "#{base_path}/shared/pipelines"    
  include_in_search_path "#{base_path}/shared/lib"

  lib_path = File.dirname(__FILE__)
  require_all_in_dir "#{lib_path}/ruby_sync/connectors", "*_connector.rb"
  require_all_in_dir "#{base_path}/shared/connectors", "*_connector.rb"
  require_all_in_dir "#{lib_path}/ruby_sync/pipelines", "*_pipeline.rb"
  require_all_in_dir "#{base_path}/shared/pipelines", "*_pipeline.rb"
end

Instance Method Details

#require_all_in_dir(dir, glob = "*.rb") ⇒ Object

We find the first directory in the search path that is a parent of the specified directory and do our requires relative to that in order to increase the likelihood that duplicate requires will be recognised.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/ruby_sync.rb', line 85

def require_all_in_dir(dir, glob="*.rb")
  expanded = File.expand_path dir
  return unless File.directory? expanded
  
  base = $:.detect do |path_dir|
    expanded_pd = File.expand_path(path_dir)
    expanded[0, expanded_pd.length] == expanded_pd
  end
  
  prefix = (base && File.expand_path(base) != expanded)? expanded[File.expand_path(base).length+1, expanded.length]+"/" : ""

  # puts $:.join "\n"
  # puts "expanded = '#{expanded}'"
  # puts "base = '#{base}'"
  # puts "prefix = '#{prefix}'"

  Dir.chdir dir do |cwd|
    Dir.glob(glob) do |filename|
      require prefix + filename
    end
  end
end