Module: FSEvent::Util

Included in:
FSEvent
Defined in:
lib/fsevent/util.rb

Overview

util.rb — various utilities

Copyright © 2014 National Institute of Advanced Industrial Science and Technology (AIST)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <www.gnu.org/licenses/>.

Class Method Summary collapse

Class Method Details

.nested_hash(n) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/fsevent/util.rb', line 21

def nested_hash(n)
  if n == 1
    {}
  else
    Hash.new {|h, k|
      h[k] = nested_hash(n-1)
    }
  end
end

.nonempty_hash(h, level) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fsevent/util.rb', line 31

def nonempty_hash(h, level)
  return nil if h.nil?
  result = {}
  h.each {|k, v|
    if level == 1
      result[k] = v
    else
      h2 = nonempty_hash(v, level-1)
      if h2
        result[k] = h2
      end
    end
  }
  if result.empty?
    nil
  else
    result
  end
end

.reaction_immediate_at_beginning?(reaction) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fsevent/util.rb', line 51

def reaction_immediate_at_beginning?(reaction)
  case reaction
  when :immediate
    true
  when :immediate_only_at_beginning
    true
  when :schedule
    false
  else
    raise "unexpected reaction: #{reaction.inspect}"
  end
end

.reaction_immediate_at_subsequent?(reaction) ⇒ Boolean

Returns:

  • (Boolean)


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

def reaction_immediate_at_subsequent?(reaction)
  case reaction
  when :immediate
    true
  when :immediate_only_at_beginning
    false
  when :schedule
    false
  else
    raise "unexpected reaction: #{reaction.inspect}"
  end
end