Sha256: 0ac0fe361113d1ed084a8f3395c972d6b8e2eeee5f15929d898111368ffff19e

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 KB

Contents

require 'rbconfig'

module FSSM::Support
  class << self
    def usable_backend
      case
        when mac? && rb_fsevent?
          'RBFSEvent'
        when linux? && rb_inotify?
          'Inotify'
        else
          'Polling'
      end
    end
    
    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

    def backend
      @@backend ||= usable_backend
    end

    def jruby?
      defined?(JRUBY_VERSION)
    end

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

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

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

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

    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

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

  end
end

Version data entries

4 entries across 3 versions & 2 rubygems

Version Path
sadui-0.0.4 vendor/bundle/ruby/2.0.0/gems/fssm-0.2.10/lib/fssm/support.rb
sadui-0.0.4 vendor/bundle/ruby/2.1.0/gems/fssm-0.2.10/lib/fssm/support.rb
fssm-0.2.10 lib/fssm/support.rb
fssm-0.2.9 lib/fssm/support.rb