Module: DistributedShelf

Included in:
Dir, DistributedFile, DistributedStat, File, File::Stat
Defined in:
lib/dshelf.rb

Constant Summary collapse

VERSION =
'0.3.0'
@@config =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.config=(conf) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/dshelf.rb', line 36

def self.config= conf
  @@config = conf
  if @@config[:distributed_path].respond_to? :each then
    @@config[:distributed_path].map! do |distributed_path|
      Regexp.new('^' + distributed_path + '/')
    end
  else
    @@config[:distributed_path] == Regexp.new('^' + @@config[:distributed_path] + '/')
  end
end

Instance Method Details

#absolutepathObject



51
52
53
# File 'lib/dshelf.rb', line 51

def absolutepath
  File.expand_path path, Dir.pwd
end

#distributed?(file) ⇒ Boolean

Returns:

  • (Boolean)


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

def distributed? file
  return false unless @@config[:distributed_path]
  if @@config[:distributed_path].respond_to? :each then
    @@config[:distributed_path].each do |distributed_path|
      return true unless (File.expand_path(file) + '/').match(distributed_path).nil?
    end
  else
    return !File.expand_path(file + '/').match(@@config[:distributed_path]).nil?
  end
  false
end

#override_class_method(method, &b) ⇒ Object



6
7
8
9
10
11
# File 'lib/dshelf.rb', line 6

def override_class_method method, &b
  (class << self; self; end).class_eval do
    alias_method "_#{method.to_s}".to_sym, method
    define_method method, &b
  end
end

#proxy_method(method, &b) ⇒ Object



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

def proxy_method(method, &b)
  old_method = :"_#{method}"
  override_class_method(method) do |*args, &bl|
    if distributed? args[0]
      b.call(*args, &bl)
    else
      self.send(old_method, *args, &bl)
    end
  end
end

#server_urlObject



47
48
49
# File 'lib/dshelf.rb', line 47

def server_url
  @@config[:storage_url]
end