Module: FSSM::Support

Defined in:
lib/fssm/support.rb

Class Method Summary collapse

Class Method Details

.backendObject



26
27
28
# File 'lib/fssm/support.rb', line 26

def backend
  @@backend ||= usable_backend
end

.carbon_core?Boolean



46
47
48
49
50
51
52
53
54
# File 'lib/fssm/support.rb', line 46

def carbon_core?
  begin
    require 'osx/foundation'
    OSX.require_framework '/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework'
    true
  rescue LoadError
    false
  end
end

.jruby?Boolean



30
31
32
# File 'lib/fssm/support.rb', line 30

def jruby?
  defined?(JRUBY_VERSION)
end

.linux?Boolean



42
43
44
# File 'lib/fssm/support.rb', line 42

def linux?
  RbConfig::CONFIG['target_os'] =~ /linux/i
end

.lion?Boolean



38
39
40
# File 'lib/fssm/support.rb', line 38

def lion?
  RbConfig::CONFIG['target_os'] =~ /darwin11/i
end

.mac?Boolean



34
35
36
# File 'lib/fssm/support.rb', line 34

def mac?
  RbConfig::CONFIG['target_os'] =~ /darwin/i
end

.optimal_backend_dependencyObject



18
19
20
21
22
23
24
# File 'lib/fssm/support.rb', line 18

def optimal_backend_dependency
  return case
    when mac?     then  ['rb-fsevent', '>= 0.4.3.1']
    when linux?   then  ['rb-inotify', '>= 0.8.8']
    else                [nil, nil]
  end
end

.rb_fsevent?Boolean



56
57
58
59
60
61
62
63
# File 'lib/fssm/support.rb', line 56

def rb_fsevent?
  begin
    require 'rb-fsevent'
    defined?(FSEvent::VERSION) ? FSEvent::VERSION.to_f >= 0.4 : false
  rescue LoadError
    false
  end
end

.rb_inotify?Boolean



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/fssm/support.rb', line 65

def rb_inotify?
  begin
    require 'rb-inotify'
    if defined?(INotify::VERSION)
      version = INotify::VERSION
      version[0] > 0 || version[1] >= 6
    end
  rescue LoadError
    false
  end
end

.usable_backendObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fssm/support.rb', line 5

def usable_backend
  case
    when mac? && !lion? && !jruby? && carbon_core?
      'FSEvents'
    when mac? && rb_fsevent?
      'RBFSEvent'
    when linux? && rb_inotify?
      'Inotify'
    else
      'Polling'
  end
end

.use_block(context, block) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/fssm/support.rb', line 77

def use_block(context, block)
  return if block.nil?
  if block.arity == 1
    block.call(context)
  else
    context.instance_eval(&block)
  end
end