Module: FSSM::Support
- Defined in:
- lib/fssm/support.rb
Class Method Summary collapse
- .backend ⇒ Object
- .carbon_core? ⇒ Boolean
- .jruby? ⇒ Boolean
- .linux? ⇒ Boolean
- .mac? ⇒ Boolean
- .rb_fsevent? ⇒ Boolean
- .rb_inotify? ⇒ Boolean
- .usable_backend ⇒ Object
- .use_block(context, block) ⇒ Object
Class Method Details
.backend ⇒ Object
31 32 33 |
# File 'lib/fssm/support.rb', line 31 def backend @@backend ||= usable_backend end |
.carbon_core? ⇒ Boolean
47 48 49 50 51 52 53 54 55 |
# File 'lib/fssm/support.rb', line 47 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
35 36 37 |
# File 'lib/fssm/support.rb', line 35 def jruby? defined?(JRUBY_VERSION) end |
.linux? ⇒ Boolean
43 44 45 |
# File 'lib/fssm/support.rb', line 43 def linux? Config::CONFIG['target_os'] =~ /linux/i end |
.mac? ⇒ Boolean
39 40 41 |
# File 'lib/fssm/support.rb', line 39 def mac? Config::CONFIG['target_os'] =~ /darwin/i end |
.rb_fsevent? ⇒ Boolean
57 58 59 60 61 62 63 64 |
# File 'lib/fssm/support.rb', line 57 def rb_fsevent? begin require 'rb-fsevent' true rescue LoadError false end end |
.rb_inotify? ⇒ Boolean
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fssm/support.rb', line 66 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_backend ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fssm/support.rb', line 5 def usable_backend choice = case when mac? && !jruby? && carbon_core? 'FSEvents' when mac? && rb_fsevent? 'RBFSEvent' when linux? && rb_inotify? 'Inotify' else 'Polling' end if (mac? || linux?) && choice == 'Polling' optimal = case when mac? 'rb-fsevent' when linux? 'rb-inotify' end STDERR.puts("FSSM: An optimized backend is available for this platform!") STDERR.puts(" gem install #{optimal}") end choice end |
.use_block(context, block) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/fssm/support.rb', line 78 def use_block(context, block) return if block.nil? if block.arity == 1 block.call(context) else context.instance_eval(&block) end end |