Module: CheapDependency

Defined in:
lib/cheap_dependency.rb

Class Method Summary collapse

Class Method Details

.cd_exists_absolute_fn(relative_fn_base) ⇒ Object



12
13
14
15
# File 'lib/cheap_dependency.rb', line 12

def self.cd_exists_absolute_fn(relative_fn_base)
  afn = File.expand_path("#{relative_fn_base}.rb", File.dirname(__FILE__))
  [File.exists?(afn), afn]
end

.cd_get(*relative_fn_base_array) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/cheap_dependency.rb', line 29

def self.cd_get(*relative_fn_base_array)
  relative_fn_base_array.each do |relative_fn_base|
    if cd_test?
      cd_load_relative relative_fn_base
    else
      cd_require_relative relative_fn_base
    end
  end
end

.cd_load_relative(relative_fn_base) ⇒ Object



23
24
25
26
27
# File 'lib/cheap_dependency.rb', line 23

def self.cd_load_relative(relative_fn_base)
  exists, afn = cd_exists_absolute_fn relative_fn_base
  load afn if exists
  require relative_fn_base unless exists
end

.cd_require_relative(relative_fn_base) ⇒ Object



17
18
19
20
21
# File 'lib/cheap_dependency.rb', line 17

def self.cd_require_relative(relative_fn_base)
  exists, afn = cd_exists_absolute_fn relative_fn_base
  require_relative relative_fn_base if exists
  require relative_fn_base unless exists
end

.cd_test(load) ⇒ Object



7
8
9
10
# File 'lib/cheap_dependency.rb', line 7

def self.cd_test(load)
  ENV[CHEAP_DEPENDENCY_ENV_NAME] = 'test' if load
  ENV[CHEAP_DEPENDENCY_ENV_NAME] = 'no_test' unless load
end

.cd_test?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/cheap_dependency.rb', line 3

def self.cd_test?
  'test' == ENV[CHEAP_DEPENDENCY_ENV_NAME]
end