Module: FileSystem

Defined in:
lib/filesystem.rb

Defined Under Namespace

Modules: Adapter Classes: DirAdapter, FileAdapter, FileUtilsAdapter, MockFileSystem, Path

Constant Summary collapse

Version =
'0.1.0'
@@mock =
false

Class Method Summary collapse

Class Method Details

.method_missing(symbol, *args) ⇒ Object

:nodoc:



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

def self.method_missing( symbol, *args ) #:nodoc:
  class_name = nil
  if symbol.id2name =~ /^get_(.*)/
    class_name = $1.capitalize
    class_name.gsub!( /_(\w)/ ) { |s| $1.capitalize }
    unless %w( Dir File FileUtils ).include?( class_name )
      class_name = nil
    end
  end
  if class_name
    if @@mock
      return_class = Class.by_name( 'FileSystem::' + class_name + 'Adapter' )
    else
      return_class = Class.by_name( class_name )
    end
    return_class || super
  elsif @@mock
    mock_file_system.send( symbol, *args )
  else
    super
  end
end

.mock=(is_mock) ⇒ Object

Tell FileSystem whether to offer interfaces to the real or mock file system. is_mock should be a Boolean.



65
# File 'lib/filesystem.rb', line 65

def self.mock= ( is_mock ); @@mock = is_mock; end

.mock_file_systemObject

If we’re in mock mode, this will return the MockFileSystem; otherwise it will raise a RuntimeError.



69
70
71
# File 'lib/filesystem.rb', line 69

def self.mock_file_system
  @@mock ? MockFileSystem.instance : ( raise RuntimeError )
end